@muggleai/works 5.5.0 → 5.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/plugin/.claude-plugin/plugin.json +1 -1
- package/dist/plugin/.cursor-plugin/plugin.json +1 -1
- package/dist/plugin/hooks/README.md +9 -3
- package/dist/plugin/hooks/hooks.json +6 -0
- package/dist/plugin/scripts/guardrail-record-tests.sh +5 -4
- package/dist/plugin/scripts/guardrails.mjs +11 -3
- package/dist/plugin/scripts/reconcile-stale-watchers.sh +59 -0
- package/dist/plugin/skills/_shared/post-merge-cleanup.md +2 -3
- package/dist/plugin/skills/_shared/session-state-writes.md +1 -1
- package/dist/plugin/skills/_shared/telemetry-events/muggle-do-cycle.md +1 -1
- package/dist/plugin/skills/do/e2e-acceptance.md +2 -0
- package/dist/plugin/skills/do/resolve-conflicts.md +5 -5
- package/dist/plugin/skills/do/respawn-watcher.md +4 -14
- package/dist/plugin/skills/muggle-pr-followup/CLAUDE.md +3 -2
- package/dist/plugin/skills/muggle-pr-followup/SKILL.md +5 -1
- package/dist/plugin/skills/muggle-pr-followup/arm-watcher.md +12 -0
- package/dist/plugin/skills/muggle-pr-followup/auto-track.md +5 -11
- package/dist/plugin/skills/muggle-pr-followup/blocked-tick.md +10 -10
- package/dist/plugin/skills/muggle-pr-followup/bootstrap.md +4 -8
- package/dist/plugin/skills/muggle-pr-followup/contract.md +13 -7
- package/dist/plugin/skills/muggle-pr-followup/evals/evals.json +101 -0
- package/dist/plugin/skills/muggle-pr-followup/output-templates/bootstrap.md +2 -2
- package/dist/plugin/skills/muggle-pr-followup/reconcile.md +10 -0
- package/dist/plugin/skills/muggle-pr-followup/state-schemas.md +19 -5
- package/dist/release-manifest.json +4 -4
- package/package.json +6 -6
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/.cursor-plugin/plugin.json +1 -1
- package/plugin/hooks/README.md +9 -3
- package/plugin/hooks/hooks.json +6 -0
- package/plugin/scripts/guardrail-record-tests.sh +5 -4
- package/plugin/scripts/guardrails.mjs +11 -3
- package/plugin/scripts/reconcile-stale-watchers.sh +59 -0
- package/plugin/skills/_shared/post-merge-cleanup.md +2 -3
- package/plugin/skills/_shared/session-state-writes.md +1 -1
- package/plugin/skills/_shared/telemetry-events/muggle-do-cycle.md +1 -1
- package/plugin/skills/do/e2e-acceptance.md +2 -0
- package/plugin/skills/do/resolve-conflicts.md +5 -5
- package/plugin/skills/do/respawn-watcher.md +4 -14
- package/plugin/skills/muggle-pr-followup/CLAUDE.md +3 -2
- package/plugin/skills/muggle-pr-followup/SKILL.md +5 -1
- package/plugin/skills/muggle-pr-followup/arm-watcher.md +12 -0
- package/plugin/skills/muggle-pr-followup/auto-track.md +5 -11
- package/plugin/skills/muggle-pr-followup/blocked-tick.md +10 -10
- package/plugin/skills/muggle-pr-followup/bootstrap.md +4 -8
- package/plugin/skills/muggle-pr-followup/contract.md +13 -7
- package/plugin/skills/muggle-pr-followup/evals/evals.json +101 -0
- package/plugin/skills/muggle-pr-followup/output-templates/bootstrap.md +2 -2
- package/plugin/skills/muggle-pr-followup/reconcile.md +10 -0
- package/plugin/skills/muggle-pr-followup/state-schemas.md +19 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "muggle",
|
|
3
3
|
"description": "Run real-browser end-to-end (E2E) acceptance tests on your web app from any AI coding agent. Generate test scripts from plain English, replay them on localhost, capture screenshots, and validate user flows like signup, checkout, and dashboards. Works across Claude Code, Cursor, Codex, and Windsurf.",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.6.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Muggle AI",
|
|
7
7
|
"email": "support@muggle-ai.com"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "muggle",
|
|
3
3
|
"displayName": "Muggle AI",
|
|
4
4
|
"description": "Ship quality products with AI-powered end-to-end (E2E) acceptance testing that validates your web app like a real user — from Claude Code and Cursor to PR.",
|
|
5
|
-
"version": "5.
|
|
5
|
+
"version": "5.6.0",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Muggle AI",
|
|
8
8
|
"email": "support@muggle-ai.com"
|
|
@@ -20,7 +20,7 @@ A guardrail emits one of two strengths:
|
|
|
20
20
|
- **Advise** — `additionalContext` (PostToolUse/UserPromptSubmit) or a plain Stop message. A soft nudge the model can ignore.
|
|
21
21
|
- **Enforce** — a `Stop` `decision: "block"` that refuses to end the turn, or a `PreToolUse` `permissionDecision: "deny"` that refuses a tool call. The model cannot proceed until the condition is met.
|
|
22
22
|
|
|
23
|
-
Enforcement is reserved for the handoffs that were being skipped: the E2E acceptance run and posting a deterministically-rendered report. Each enforcing gate carries an escape so it can't trap a turn — the E2E gate
|
|
23
|
+
Enforcement is reserved for the handoffs that were being skipped: the E2E acceptance run and posting a deterministically-rendered report. Each enforcing gate carries an escape so it can't trap a turn — the E2E gate accepts an explicit skip declaration (`echo "MUGGLE_E2E_SKIP: <reason>"`, session-durable) and hard-releases after `MAX_E2E_BLOCKS` (3) blocks; the report gate only denies a body it can positively see is a hand-written report and fails open otherwise.
|
|
24
24
|
|
|
25
25
|
## Mechanism
|
|
26
26
|
|
|
@@ -31,7 +31,13 @@ Each guardrail is a thin bash wrapper in `../scripts/` registered in `hooks.json
|
|
|
31
31
|
| Hook event | Wrapper | Strength | Condition | Preference | Effect |
|
|
32
32
|
| :--------- | :------ | :------- | :-------- | :--------- | :----- |
|
|
33
33
|
| `PostToolUse` (Bash) | `guardrail-pr-opened.sh` | advise | a `gh pr create`/`gh pr ready` just succeeded | `autoWatchPR` | start a `muggle-pr-followup` watcher on the new PR |
|
|
34
|
-
| `PostToolUse` (Bash + muggle execute/replay MCP tools) | `guardrail-record-tests.sh` | record | a unit-test command passed,
|
|
34
|
+
| `PostToolUse` (Bash + muggle execute/replay MCP tools) | `guardrail-record-tests.sh` | record | a unit-test command passed, an E2E run happened, or an `echo "MUGGLE_E2E_SKIP: <reason>"` marker declared E2E un-runnable | — | set `unitTestsGreen` / `e2eRun` / `e2eSkipped` session state |
|
|
35
35
|
| `PreToolUse` (Bash) | `guardrail-report-format.sh` | **enforce** | a `gh pr comment\|create\|edit` body reads like an E2E report but lacks the `build-pr-section` sentinel | — | **deny** — render via `muggle build-pr-section` instead |
|
|
36
|
-
| `Stop` | `guardrail-e2e-gate.sh` | **enforce** | unit tests passed this session
|
|
36
|
+
| `Stop` | `guardrail-e2e-gate.sh` | **enforce** | unit tests passed this session, no E2E ran yet, and no skip was recorded | `autoE2ETest` | **block** the turn until E2E runs via `muggle-test` or a `MUGGLE_E2E_SKIP` marker records a legitimate skip (full message once, one-line reminders after; releases after 3 blocks) |
|
|
37
37
|
| `UserPromptSubmit` | `guardrail-build-router.sh` | advise | a build/implement/fix request (first one this session) | `autoRouteBuildToMuggleDo` | route the work through `muggle-do` (build delegated to superpowers) |
|
|
38
|
+
|
|
39
|
+
## Session-start reconcile nudge
|
|
40
|
+
|
|
41
|
+
`SessionStart` (`scripts/reconcile-stale-watchers.sh`) — a standalone advisory, not part of the `guardrails.mjs` decision tree above.
|
|
42
|
+
|
|
43
|
+
`muggle-pr-followup` watchers are session-only `/loop` crons; they die on session end and the 7-day `/loop` expiry, leaving open PRs with no live poller. The skill's [`reconcile`](../skills/muggle-pr-followup/reconcile.md) procedure recovers them — finalizes slots whose PR went terminal, sweeps orphan crons, re-arms silently-stopped open watchers — but re-arming needs the `CronCreate` tool, which a shell hook can't call. So this hook nudges rather than acts: it scans `~/.muggle-ai/muggle-do/sessions/*/` for open slots (a `prs.json` with no `result.md`) and, **only when one or more exist**, injects `additionalContext` telling the agent to run `/muggle:muggle-pr-followup reconcile`. Zero open slots → it emits nothing. A pure directory scan (no `gh`, no writes), so it's cheap enough for every session start.
|
|
@@ -9,6 +9,12 @@
|
|
|
9
9
|
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/ensure-electron-app.sh\"",
|
|
10
10
|
"async": false,
|
|
11
11
|
"timeout": 120
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"type": "command",
|
|
15
|
+
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/reconcile-stale-watchers.sh\"",
|
|
16
|
+
"async": false,
|
|
17
|
+
"timeout": 10
|
|
12
18
|
}
|
|
13
19
|
]
|
|
14
20
|
}
|
|
@@ -8,12 +8,13 @@ set -uo pipefail
|
|
|
8
8
|
#
|
|
9
9
|
# Fires after every Bash call and every muggle execute/replay, so a keyword
|
|
10
10
|
# pre-filter for test runners and the muggle E2E tool names keeps Node off the
|
|
11
|
-
# hot path. Only a `test` command (npm/pnpm/yarn/jest/vitest/pytest/go/cargo)
|
|
12
|
-
# a muggle execute/replay/test-generation event
|
|
13
|
-
# then inspects the output for pass/fail and updates
|
|
11
|
+
# hot path. Only a `test` command (npm/pnpm/yarn/jest/vitest/pytest/go/cargo),
|
|
12
|
+
# a muggle execute/replay/test-generation event, or an E2E skip marker reaches
|
|
13
|
+
# guardrails.mjs, which then inspects the output for pass/fail and updates
|
|
14
|
+
# state. Degrades to {}.
|
|
14
15
|
payload="$(cat)"
|
|
15
16
|
|
|
16
|
-
if ! grep -Eiq '(pnpm|npm|yarn)[[:space:]]+(run[[:space:]]+)?test|jest|vitest|pytest|go[[:space:]]+test|cargo[[:space:]]+test|muggle.*(execute|test-generation|replay)' <<<"$payload"; then
|
|
17
|
+
if ! grep -Eiq '(pnpm|npm|yarn)[[:space:]]+(run[[:space:]]+)?test|jest|vitest|pytest|go[[:space:]]+test|cargo[[:space:]]+test|muggle.*(execute|test-generation|replay)|MUGGLE_E2E_SKIP' <<<"$payload"; then
|
|
17
18
|
printf '{}'
|
|
18
19
|
exit 0
|
|
19
20
|
fi
|
|
@@ -44,9 +44,13 @@ ${input2.tool_response?.output ?? ""}`;
|
|
|
44
44
|
var TEST_CMD = /\b(pnpm|npm|yarn)\s+(run\s+)?test\b|\b(jest|vitest|pytest)\b|\bgo\s+test\b|\bcargo\s+test\b/;
|
|
45
45
|
var FAIL = /\b\d+\s+failed\b|\bFAIL\b|✗/;
|
|
46
46
|
var E2E_TOOL = /muggle.*(execute|test-generation|replay)/i;
|
|
47
|
+
var E2E_SKIP_MARKER = /^\s*echo\s+["']?MUGGLE_E2E_SKIP\b/;
|
|
47
48
|
function isTestCommand(cmd) {
|
|
48
49
|
return TEST_CMD.test(cmd);
|
|
49
50
|
}
|
|
51
|
+
function isE2ESkipMarker(cmd) {
|
|
52
|
+
return E2E_SKIP_MARKER.test(cmd);
|
|
53
|
+
}
|
|
50
54
|
function testsPassed(input2) {
|
|
51
55
|
const out = `${input2.tool_response?.stdout ?? ""}
|
|
52
56
|
${input2.tool_response?.stderr ?? ""}`;
|
|
@@ -60,7 +64,7 @@ function isE2ERun(input2) {
|
|
|
60
64
|
// src/guardrails/shouldRunE2E.ts
|
|
61
65
|
var MAX_E2E_BLOCKS = 3;
|
|
62
66
|
function shouldRunE2E(state) {
|
|
63
|
-
return state.unitTestsGreen === true && state.e2eRun !== true;
|
|
67
|
+
return state.unitTestsGreen === true && state.e2eRun !== true && state.e2eSkipped !== true;
|
|
64
68
|
}
|
|
65
69
|
function applyRecordedRun(state, run) {
|
|
66
70
|
let next = state;
|
|
@@ -70,6 +74,9 @@ function applyRecordedRun(state, run) {
|
|
|
70
74
|
if (run.e2eRan) {
|
|
71
75
|
next = { ...next, e2eRun: true };
|
|
72
76
|
}
|
|
77
|
+
if (run.e2eSkipped) {
|
|
78
|
+
next = { ...next, e2eSkipped: true };
|
|
79
|
+
}
|
|
73
80
|
return next;
|
|
74
81
|
}
|
|
75
82
|
function e2eGateDecision(state, maxBlocks = MAX_E2E_BLOCKS) {
|
|
@@ -195,7 +202,8 @@ function recordTests() {
|
|
|
195
202
|
const state = readState(sessionId);
|
|
196
203
|
const next = applyRecordedRun(state, {
|
|
197
204
|
unitTestPassed: isTestCommand(cmd) && testsPassed(input),
|
|
198
|
-
e2eRan: isE2ERun(input)
|
|
205
|
+
e2eRan: isE2ERun(input),
|
|
206
|
+
e2eSkipped: isE2ESkipMarker(cmd)
|
|
199
207
|
});
|
|
200
208
|
if (next !== state) writeState(next);
|
|
201
209
|
return "{}";
|
|
@@ -206,7 +214,7 @@ function e2eGate() {
|
|
|
206
214
|
if (decision.action === "none" /* None */ || decision.action === "release" /* Release */) return "{}";
|
|
207
215
|
state.e2eBlockCount = decision.blockCount;
|
|
208
216
|
writeState(state);
|
|
209
|
-
const reason = `Do not end the turn yet. Unit tests passed this session but no E2E acceptance run has happened. Per the autoE2ETest preference (default: always), run change-driven E2E now via /muggle:muggle-test, then finish. If E2E genuinely cannot run here (no app, services down, no PR),
|
|
217
|
+
const reason = decision.blockCount === 1 ? `Do not end the turn yet. Unit tests passed this session but no E2E acceptance run has happened. Per the autoE2ETest preference (default: always), run change-driven E2E now via /muggle:muggle-test, then finish. If E2E genuinely cannot run here (no app to drive, services down, no PR), tell the user why and run \`echo "MUGGLE_E2E_SKIP: <reason>"\` \u2014 that records the skip and keeps this gate quiet for the rest of the session.` : `E2E acceptance run still owed (reminder ${decision.blockCount}/${MAX_E2E_BLOCKS}): run /muggle:muggle-test, or record a legitimate skip via \`echo "MUGGLE_E2E_SKIP: <reason>"\`.`;
|
|
210
218
|
return blockStop(reason, host);
|
|
211
219
|
}
|
|
212
220
|
function reportGate() {
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
set -euo pipefail
|
|
4
|
+
|
|
5
|
+
# muggle-pr-followup watchers are session-only crons — they die on session end
|
|
6
|
+
# and on the 7-day /loop expiry, leaving open PRs with no live poller. Re-arming
|
|
7
|
+
# needs CronCreate, a Claude tool a shell hook can't call, so this hook can't
|
|
8
|
+
# recover a watcher itself. It nudges instead: on session start, if any open slot
|
|
9
|
+
# exists, it tells the agent to run reconcile (which finalizes terminal slots and
|
|
10
|
+
# re-arms silently-dead open watchers). A pure directory scan — no gh, no writes —
|
|
11
|
+
# so it stays cheap enough to run on every session start.
|
|
12
|
+
|
|
13
|
+
escape_for_json() {
|
|
14
|
+
local s="$1"
|
|
15
|
+
s="${s//\\/\\\\}"
|
|
16
|
+
s="${s//\"/\\\"}"
|
|
17
|
+
s="${s//$'\n'/\\n}"
|
|
18
|
+
s="${s//$'\r'/\\r}"
|
|
19
|
+
s="${s//$'\t'/\\t}"
|
|
20
|
+
printf '%s' "$s"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
# A slot is a live-or-dead open watcher iff it has prs.json (a tracked PR) but no
|
|
24
|
+
# result.md (not yet finalized). result.md is the terminal marker.
|
|
25
|
+
sessions_dir="${HOME}/.muggle-ai/muggle-do/sessions"
|
|
26
|
+
stale_count=0
|
|
27
|
+
if [ -d "$sessions_dir" ]; then
|
|
28
|
+
for slot in "$sessions_dir"/*/; do
|
|
29
|
+
[ -d "$slot" ] || continue
|
|
30
|
+
if [ -f "${slot}prs.json" ] && [ ! -f "${slot}result.md" ]; then
|
|
31
|
+
stale_count=$((stale_count + 1))
|
|
32
|
+
fi
|
|
33
|
+
done
|
|
34
|
+
fi
|
|
35
|
+
|
|
36
|
+
# Clean state: no open slots to reconcile → stay completely silent, never nudge.
|
|
37
|
+
if [ "$stale_count" -eq 0 ]; then
|
|
38
|
+
exit 0
|
|
39
|
+
fi
|
|
40
|
+
|
|
41
|
+
if [ "$stale_count" -eq 1 ]; then
|
|
42
|
+
slot_word="slot"
|
|
43
|
+
else
|
|
44
|
+
slot_word="slots"
|
|
45
|
+
fi
|
|
46
|
+
|
|
47
|
+
context="muggle-pr-followup: ${stale_count} open watcher ${slot_word} found (a tracked PR with no result.md). Session-only watcher crons die on session end and after the 7-day /loop expiry, so these may have no live poller. Run \`/muggle:muggle-pr-followup reconcile\` to finalize any whose PR went terminal and re-arm silently-stopped open watchers. Reconcile is idempotent — it re-arms only genuinely dead watchers and stays quiet on the rest."
|
|
48
|
+
|
|
49
|
+
escaped_context=$(escape_for_json "$context")
|
|
50
|
+
|
|
51
|
+
if [ -n "${CURSOR_PLUGIN_ROOT:-}" ]; then
|
|
52
|
+
printf '{\n "additional_context": "%s"\n}\n' "$escaped_context"
|
|
53
|
+
elif [ -n "${CLAUDE_PLUGIN_ROOT:-}" ]; then
|
|
54
|
+
printf '{\n "hookSpecificOutput": {\n "hookEventName": "SessionStart",\n "additionalContext": "%s"\n }\n}\n' "$escaped_context"
|
|
55
|
+
else
|
|
56
|
+
printf '{\n "additional_context": "%s"\n}\n' "$escaped_context"
|
|
57
|
+
fi
|
|
58
|
+
|
|
59
|
+
exit 0
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Gated by [`autoCleanup`](../muggle-preferences/preference-gates/autoCleanup.md). Follow the standard procedure in [`preference-gates/README.md`](../muggle-preferences/preference-gates/README.md). Fire only after the PR is **merged** — never while it's still open.
|
|
4
4
|
|
|
5
|
-
On `always`, the
|
|
5
|
+
On `always`, the steps below run as one pre-authorized sequence (no per-step prompts). Stop on the first failure; do not force.
|
|
6
6
|
|
|
7
|
-
1. `git worktree remove {worktreePath}
|
|
7
|
+
1. **Remove the worktree — link-safe.** `git worktree remove {worktreePath}`, only if a worktree was used. A worktree's dependency dir (e.g. `node_modules`) is often a **link** (symlink, or a Windows junction) to a shared tree, not a real copy — and a forced/recursive delete follows the link and wipes that shared target, breaking every worktree. So never `--force`: unlink the dependency link first (remove the link only, using the host OS's unlink), then a plain `git worktree remove {worktreePath}`.
|
|
8
8
|
2. `git branch -d {branch}` — **skip when no worktree was used**: the branch is the user's current live checkout (a bootstrap/auto-track watcher), and the checked-out branch must never be deleted. Then `git push origin --delete {branch}`.
|
|
9
9
|
3. Clear `.muggle-ai/` session folders for this branch's runs and stale `/tmp/muggle-prepare-*.log` files. Cloud results stay.
|
|
10
|
-
4. Invoke `commit-commands:clean_gone` via the `Skill` tool.
|
|
@@ -18,5 +18,5 @@ If you script the rewrite instead of using the Write tool, any tool that replace
|
|
|
18
18
|
|
|
19
19
|
## Field map
|
|
20
20
|
|
|
21
|
-
- `last_seen.json` — one object keyed by `"<owner>/<repo>#<n>"`. Mutate fields under that key: `idle_tick_count`, `cycles_completed` (counters), `last_pushed_sha`, `lastBodyReviewId` (scalars), `pushed_shas`, `escalated_review_ids`, `ci_escalated_shas`, `
|
|
21
|
+
- `last_seen.json` — one object keyed by `"<owner>/<repo>#<n>"`. Mutate fields under that key: `idle_tick_count`, `cycles_completed` (counters), `last_pushed_sha`, `lastBodyReviewId` (scalars), `pushed_shas`, `escalated_review_ids`, `ci_escalated_shas`, `conflict_escalated_keys` (arrays), `ci_fix_attempts[<sha>]` (keyed by head SHA), `conflict_resolve_attempts[<head-sha>..<base-tip-sha>]` (keyed by the head/base-tip pair).
|
|
22
22
|
- `prs.json` — a one-element array. Mutate `[0]`: `head_sha`, `state`.
|
|
@@ -30,6 +30,6 @@ One per address-reviews invocation, regardless of outcome.
|
|
|
30
30
|
- `"ci-fixed"` — a watcher-dispatched fix-ci cycle pushed a fix for one or more red checks.
|
|
31
31
|
- `"ci-escalated"` — fix-ci exhausted its 3 attempts for the SHA or the failing checks were out of scope; the SHA was added to `ci_escalated_shas`. No further auto-fix on it.
|
|
32
32
|
- `"rebased"` — a watcher-dispatched rebase cycle rebased the branch onto its base (behind-only or conflicts resolved), verified, and force-pushed.
|
|
33
|
-
- `"rebase-escalated"` — the rebase couldn't be completed (a conflict under `autoResolveConflicts=never`, verification failed, or the 2-attempt budget for the
|
|
33
|
+
- `"rebase-escalated"` — the rebase couldn't be completed (a conflict under `autoResolveConflicts=never`, verification failed, or the 2-attempt budget for the head/base-tip pair was spent); the pair was added to `conflict_escalated_keys`. No further auto-rebase until either side moves.
|
|
34
34
|
|
|
35
35
|
For fix-ci cycles (`ci-fixed` / `ci-escalated`) the `review_ids_*` arrays are empty and the `ci_checks_*` arrays carry the data: `ci_checks_in` (red checks dispatched), `ci_checks_fixed` (made green and pushed), `ci_checks_escalated` (out-of-scope or unresolved). For rebase cycles (`rebased` / `rebase-escalated`) all the `review_ids_*` and `ci_checks_*` arrays are empty; the SHA fields carry the before/after of the rebase.
|
|
@@ -20,6 +20,8 @@ This stage is **mode-driven by pre-flight**:
|
|
|
20
20
|
|
|
21
21
|
- `local-e2e` runs the local browser flow (`test-feature-local` approach).
|
|
22
22
|
- `unit-only` or `skip` does not execute browser runs and must emit an explicit non-pass verdict (`SKIPPED` / `UNIT-ONLY` equivalent in downstream reporting).
|
|
23
|
+
|
|
24
|
+
**Every SKIPPED exit from this stage** (Step 0 poll-only, Step 1 `unit-only`/`skip`, Step 1.5 placeholder branch) also runs `echo "MUGGLE_E2E_SKIP: <one-line reason>"` as a single Bash call before exiting — it records the skip in guardrail session state so the Stop-hook E2E gate releases instead of blocking the turn.
|
|
23
25
|
- `staging-replay` is not executed in this stage path and should be surfaced as `INCONCLUSIVE` unless the caller has already routed to a dedicated staging runner.
|
|
24
26
|
|
|
25
27
|
For local runs, the tool boundaries are:
|
|
@@ -14,13 +14,13 @@ Rebase a PR's branch onto its base — whether it's merely **behind** (out of da
|
|
|
14
14
|
|
|
15
15
|
## Inputs from disk
|
|
16
16
|
|
|
17
|
-
From `~/.muggle-ai/muggle-do/sessions/<slug>/`: `prs.json` (PR + branch + `head_sha`), `last_seen.json` (`conflict_resolve_attempts`, `
|
|
17
|
+
From `~/.muggle-ai/muggle-do/sessions/<slug>/`: `prs.json` (PR + branch + `head_sha`), `last_seen.json` (`conflict_resolve_attempts`, `conflict_escalated_keys`, `pushed_shas`), `state.md` (worktree path, validation strategy, base branch).
|
|
18
18
|
|
|
19
19
|
## Procedure
|
|
20
20
|
|
|
21
21
|
### Step 1 — Re-attach
|
|
22
22
|
|
|
23
|
-
Materialize the PR branch in its worktree per [`../_shared/pr-branch-worktree.md`](../_shared/pr-branch-worktree.md) (or use `state.md`'s `worktreePath`). Capture `rebase_sha = prs.json[0].head_sha` and the base branch (`baseRefName` from [`../_shared/vcs/github/pr-metadata.md`](../_shared/vcs/github/pr-metadata.md)).
|
|
23
|
+
Materialize the PR branch in its worktree per [`../_shared/pr-branch-worktree.md`](../_shared/pr-branch-worktree.md) (or use `state.md`'s `worktreePath`). Capture `rebase_sha = prs.json[0].head_sha` and the base branch (`baseRefName` from [`../_shared/vcs/github/pr-metadata.md`](../_shared/vcs/github/pr-metadata.md)). Capture the base tip too — `.base_commit.sha` from that recipe's `compare` call — and form `rebase_key = "<rebase_sha>..<base_tip_sha>"`. Both budget fields below are keyed on that pair, matching the watcher's Step 5; writing a bare SHA instead leaves an entry the watcher ignores, and the rebase re-dispatches forever.
|
|
24
24
|
|
|
25
25
|
### Step 2 — Rebase onto base (resolve conflicts if any)
|
|
26
26
|
|
|
@@ -37,13 +37,13 @@ Build (typecheck + lint on the changed surface) + unit suite must pass. Run E2E
|
|
|
37
37
|
|
|
38
38
|
### Step 4 — Force-push + respawn
|
|
39
39
|
|
|
40
|
-
Push with `--force-with-lease` (the rebase rewrote history). Append the new SHA to `last_seen.pushed_shas`; increment `last_seen.conflict_resolve_attempts[
|
|
40
|
+
Push with `--force-with-lease` (the rebase rewrote history). Append the new SHA to `last_seen.pushed_shas`; increment `last_seen.conflict_resolve_attempts[rebase_key]` — both whole-file rewrites (Read → change field → Write) per [`../_shared/session-state-writes.md`](../_shared/session-state-writes.md), never the Edit tool. Respawn the watcher per [`respawn-watcher.md`](respawn-watcher.md). Its next tick re-checks the branch against its base on the new head — the rebase is its own verify loop, bounded by the per-SHA attempt budget.
|
|
41
41
|
|
|
42
42
|
### Step 5 — Escalate (can't resolve / budget spent)
|
|
43
43
|
|
|
44
|
-
When `autoResolveConflicts=never`, the resolution failed verification, or `conflict_resolve_attempts[
|
|
44
|
+
When `autoResolveConflicts=never`, the resolution failed verification, or `conflict_resolve_attempts[rebase_key]` has reached 2:
|
|
45
45
|
|
|
46
|
-
1. Add `
|
|
46
|
+
1. Add `rebase_key` to `last_seen.conflict_escalated_keys` so the watcher does not re-dispatch this head against this base. If the base later moves, the key changes and the branch re-arms on its own — a conflict the user resolved upstream stops being this watcher's dead end.
|
|
47
47
|
2. Emit one terminal escalation naming the PR and the conflicting files (or the failing verification, for a behind-only rebase that didn't verify).
|
|
48
48
|
3. Respawn the watcher per [`respawn-watcher.md`](respawn-watcher.md) — it keeps polling for the user's manual resolution or any new reviews.
|
|
49
49
|
|
|
@@ -1,26 +1,16 @@
|
|
|
1
1
|
# Respawn the watcher
|
|
2
2
|
|
|
3
|
-
The single, guaranteed watcher restart shared by every watcher-dispatched `/muggle-do` mode — address-reviews, fix-ci, and rebase.
|
|
3
|
+
The single, guaranteed watcher restart shared by every watcher-dispatched `/muggle-do` mode — address-reviews, fix-ci, and rebase. Dispatch ends the active watch ([`../muggle-pr-followup/contract.md`](../muggle-pr-followup/contract.md) Steps 4 / 5 / 6), so for the duration of the cycle nothing watches this PR. Respawning is what arms the next watch. This is a runtime dispatch of the watcher's arming, not a doc dependency on its caller — allowed per the one-way rule in [`../CLAUDE.md`](../CLAUDE.md).
|
|
4
4
|
|
|
5
5
|
## The guarantee
|
|
6
6
|
|
|
7
|
-
Respawn is the **last action on every exit path that leaves the PR open** — the happy path *and* every escalation, early-exit, or abort.
|
|
8
|
-
|
|
9
|
-
The one exception is a **terminal** PR (merged or closed): a terminal PR needs no watcher, so the terminal branch finalizes instead of respawning.
|
|
7
|
+
Respawn is the **last action on every exit path that leaves the PR open** — the happy path *and* every escalation, early-exit, or abort. Any open-PR exit that skips respawn leaves the slot with nothing watching: the PR sits silent until a session restart or a reconcile sweep re-arms it. That silent stop is the exact failure this file exists to prevent, so treat "did I respawn on this branch?" as a checklist item on every exit, not only the success case.
|
|
10
8
|
|
|
11
9
|
## Procedure
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
1. **Refresh PR state** — `github` per [`../_shared/vcs/github/pr-metadata.md`](../_shared/vcs/github/pr-metadata.md), `gitlab` per [`../_shared/vcs/gitlab/mr-metadata.md`](../_shared/vcs/gitlab/mr-metadata.md).
|
|
16
|
-
2. **If merged or closed** → write `result.md` per [`../muggle-pr-followup/state-schemas.md`](../muggle-pr-followup/state-schemas.md#resultmd) and **do not respawn**. The PR is terminal; the watcher's job is done.
|
|
17
|
-
3. **Otherwise** → dispatch, verbatim, as the turn's last action:
|
|
18
|
-
|
|
19
|
-
```
|
|
20
|
-
/loop 1m /muggle:muggle-pr-followup <slug> <n>
|
|
21
|
-
```
|
|
11
|
+
As the final action of the turn, settle the watch per [`../muggle-pr-followup/arm-watcher.md`](../muggle-pr-followup/arm-watcher.md): its drain tick finalizes a terminal PR (merged or closed — the monitor exits on its own at terminal), dispatches a follow-on cycle if feedback arrived while this one ran, or advances the watermark — arming a fresh monitor only if none is alive.
|
|
22
12
|
|
|
23
|
-
|
|
13
|
+
A cycle is not finished while its per-comment replies are unposted. A blocked reply — e.g. GitHub refuses with 422 while the reviewer's own pending review is open — escalates to the owner and holds this arming until the replies land. Never resume the watch over unposted replies.
|
|
24
14
|
|
|
25
15
|
## Recovery net
|
|
26
16
|
|
|
@@ -6,13 +6,14 @@ This folder holds the watcher loop that drives one PR toward merge-ready. The wa
|
|
|
6
6
|
|
|
7
7
|
- [`SKILL.md`](SKILL.md) — public entry. Routing between bootstrap (URL input), tick (slug + PR number), and auto-track (no args). Read first.
|
|
8
8
|
- [`auto-track.md`](auto-track.md) — the no-args procedure: discovers PRs pushed this session (any repo) and seeds one poll-only watcher each. Seeds no E2E context — the watcher only watches.
|
|
9
|
-
- [`bootstrap.md`](bootstrap.md) — the bootstrap procedure (resolves the validation context once when the PR has a testable surface — else seeds poll-only like auto-track — then
|
|
9
|
+
- [`bootstrap.md`](bootstrap.md) — the bootstrap procedure (resolves the validation context once when the PR has a testable surface — else seeds poll-only like auto-track — then arms the first watch).
|
|
10
|
+
- [`arm-watcher.md`](arm-watcher.md) — the drain-then-watch arming sequence shared by bootstrap, auto-track, and the executor's respawn: one tick, then a persistent labeled monitor.
|
|
10
11
|
- [`contract.md`](contract.md) — the watcher per-tick procedure (poll → dispatch → exit; on a human-blocked PR it reminds the owner each tick at the normal `1m` cadence, resuming evaluation on external change).
|
|
11
12
|
- [`blocked-tick.md`](blocked-tick.md) — the conditional blocked-path detail: fingerprint, flag-and-remind (Step 7), and remind-or-resume (Step 2.5), all at the normal `1m` cadence. Referenced by `contract.md`; runs only while `last_seen.blocked` is set.
|
|
12
13
|
- [`finalize.md`](finalize.md) — shared termination sequence for a terminal PR (mark terminal, `result.md`, log/telemetry, unschedule cron, post-merge cleanup handoff). Called by `contract.md` and `reconcile.md`.
|
|
13
14
|
- [`cancel-cron.md`](cancel-cron.md) — stops this watcher's cron, recorded-id-first (survives `CronList` going blind) with a `CronList`-match fallback, plus the tool-call-not-shell guard. Referenced by `contract.md` and `finalize.md`.
|
|
14
15
|
- [`record-cron-id.md`](record-cron-id.md) — the per-tick self-record that keeps this slot's cron id in `cron.json` deletable after a compaction blinds `CronList`. Referenced by `contract.md` Step 0.
|
|
15
|
-
- [`reconcile.md`](reconcile.md) — sweep that finalizes slots whose PR went terminal while polling lapsed, deletes orphaned crons, and re-arms open slots whose watcher stopped silently (dropped respawn); runs at the top of auto-track and
|
|
16
|
+
- [`reconcile.md`](reconcile.md) — sweep that finalizes slots whose PR went terminal while polling lapsed, deletes orphaned crons, and re-arms open slots whose watcher stopped silently (dropped respawn); runs on demand, at the top of auto-track, and nudged by a session-start hook.
|
|
16
17
|
- [`state-schemas.md`](state-schemas.md) — canonical JSON shapes of session state files.
|
|
17
18
|
- [`output-templates.md`](output-templates.md) — TOC of message templates; per-group files in `output-templates/`.
|
|
18
19
|
|
|
@@ -14,7 +14,9 @@ A watcher that babysits one open PR toward **merge-ready** — review threads ad
|
|
|
14
14
|
|
|
15
15
|
**Per-PR isolation.** One watcher per PR. Multi-PR work runs N independent watchers.
|
|
16
16
|
|
|
17
|
-
**
|
|
17
|
+
**Arming.** Bootstrap, auto-track, and the executor's post-cycle respawn all arm the watch the same way — one drain tick, then one persistent labeled monitor per PR — visible as a running task for as long as the PR is polled, gone at terminal ([`arm-watcher.md`](arm-watcher.md)). Crons are the recovery substrate only ([`reconcile.md`](reconcile.md)).
|
|
18
|
+
|
|
19
|
+
**One reminder when blocked pending a human.** When a PR can't progress without the user — an escalated rebase/CI budget spent, or an ambiguous review awaiting direction — the tick that flags the block emits **one** one-line reminder: the pending act plus a reference back to the decision context ([`contract.md`](contract.md) Steps 2.5, 7). After that the watch stays visible and silent — no repeat nagging — and the block clears the instant a wake finds a push, review, or CI/deploy state moved.
|
|
18
20
|
|
|
19
21
|
**Cron lifecycle.** Each tick records its `/loop` cron id to `cron.json` while `CronList` can still see it ([`record-cron-id.md`](record-cron-id.md)), so teardown can delete the cron by id after a session continue / compaction blinds `CronList` to it. Reconcile ([`reconcile.md`](reconcile.md)) sweeps crons whose PR is terminal or whose slot is gone, and re-arms an open slot whose watcher stopped silently.
|
|
20
22
|
|
|
@@ -35,6 +37,8 @@ The skill recognizes its mode by inspecting `$ARGUMENTS` and falling back to on-
|
|
|
35
37
|
|
|
36
38
|
Auto-track runs **reconcile** first, so a no-arg invocation also finalizes any slot whose PR merged or closed while its watcher was down (expired cron, ended session) and re-arms any open slot whose watcher stopped silently (a dropped respawn). Reconcile recovers a watcher that was already running; it never seeds a first watcher for a PR — that is auto-track's / bootstrap's job.
|
|
37
39
|
|
|
40
|
+
**Reconcile also runs at session start** — a `SessionStart` hook ([`../../hooks/README.md`](../../hooks/README.md)) surfaces the sweep when open slots exist, catching a watcher that died with its session (end, or 7-day `/loop` expiry) before a manual sweep would. See [`reconcile.md`](reconcile.md#triggers).
|
|
41
|
+
|
|
38
42
|
Bootstrap accepts three optional trailing flags:
|
|
39
43
|
|
|
40
44
|
- `--slug=<name>` — override the default `<repo>-pr<n>` slug
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Arming the Watch
|
|
2
|
+
|
|
3
|
+
How an orchestrating session starts the watch on one PR. Every arming point runs this same sequence: [`bootstrap.md`](bootstrap.md) Step 8, [`auto-track.md`](auto-track.md) Step 6, and the executor's post-cycle settle.
|
|
4
|
+
|
|
5
|
+
1. **Drain.** Run one tick per [`contract.md`](contract.md). It acts on everything already outstanding — actionable threads, body-only reviews past the watermark, a stale branch, red CI — and finalizes a terminal PR. If the tick dispatched a cycle, stop here: the cycle's exit path settles the watch when it finishes.
|
|
6
|
+
2. **Seed the watermark.** Write the slot's watch watermark ([`state-schemas.md`](state-schemas.md#watch-watermarkenv)) from a fetch taken after the drain completes. Never let the loop capture its own baseline — anything landing between drain and launch would be swallowed.
|
|
7
|
+
3. **Watch.** Write the loop as `watch.sh` in the slot and start it as a **persistent background monitor** in the orchestrating session — the command is the one-line script path, and the label is `PR #<n> — <title>`. Both matter: some task surfaces show the label, others show the command, and a slot-path command keeps the watch identifiable everywhere a raw script blob would not. One monitor per PR, alive from arm to terminal: it is the watch's visible handle, showing as a running task the entire time the PR is polled. Its loop checks about every 60 seconds, re-reading the watermark each iteration; on a newer submitted review, a newer thread comment, or a thread newly unresolved it prints one line and **keeps watching** — advancing its in-memory floor so each event prints exactly once. It exits only when the PR goes terminal or after five consecutive failed fetches. Quiet iterations print nothing and cost nothing — no model tokens are spent while the watch is quiet.
|
|
8
|
+
4. **On event.** The monitor's line wakes the session: run the tick (step 1), which derives everything from live provider state; a terminal PR finalizes there while the monitor exits on its own. Persistent fetch failure → surface the reason; [`reconcile.md`](reconcile.md) re-arms the slot on its next sweep.
|
|
9
|
+
|
|
10
|
+
**After a cycle** — advance the watermark file from a fetch taken after the replies land; that write is what stops the loop from reporting the loop's own reply. A cycle that skips the advance leaves the watermark stale, and the next event will be an echo. Arm a fresh monitor only when none is alive (session restart, killed task); the settle path never duplicates a running watch.
|
|
11
|
+
|
|
12
|
+
Drain-then-watch is the invariant: the tick handles everything up to the watermark with the real semantics — marker rule, watermark, attempt budgets — that the watch deliberately lacks, so the monitor only needs to see what arrives after it.
|
|
@@ -67,22 +67,16 @@ Already tracking (skipped):
|
|
|
67
67
|
...
|
|
68
68
|
(or "none")
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
Arming:
|
|
71
|
+
<owner>/<repo>#<n>
|
|
72
72
|
...
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
Print the summary **before** the
|
|
75
|
+
Print the summary **before** arming the watchers so it stays visible.
|
|
76
76
|
|
|
77
|
-
### Step 6 —
|
|
77
|
+
### Step 6 — Arm the watchers
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
```
|
|
82
|
-
/loop 1m /muggle:muggle-pr-followup <slug> <n>
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
Each registers an independent cron — the N-independent-watchers model from [`SKILL.md`](SKILL.md).
|
|
79
|
+
Arm one watch per **newly tracked** PR (not the skipped ones), per [`arm-watcher.md`](arm-watcher.md). Each watch is independent — one drain tick and one labeled monitor per PR.
|
|
86
80
|
|
|
87
81
|
### Step 7 — Emit telemetry
|
|
88
82
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Blocked-tick procedure
|
|
2
2
|
|
|
3
|
-
The watcher's conditional path for a PR **blocked pending a human** — a durable block only the user can clear (an escalated rebase or CI budget spent, or an ambiguous review awaiting direction). Entered from [`contract.md`](contract.md) Step 7 (flag), then driven each subsequent tick by Step 2.5 (
|
|
3
|
+
The watcher's conditional path for a PR **blocked pending a human** — a durable block only the user can clear (an escalated rebase or CI budget spent, or an ambiguous review awaiting direction). Entered from [`contract.md`](contract.md) Step 7 (flag), then driven on each subsequent tick by Step 2.5 (resume gate). None of this runs on a normal tick: when `last_seen.blocked` is absent, the watcher skips straight through.
|
|
4
4
|
|
|
5
|
-
**Governing rule —
|
|
5
|
+
**Governing rule — one reminder per block, and the watch never stops.** The tick that flags the block reminds the owner once; every later blocked tick is silent. The watch keeps standing — the monitor stays visible, and ticks still run at their normal cadence (historically `1m`) whenever a wake or recovery cron fires — with fingerprint-based auto-resume clearing the block the moment external state moves. No repeat nagging, no cadence swap, no separate `reminded` flag: `blocked` present means the reminder has already been sent.
|
|
6
6
|
|
|
7
7
|
## The fingerprint
|
|
8
8
|
|
|
@@ -20,19 +20,19 @@ When an idle tick is a durable human-block and `last_seen.blocked` is not alread
|
|
|
20
20
|
|
|
21
21
|
1. Increment `last_seen.idle_tick_count`.
|
|
22
22
|
2. Write `last_seen.blocked = { reason, since: <now>, fingerprint }` (reuse the `latest_review_id` / `ci_digest` already fetched this tick).
|
|
23
|
-
3. **Remind the owner** — emit the one-line reminder per [`output-templates/blocked-reminder.md`](output-templates/blocked-reminder.md): the pending act plus a reference back to the decision context.
|
|
24
|
-
4. Append a `blocked reason=<reason>` line to `followup.log` per [`output-templates/watcher-log.md`](output-templates/watcher-log.md); emit a `tick` event with `idle: true`, `blocked: true`, and the same other fields as a transient idle. Exit.
|
|
23
|
+
3. **Remind the owner** — emit the one-line reminder per [`output-templates/blocked-reminder.md`](output-templates/blocked-reminder.md): the pending act plus a reference back to the decision context. This is the block's **only** reminder.
|
|
24
|
+
4. Append a `blocked reason=<reason>` line to `followup.log` per [`output-templates/watcher-log.md`](output-templates/watcher-log.md); emit a `tick` event with `idle: true`, `blocked: true`, and the same other fields as a transient idle. Exit.
|
|
25
25
|
|
|
26
26
|
## Remind or resume (the Step 2.5 gate)
|
|
27
27
|
|
|
28
28
|
Every subsequent tick while `last_seen.blocked` is present: recompute the fingerprint and compare to `last_seen.blocked.fingerprint`.
|
|
29
29
|
|
|
30
|
-
- **Unchanged** → still blocked.
|
|
31
|
-
- **Changed** → clear `last_seen.blocked` and **fall through to [`contract.md`](contract.md) Step 3** to re-evaluate against the moved state this same tick
|
|
30
|
+
- **Unchanged** → still blocked. Stay **silent** — the reminder went out when the block was flagged. Increment `last_seen.idle_tick_count`, append a `blocked reason=<reason>` line to `followup.log`, emit a `tick` event with `idle: true`, `blocked: true`. Exit.
|
|
31
|
+
- **Changed** → clear `last_seen.blocked` and **fall through to [`contract.md`](contract.md) Step 3** to re-evaluate against the moved state this same tick: a dispatch hands the PR to the cycle (its exit settles the watch); a transient idle changes nothing; idling back into a block re-flags per Step 7 — a new block, which sends its own single reminder.
|
|
32
32
|
|
|
33
33
|
## Invariants
|
|
34
34
|
|
|
35
|
-
-
|
|
36
|
-
- The
|
|
37
|
-
-
|
|
38
|
-
- The
|
|
35
|
+
- One reminder per block — sent when flagged, never repeated while the same block holds. A re-flag after a resume is a new block and sends its own single reminder.
|
|
36
|
+
- The watch never stops — a blocked PR stays visibly watched at the normal `1m` cadence; only a terminal PR or an explicit teardown ends it.
|
|
37
|
+
- The block clears the instant any fingerprint component moves, caught at the next wake or tick.
|
|
38
|
+
- The blocked path never posts to the PR.
|
|
@@ -73,7 +73,7 @@ Write under `~/.muggle-ai/muggle-do/sessions/<slug>/`:
|
|
|
73
73
|
|
|
74
74
|
**`last_seen.json`** — see [`state-schemas.md`](state-schemas.md#last_seenjson). One key (`"<owner>/<repo>#<n>"`), `lastBodyReviewId` from Step 6, `last_pushed_sha: null`, `idle_tick_count: 0`, `cycles_completed: 0`, `escalated_review_ids: []`, `pushed_shas: []`. Omit `blocked` — the watcher starts unblocked.
|
|
75
75
|
|
|
76
|
-
**`cron.json`** — see [`state-schemas.md`](state-schemas.md#cronjson). `cron_id: null` (
|
|
76
|
+
**`cron.json`** — see [`state-schemas.md`](state-schemas.md#cronjson). `cron_id: null` (bootstrap arms no cron; a tick running under one recorded by [`reconcile.md`](reconcile.md) self-records its id per [`record-cron-id.md`](record-cron-id.md)), `command: "/muggle:muggle-pr-followup <slug> <n>"`, `interval: "1m"`, `recorded_at: <now>`.
|
|
77
77
|
|
|
78
78
|
**`state.md`** — see [`state-schemas.md`](state-schemas.md#statemd). `Bootstrapped from URL: yes`. Cache the loop-user login. If Step 6.5 resolved a validation context, append the `## Pre-flight answers` block with its fields, per [`../_shared/resolve-e2e-validation-context.md`](../_shared/resolve-e2e-validation-context.md#persisted-fields). If it seeded poll-only, write **no** such block — a missing block is a clean E2E skip.
|
|
79
79
|
|
|
@@ -81,17 +81,13 @@ Do **not** write `cycle.json` or `requirements.md` — those files are no longer
|
|
|
81
81
|
|
|
82
82
|
Create `iterations/` subdir (empty) for future caller use.
|
|
83
83
|
|
|
84
|
-
### Step 8 —
|
|
84
|
+
### Step 8 — Arm the watch
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
```
|
|
89
|
-
/loop 1m /muggle:muggle-pr-followup <slug> <n>
|
|
90
|
-
```
|
|
86
|
+
Arm per [`arm-watcher.md`](arm-watcher.md) as the last action of the turn: one tick drains anything already actionable — this is the first tick Step 6 promises — then a persistent, labeled monitor keeps watch — visible until the PR terminates. The cron path stays as the recovery substrate ([`reconcile.md`](reconcile.md)), so `cron.json` is still seeded in Step 7.
|
|
91
87
|
|
|
92
88
|
### Step 9 — Print the success summary
|
|
93
89
|
|
|
94
|
-
Use the success-summary template from [`output-templates/bootstrap.md`](output-templates/bootstrap.md). Print it **before** the
|
|
90
|
+
Use the success-summary template from [`output-templates/bootstrap.md`](output-templates/bootstrap.md). Print it **before** arming the watch so it's visible.
|
|
95
91
|
|
|
96
92
|
### Step 10 — Emit telemetry
|
|
97
93
|
|
|
@@ -33,11 +33,13 @@ Every `increment`/`reset` this procedure applies to `last_seen.json`, and the `p
|
|
|
33
33
|
|
|
34
34
|
If `prs.json[0].state` on disk is already `merged` or `closed`, this slot was finalized by a prior tick and this is a stale (queued) fire — per-minute cron fires enqueued while the session was busy still drain after the cron is cancelled. Defensively cancel any lingering cron for this slug per [`cancel-cron.md`](cancel-cron.md) (no-op if none), append a `stale-tick` line to `followup.log`, and exit. Do not re-fetch or re-finalize.
|
|
35
35
|
|
|
36
|
+
**Orphan escalation — on the third or later stale fire.** Count prior `stale-tick` lines for this slot in `followup.log` before appending this one. Three or more means both `cancel-cron.md` lookups have already run on earlier stale fires and the cron still fires — it is orphaned in a session runtime neither the recorded id nor `CronList` can reach, so it will keep firing until the 7-day expiry. Escalate to the owner **once**: if `followup.log` has no `stale-orphan-escalated` line, print one line — `orphaned cron: <slug> keeps firing after finalize; no in-session cancel can reach it — restarting the Claude session is the only clean clear` — and append a `stale-orphan-escalated` line so every later stale fire absorbs silently again. Never respond to an unreachable cron by guess-deleting ids `CronList` does surface: those belong to other live watchers, and deleting one silently kills a wanted loop.
|
|
37
|
+
|
|
36
38
|
Otherwise, self-record this watcher's cron id per [`record-cron-id.md`](record-cron-id.md) before proceeding. Recording every tick — while `CronList` can still see the cron — is what keeps the id a valid `CronDelete` target after a session continue / compaction blinds `CronList` to it, so teardown ([`finalize.md`](finalize.md), [`reconcile.md`](reconcile.md)) can always kill the orphan.
|
|
37
39
|
|
|
38
40
|
### Step 1 — Refresh PR state
|
|
39
41
|
|
|
40
|
-
Per [`../_shared/vcs/github/pr-metadata.md`](../_shared/vcs/github/pr-metadata.md). Update `prs.json[0].head_sha` and `prs.json[0].state` from the response; keep `mergeable` (conflict signal) for Step 5, and run the recipe's `compare` call to capture `behind_by` (out-of-date signal)
|
|
42
|
+
Per [`../_shared/vcs/github/pr-metadata.md`](../_shared/vcs/github/pr-metadata.md). Update `prs.json[0].head_sha` and `prs.json[0].state` from the response; keep `mergeable` (conflict signal) for Step 5, and run the recipe's `compare` call to capture both `behind_by` (out-of-date signal) and `.base_commit.sha` — the base branch tip, Step 5's `base_tip_sha`.
|
|
41
43
|
|
|
42
44
|
### Step 2 — Termination check
|
|
43
45
|
|
|
@@ -58,7 +60,7 @@ If `state` is `MERGED` or `CLOSED`:
|
|
|
58
60
|
|
|
59
61
|
Only when `last_seen.blocked` is present (the watcher is awaiting the owner on a durable human-block, flagged in Step 7). When absent, skip straight to Step 3.
|
|
60
62
|
|
|
61
|
-
Run the
|
|
63
|
+
Run the resume gate per [`blocked-tick.md`](blocked-tick.md): recompute the fingerprint; while it holds, stay blocked **silently** — the single owner reminder went out when the block was flagged — and clear the block and fall through to Step 3 the moment it moves. The block never changes the poll; it only mutes dispatch until the state the user must act on moves.
|
|
62
64
|
|
|
63
65
|
### Step 3 — Compute the actionable set from live thread state
|
|
64
66
|
|
|
@@ -102,7 +104,11 @@ A merge-ready branch is **current with its base** — neither conflicting nor be
|
|
|
102
104
|
|
|
103
105
|
This trigger is **independent of approval and CI state**: an out-of-date branch is rebased whether or not it has been reviewed, approved, or has green checks. The watcher acts on staleness directly — it never waits for an approval to surface it.
|
|
104
106
|
|
|
105
|
-
|
|
107
|
+
Rebase dedup is keyed on the **pair** `rebase_key = "<head_sha>..<base_tip_sha>"`, not on the head alone. Whether a branch conflicts is a function of both sides, so a head-only key wedges a PR permanently the first time the base moves: the head cannot change while nobody pushes, so one stale entry suppresses every genuinely new conflict that base movement introduces, forever. Take `base_tip_sha` from the Step 1 compare's `.base_commit.sha` (the base branch tip, which advances when the base does) — **never** `.merge_base_commit.sha`, which does not move when only the base advances and so would never re-arm.
|
|
108
|
+
|
|
109
|
+
Entries written by an older watcher are bare head SHAs with no `..` — ignore them when reading `conflict_escalated_keys`, which re-arms any slot a head-only key had wedged.
|
|
110
|
+
|
|
111
|
+
If a rebase is due **and** `conflict_resolve_attempts[rebase_key] < 2` **and** `rebase_key` ∉ `conflict_escalated_keys` → dispatch and exit:
|
|
106
112
|
|
|
107
113
|
1. Reset `last_seen.idle_tick_count` to 0.
|
|
108
114
|
2. **Stop this watcher (single-thread):** cancel its cron exactly as in Step 4 — `/muggle-do`'s rebase respawns it when the cycle is done.
|
|
@@ -114,7 +120,7 @@ If a rebase is due **and** `conflict_resolve_attempts[head_sha] < 2` **and** `he
|
|
|
114
120
|
4. Append a dispatching line to `followup.log`; emit a `tick` event with `rebase_needed: true`, `dispatched_rebase: true`.
|
|
115
121
|
5. Exit. The dev cycle owns the PR; its respawn restarts the watcher, whose next tick re-checks the branch against its base on the new head — the rebase is its own verify loop, bounded by the per-SHA attempt budget.
|
|
116
122
|
|
|
117
|
-
Otherwise — `behind_by == 0` and not conflicting (`mergeable == UNKNOWN` is fine here: `behind_by` is exact while GitHub is still computing conflict state, so a stale branch still triggers), or budget spent (`conflict_resolve_attempts[
|
|
123
|
+
Otherwise — `behind_by == 0` and not conflicting (`mergeable == UNKNOWN` is fine here: `behind_by` is exact while GitHub is still computing conflict state, so a stale branch still triggers), or budget spent (`conflict_resolve_attempts[rebase_key] >= 2` or `rebase_key` ∈ `conflict_escalated_keys`) → fall through to CI.
|
|
118
124
|
|
|
119
125
|
### Step 6 — No actionable feedback, branch current → poll CI for the head SHA
|
|
120
126
|
|
|
@@ -137,15 +143,15 @@ Fetch the CI rollup for `prs.json[0].head_sha`, provider resolved as in Step 3
|
|
|
137
143
|
|
|
138
144
|
Any idle branch (Steps 4–6 that did not dispatch). First classify **why** this tick idled. It is **blocked pending a human** when the head is under a durable block that only the user can clear:
|
|
139
145
|
|
|
140
|
-
- `
|
|
146
|
+
- `rebase_key` ∈ `conflict_escalated_keys` — a rebase `/muggle-do` gave up on (a semantic conflict, or `autoResolveConflicts=never`), reason `conflict_escalated`. This block clears on its own when the base moves: the new `base_tip_sha` yields a key the set does not contain, and the branch re-arms for a fresh rebase attempt; or
|
|
141
147
|
- `head_sha` ∈ `ci_escalated_shas` — CI the fix-ci stage gave up on, reason `ci_escalated`; or
|
|
142
148
|
- `last_seen.escalated_review_ids` is non-empty with the actionable set empty — an ambiguous review awaiting the user's direction, reason `reviews_escalated`.
|
|
143
149
|
|
|
144
150
|
Everything else that idles is **transient** — green and waiting for the next review, CI still pending, or `mergeable == UNKNOWN` — and must keep the responsive `1m` cadence; those turn a state on their own and the watcher should catch it promptly.
|
|
145
151
|
|
|
146
|
-
**Transient idle** (no durable block): unchanged — increment `last_seen.idle_tick_count`, append an idle line to `followup.log` per [`output-templates/watcher-log.md`](output-templates/watcher-log.md), emit a `tick` event with `idle: true`, `blocked: false`, `actionable_threads: 0`, `dispatched_review_ids: []`, `rebase_needed: <bool>`, `dispatched_rebase: false`, `checks_red: <count or 0>`, `dispatched_ci_fix: false`. Exit. The next tick fires in 1 min via `/loop`.
|
|
152
|
+
**Transient idle** (no durable block): unchanged — increment `last_seen.idle_tick_count`, append an idle line to `followup.log` per [`output-templates/watcher-log.md`](output-templates/watcher-log.md), emit a `tick` event with `idle: true`, `blocked: false`, `actionable_threads: 0`, `dispatched_review_ids: []`, `rebase_needed: <bool>`, `dispatched_rebase: false`, `checks_red: <count or 0>`, `dispatched_ci_fix: false`. Exit. The next tick fires from the arming loop ([`arm-watcher.md`](arm-watcher.md)) — or, under a recovery cron, in 1 min via `/loop`.
|
|
147
153
|
|
|
148
|
-
**Blocked pending a human** (a durable block, and `last_seen.blocked` not already set): enter the blocked path per [`blocked-tick.md`](blocked-tick.md) — flag `last_seen.blocked` and emit the one-line owner reminder
|
|
154
|
+
**Blocked pending a human** (a durable block, and `last_seen.blocked` not already set): enter the blocked path per [`blocked-tick.md`](blocked-tick.md) — flag `last_seen.blocked` and emit the one-line owner reminder, **once per block**. From the next tick on, the Step 2.5 gate carries the block silently. Exit.
|
|
149
155
|
|
|
150
156
|
## Output
|
|
151
157
|
|