@muggleai/works 5.5.1 → 5.7.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.
Files changed (44) hide show
  1. package/dist/plugin/.claude-plugin/plugin.json +1 -1
  2. package/dist/plugin/.cursor-plugin/plugin.json +1 -1
  3. package/dist/plugin/hooks/README.md +6 -3
  4. package/dist/plugin/hooks/hooks.json +34 -0
  5. package/dist/plugin/scripts/guardrail-offer-ran.sh +35 -0
  6. package/dist/plugin/scripts/guardrail-pr-terminal.sh +21 -0
  7. package/dist/plugin/scripts/guardrail-record-tests.sh +5 -4
  8. package/dist/plugin/scripts/guardrail-terminal-gate.sh +38 -0
  9. package/dist/plugin/scripts/guardrails.mjs +96 -3
  10. package/dist/plugin/skills/do/e2e-acceptance.md +2 -0
  11. package/dist/plugin/skills/do/respawn-watcher.md +4 -14
  12. package/dist/plugin/skills/muggle-pr-followup/CLAUDE.md +2 -1
  13. package/dist/plugin/skills/muggle-pr-followup/SKILL.md +3 -1
  14. package/dist/plugin/skills/muggle-pr-followup/arm-watcher.md +12 -0
  15. package/dist/plugin/skills/muggle-pr-followup/auto-track.md +5 -11
  16. package/dist/plugin/skills/muggle-pr-followup/blocked-tick.md +10 -10
  17. package/dist/plugin/skills/muggle-pr-followup/bootstrap.md +4 -8
  18. package/dist/plugin/skills/muggle-pr-followup/contract.md +5 -3
  19. package/dist/plugin/skills/muggle-pr-followup/evals/evals.json +12 -0
  20. package/dist/plugin/skills/muggle-pr-followup/output-templates/bootstrap.md +2 -2
  21. package/dist/plugin/skills/muggle-pr-followup/state-schemas.md +10 -0
  22. package/dist/release-manifest.json +4 -4
  23. package/package.json +1 -1
  24. package/plugin/.claude-plugin/plugin.json +1 -1
  25. package/plugin/.cursor-plugin/plugin.json +1 -1
  26. package/plugin/hooks/README.md +6 -3
  27. package/plugin/hooks/hooks.json +34 -0
  28. package/plugin/scripts/guardrail-offer-ran.sh +35 -0
  29. package/plugin/scripts/guardrail-pr-terminal.sh +21 -0
  30. package/plugin/scripts/guardrail-record-tests.sh +5 -4
  31. package/plugin/scripts/guardrail-terminal-gate.sh +38 -0
  32. package/plugin/scripts/guardrails.mjs +96 -3
  33. package/plugin/skills/do/e2e-acceptance.md +2 -0
  34. package/plugin/skills/do/respawn-watcher.md +4 -14
  35. package/plugin/skills/muggle-pr-followup/CLAUDE.md +2 -1
  36. package/plugin/skills/muggle-pr-followup/SKILL.md +3 -1
  37. package/plugin/skills/muggle-pr-followup/arm-watcher.md +12 -0
  38. package/plugin/skills/muggle-pr-followup/auto-track.md +5 -11
  39. package/plugin/skills/muggle-pr-followup/blocked-tick.md +10 -10
  40. package/plugin/skills/muggle-pr-followup/bootstrap.md +4 -8
  41. package/plugin/skills/muggle-pr-followup/contract.md +5 -3
  42. package/plugin/skills/muggle-pr-followup/evals/evals.json +12 -0
  43. package/plugin/skills/muggle-pr-followup/output-templates/bootstrap.md +2 -2
  44. package/plugin/skills/muggle-pr-followup/state-schemas.md +10 -0
@@ -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.5.1",
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.1",
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 releases to advisory 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.
23
+ Enforcement is reserved for the handoffs that were being skipped: the E2E acceptance run, posting a deterministically-rendered report, and the post-merge handoff. 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; the post-merge gate hard-releases after `MAX_PR_TERMINAL_BLOCKS` (3) blocks, and only the AskUserQuestion next-options offer clears it — nothing else resets its counter.
24
24
 
25
25
  ## Mechanism
26
26
 
@@ -31,9 +31,12 @@ 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, or an E2E run happened | — | set `unitTestsGreen` / `e2eRun` session state |
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
+ | `PostToolUse` (Bash + Monitor) | `guardrail-pr-terminal.sh` | advise | a PR just went terminal — a `gh pr merge`/`gh pr close` success line or the watch monitor's `TERMINAL pr=N` exit line (never bare `"state":"MERGED"` metadata) | — | record `terminalPending`, direct the post-merge handoff: finalize the watcher slot, tear down per `autoCleanup`, offer next options via AskUserQuestion |
36
+ | `PostToolUse` (AskUserQuestion) | `guardrail-offer-ran.sh` | record | a next-options offer ran while a terminal PR was pending | — | clear `terminalPending` — the only exit for the post-merge Stop gate |
35
37
  | `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 and no E2E ran yet | `autoE2ETest` | **block** the turn until E2E runs via `muggle-test` (releases after 3 blocks) |
38
+ | `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) |
39
+ | `Stop` | `guardrail-terminal-gate.sh` | **enforce** | a PR went terminal this session and the AskUserQuestion next-options offer hasn't run since | — | **block** the turn until the post-merge handoff runs (full message once, one-line reminders after; releases after 3 blocks; nothing but the offer resets the counter) |
37
40
  | `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
41
 
39
42
  ## Session-start reconcile nudge
@@ -47,6 +47,12 @@
47
47
  "command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-record-tests.sh\"",
48
48
  "async": false,
49
49
  "timeout": 10
50
+ },
51
+ {
52
+ "type": "command",
53
+ "command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-pr-terminal.sh\"",
54
+ "async": false,
55
+ "timeout": 10
50
56
  }
51
57
  ]
52
58
  },
@@ -60,6 +66,28 @@
60
66
  "timeout": 10
61
67
  }
62
68
  ]
69
+ },
70
+ {
71
+ "matcher": "Monitor",
72
+ "hooks": [
73
+ {
74
+ "type": "command",
75
+ "command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-pr-terminal.sh\"",
76
+ "async": false,
77
+ "timeout": 10
78
+ }
79
+ ]
80
+ },
81
+ {
82
+ "matcher": "AskUserQuestion",
83
+ "hooks": [
84
+ {
85
+ "type": "command",
86
+ "command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-offer-ran.sh\"",
87
+ "async": false,
88
+ "timeout": 10
89
+ }
90
+ ]
63
91
  }
64
92
  ],
65
93
  "Stop": [
@@ -70,6 +98,12 @@
70
98
  "command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-e2e-gate.sh\"",
71
99
  "async": false,
72
100
  "timeout": 10
101
+ },
102
+ {
103
+ "type": "command",
104
+ "command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-terminal-gate.sh\"",
105
+ "async": false,
106
+ "timeout": 10
73
107
  }
74
108
  ]
75
109
  }
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env bash
2
+ set -uo pipefail
3
+
4
+ # Next-options-offer observer (PostToolUse/AskUserQuestion). An AskUserQuestion
5
+ # call while a terminal PR is pending IS the post-merge handoff's exit: it
6
+ # clears terminalPending so the Stop gate (guardrail-terminal-gate.sh)
7
+ # releases. Emits no directive.
8
+ #
9
+ # Pre-filter: only spawn Node when the per-session state actually has a
10
+ # pending terminal PR, so the ordinary AskUserQuestion (no PR merged this
11
+ # session) never pays Node cold-start. Degrades to {}.
12
+ payload="$(cat)"
13
+
14
+ raw_sid="$(printf '%s' "$payload" | grep -oE '"session_id"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 | sed -E 's/.*:[[:space:]]*"([^"]*)".*/\1/')"
15
+ [ -n "$raw_sid" ] || raw_sid="unknown"
16
+ sid="$(printf '%s' "$raw_sid" | sed 's/[^A-Za-z0-9_-]/_/g')"
17
+
18
+ # Resolve the same home dir Node's os.homedir() uses. HOME is correct on
19
+ # macOS/Linux and on most Git Bash setups; fall back to converting USERPROFILE
20
+ # when HOME doesn't hold the state dir (some Windows shells point HOME elsewhere).
21
+ home="${HOME:-}"
22
+ if [ ! -d "$home/.muggle-ai" ] && command -v cygpath >/dev/null 2>&1 && [ -n "${USERPROFILE:-}" ]; then
23
+ home="$(cygpath -u "$USERPROFILE" 2>/dev/null || printf '%s' "$home")"
24
+ fi
25
+
26
+ state_file="$home/.muggle-ai/guardrails/$sid.json"
27
+ if [ ! -f "$state_file" ] \
28
+ || ! grep -q '"terminalPending"' "$state_file" \
29
+ || grep -q '"terminalPending": \[\]' "$state_file"; then
30
+ printf '{}'
31
+ exit 0
32
+ fi
33
+
34
+ root="${CLAUDE_PLUGIN_ROOT:-${CURSOR_PLUGIN_ROOT:-}}"
35
+ printf '%s' "$payload" | node "${root}/scripts/guardrails.mjs" offer-ran 2>/dev/null || printf '{}'
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env bash
2
+ set -uo pipefail
3
+
4
+ # PR-terminal guardrail (PostToolUse/Bash + Monitor). When a PR just went
5
+ # terminal — a `gh pr merge`/`gh pr close` success line or the pr-followup
6
+ # watch monitor's `TERMINAL pr=N` exit line — arm the post-merge handoff:
7
+ # record the PR as pending, nudge the model to finalize/tear down and offer
8
+ # next options, and hold the Stop gate (guardrail-terminal-gate.sh) until the
9
+ # AskUserQuestion offer runs. Decision logic lives in the bundled guardrails.mjs.
10
+ #
11
+ # Fires after every Bash call, so a keyword pre-filter for the terminal output
12
+ # shapes keeps Node off the hot path. Degrades to {} so it never blocks.
13
+ payload="$(cat)"
14
+
15
+ if ! grep -Eiq 'merged pull request|closed pull request|TERMINAL pr=' <<<"$payload"; then
16
+ printf '{}'
17
+ exit 0
18
+ fi
19
+
20
+ root="${CLAUDE_PLUGIN_ROOT:-${CURSOR_PLUGIN_ROOT:-}}"
21
+ printf '%s' "$payload" | node "${root}/scripts/guardrails.mjs" pr-terminal 2>/dev/null || printf '{}'
@@ -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) or
12
- # a muggle execute/replay/test-generation event reaches guardrails.mjs, which
13
- # then inspects the output for pass/fail and updates state. Degrades to {}.
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
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env bash
2
+ set -uo pipefail
3
+
4
+ # PR-terminal → post-merge handoff gate (Stop). When a PR went terminal this
5
+ # session (merged/closed) and the next-options offer hasn't run, block the
6
+ # turn end until the handoff — finalize, teardown, AskUserQuestion offer —
7
+ # happens. Releases unconditionally after 3 blocks.
8
+ #
9
+ # This must stay synchronous (only a sync Stop hook can block the turn end),
10
+ # and it fires on EVERY turn end. There is no command payload to key off, so
11
+ # the pre-filter reads the same per-session state file guardrails.mjs uses and
12
+ # only spawns Node when a terminal PR is actually pending. On the overwhelming
13
+ # majority of turns no PR went terminal, so the state file is absent or
14
+ # terminalPending is empty and we return {} in-shell. Degrades to {}.
15
+ payload="$(cat)"
16
+
17
+ raw_sid="$(printf '%s' "$payload" | grep -oE '"session_id"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 | sed -E 's/.*:[[:space:]]*"([^"]*)".*/\1/')"
18
+ [ -n "$raw_sid" ] || raw_sid="unknown"
19
+ sid="$(printf '%s' "$raw_sid" | sed 's/[^A-Za-z0-9_-]/_/g')"
20
+
21
+ # Resolve the same home dir Node's os.homedir() uses. HOME is correct on
22
+ # macOS/Linux and on most Git Bash setups; fall back to converting USERPROFILE
23
+ # when HOME doesn't hold the state dir (some Windows shells point HOME elsewhere).
24
+ home="${HOME:-}"
25
+ if [ ! -d "$home/.muggle-ai" ] && command -v cygpath >/dev/null 2>&1 && [ -n "${USERPROFILE:-}" ]; then
26
+ home="$(cygpath -u "$USERPROFILE" 2>/dev/null || printf '%s' "$home")"
27
+ fi
28
+
29
+ state_file="$home/.muggle-ai/guardrails/$sid.json"
30
+ if [ ! -f "$state_file" ] \
31
+ || ! grep -q '"terminalPending"' "$state_file" \
32
+ || grep -q '"terminalPending": \[\]' "$state_file"; then
33
+ printf '{}'
34
+ exit 0
35
+ fi
36
+
37
+ root="${CLAUDE_PLUGIN_ROOT:-${CURSOR_PLUGIN_ROOT:-}}"
38
+ printf '%s' "$payload" | node "${root}/scripts/guardrails.mjs" terminal-gate 2>/dev/null || printf '{}'
@@ -40,13 +40,72 @@ ${input2.tool_response?.output ?? ""}`;
40
40
  return m ? m[0] : null;
41
41
  }
42
42
 
43
+ // src/guardrails/constants.ts
44
+ var GH_PR_MERGED_LINE = /\b(?:Merged|Squashed and merged|Rebased and merged) pull request [\w./-]*#(\d+)/;
45
+ var GH_PR_CLOSED_LINE = /\bClosed pull request [\w./-]*#(\d+)/;
46
+ var PR_MONITOR_TERMINAL_LINE = /\bTERMINAL pr=(\d+): (MERGED|CLOSED)\b/;
47
+ var MAX_PR_TERMINAL_BLOCKS = 3;
48
+
49
+ // src/guardrails/prTerminal.ts
50
+ function detectPrTerminal(input2) {
51
+ if (input2.tool_name !== "Bash" && input2.tool_name !== "Monitor") return null;
52
+ const response = input2.tool_response;
53
+ const haystack = [response?.stdout, response?.stderr, response?.output, response?.content].filter((part) => typeof part === "string").join("\n");
54
+ const mergedMatch = haystack.match(GH_PR_MERGED_LINE);
55
+ if (mergedMatch) {
56
+ return { prNumber: Number(mergedMatch[1]), verdict: "merged" /* Merged */ };
57
+ }
58
+ const closedMatch = haystack.match(GH_PR_CLOSED_LINE);
59
+ if (closedMatch) {
60
+ return { prNumber: Number(closedMatch[1]), verdict: "closed" /* Closed */ };
61
+ }
62
+ const monitorMatch = haystack.match(PR_MONITOR_TERMINAL_LINE);
63
+ if (monitorMatch) {
64
+ return {
65
+ prNumber: Number(monitorMatch[1]),
66
+ verdict: monitorMatch[2] === "MERGED" ? "merged" /* Merged */ : "closed" /* Closed */
67
+ };
68
+ }
69
+ return null;
70
+ }
71
+ function applyPrTerminalDetected(state, prNumber) {
72
+ const pending = state.terminalPending ?? [];
73
+ const handled = state.terminalHandled ?? [];
74
+ if (pending.includes(prNumber) || handled.includes(prNumber)) return state;
75
+ return { ...state, terminalPending: [...pending, prNumber] };
76
+ }
77
+ function applyNextOptionsOffered(state) {
78
+ const pending = state.terminalPending ?? [];
79
+ if (pending.length === 0) return state;
80
+ return {
81
+ ...state,
82
+ terminalPending: [],
83
+ terminalHandled: [...state.terminalHandled ?? [], ...pending],
84
+ terminalBlockCount: 0
85
+ };
86
+ }
87
+ function prTerminalGateDecision(state, maxBlocks = MAX_PR_TERMINAL_BLOCKS) {
88
+ const blockCount = state.terminalBlockCount ?? 0;
89
+ if ((state.terminalPending ?? []).length === 0) {
90
+ return { action: "none" /* None */, blockCount };
91
+ }
92
+ if (blockCount >= maxBlocks) {
93
+ return { action: "release" /* Release */, blockCount };
94
+ }
95
+ return { action: "block" /* Block */, blockCount: blockCount + 1 };
96
+ }
97
+
43
98
  // src/guardrails/testsGreen.ts
44
99
  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
100
  var FAIL = /\b\d+\s+failed\b|\bFAIL\b|✗/;
46
101
  var E2E_TOOL = /muggle.*(execute|test-generation|replay)/i;
102
+ var E2E_SKIP_MARKER = /^\s*echo\s+["']?MUGGLE_E2E_SKIP\b/;
47
103
  function isTestCommand(cmd) {
48
104
  return TEST_CMD.test(cmd);
49
105
  }
106
+ function isE2ESkipMarker(cmd) {
107
+ return E2E_SKIP_MARKER.test(cmd);
108
+ }
50
109
  function testsPassed(input2) {
51
110
  const out = `${input2.tool_response?.stdout ?? ""}
52
111
  ${input2.tool_response?.stderr ?? ""}`;
@@ -60,7 +119,7 @@ function isE2ERun(input2) {
60
119
  // src/guardrails/shouldRunE2E.ts
61
120
  var MAX_E2E_BLOCKS = 3;
62
121
  function shouldRunE2E(state) {
63
- return state.unitTestsGreen === true && state.e2eRun !== true;
122
+ return state.unitTestsGreen === true && state.e2eRun !== true && state.e2eSkipped !== true;
64
123
  }
65
124
  function applyRecordedRun(state, run) {
66
125
  let next = state;
@@ -70,6 +129,9 @@ function applyRecordedRun(state, run) {
70
129
  if (run.e2eRan) {
71
130
  next = { ...next, e2eRun: true };
72
131
  }
132
+ if (run.e2eSkipped) {
133
+ next = { ...next, e2eSkipped: true };
134
+ }
73
135
  return next;
74
136
  }
75
137
  function e2eGateDecision(state, maxBlocks = MAX_E2E_BLOCKS) {
@@ -190,12 +252,40 @@ function prOpened() {
190
252
  Per the autoWatchPR preference, a muggle-pr-followup watcher should handle its incoming reviews. If autoWatchPR=always, start it now by invoking /muggle:muggle-pr-followup with the PR URL; if =ask, offer it to the user; if =never, do nothing.`;
191
253
  return envelope("PostToolUse", ctx, host);
192
254
  }
255
+ function prTerminal() {
256
+ const terminalEvent = detectPrTerminal(input);
257
+ if (!terminalEvent) return "{}";
258
+ const state = readState(sessionId);
259
+ const next = applyPrTerminalDetected(state, terminalEvent.prNumber);
260
+ if (next === state) return "{}";
261
+ writeState(next);
262
+ const ctx = `PR #${terminalEvent.prNumber} went terminal (${terminalEvent.verdict}). Run the post-merge handoff now: finalize the watcher slot, tear down per autoCleanup, then OFFER NEXT OPTIONS to the user (AskUserQuestion) \u2014 release, queued work, deferred items. The stop gate holds until the offer runs.`;
263
+ return envelope("PostToolUse", ctx, host);
264
+ }
265
+ function offerRan() {
266
+ if (input.tool_name !== "AskUserQuestion") return "{}";
267
+ const state = readState(sessionId);
268
+ const next = applyNextOptionsOffered(state);
269
+ if (next !== state) writeState(next);
270
+ return "{}";
271
+ }
272
+ function terminalGate() {
273
+ const state = readState(sessionId);
274
+ const decision = prTerminalGateDecision(state);
275
+ if (decision.action !== "block" /* Block */) return "{}";
276
+ state.terminalBlockCount = decision.blockCount;
277
+ writeState(state);
278
+ const pendingPrList = (state.terminalPending ?? []).map((prNumber) => `#${prNumber}`).join(", ");
279
+ const reason = decision.blockCount === 1 ? `Do not end the turn yet. PR ${pendingPrList} went terminal (merged/closed) but the post-merge handoff has not run. Finalize the watcher slot, tear down per autoCleanup, then offer next options to the user via AskUserQuestion \u2014 release, queued work, deferred items. Only the AskUserQuestion offer clears this gate.` : `Post-merge handoff still owed for PR ${pendingPrList} (reminder ${decision.blockCount}/${MAX_PR_TERMINAL_BLOCKS}): finalize + tear down, then run the AskUserQuestion next-options offer.`;
280
+ return blockStop(reason, host);
281
+ }
193
282
  function recordTests() {
194
283
  const cmd = input.tool_input?.command ?? "";
195
284
  const state = readState(sessionId);
196
285
  const next = applyRecordedRun(state, {
197
286
  unitTestPassed: isTestCommand(cmd) && testsPassed(input),
198
- e2eRan: isE2ERun(input)
287
+ e2eRan: isE2ERun(input),
288
+ e2eSkipped: isE2ESkipMarker(cmd)
199
289
  });
200
290
  if (next !== state) writeState(next);
201
291
  return "{}";
@@ -206,7 +296,7 @@ function e2eGate() {
206
296
  if (decision.action === "none" /* None */ || decision.action === "release" /* Release */) return "{}";
207
297
  state.e2eBlockCount = decision.blockCount;
208
298
  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), say so explicitly to the user \u2014 this gate releases after ${MAX_E2E_BLOCKS} attempts.`;
299
+ 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
300
  return blockStop(reason, host);
211
301
  }
212
302
  function reportGate() {
@@ -225,8 +315,11 @@ function buildRouter() {
225
315
  }
226
316
  var handlers = {
227
317
  "pr-opened": prOpened,
318
+ "pr-terminal": prTerminal,
319
+ "offer-ran": offerRan,
228
320
  "record-tests": recordTests,
229
321
  "e2e-gate": e2eGate,
322
+ "terminal-gate": terminalGate,
230
323
  "report-gate": reportGate,
231
324
  "build-router": buildRouter
232
325
  };
@@ -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:
@@ -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. The watcher cancels its own cron the moment it dispatches a cycle ([`../muggle-pr-followup/contract.md`](../muggle-pr-followup/contract.md) Steps 4 / 5 / 5b), so for the duration of the cycle **no cron is armed for this slot**. Respawning is what arms the next one. This is a runtime dispatch of the watcher's slash command, not a doc dependency on it — allowed per the one-way rule in [`../CLAUDE.md`](../CLAUDE.md).
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. Since the dispatch already cancelled the cron, any open-PR exit that skips respawn leaves the slot with no cron and no next tick: the poller stops silently and stays stopped 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.
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
- Run as the final action of the turn:
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
- Exactly one cron results — the dispatch already cancelled the prior one, so this is never a duplicate. The next tick self-records the new cron id ([`../muggle-pr-followup/record-cron-id.md`](../muggle-pr-followup/record-cron-id.md)).
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,7 +6,8 @@ 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 dispatches the first watcher).
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`.
@@ -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
- **Active reminders 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 watcher keeps its `1m` poll and turns each blocked tick into a **one-line reminder**: the pending act plus a reference back to the decision context, nudging the owner every poll until they act ([`contract.md`](contract.md) Steps 2.5, 7). The block reminds but never stops or slows: each tick stays cheap (a fingerprint check, one line out), and the block clears the instant a push, review, or CI/deploy state moves.
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
 
@@ -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
- Dispatching:
71
- /loop 1m /muggle:muggle-pr-followup <slug> <n>
70
+ Arming:
71
+ <owner>/<repo>#<n>
72
72
  ...
73
73
  ```
74
74
 
75
- Print the summary **before** the `/loop` dispatches so it stays visible.
75
+ Print the summary **before** arming the watchers so it stays visible.
76
76
 
77
- ### Step 6 — Dispatch the watchers
77
+ ### Step 6 — Arm the watchers
78
78
 
79
- As the last action of the turn, emit one `/loop` line per **newly tracked** PR (not the skipped ones):
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 (remind-or-resume). None of this runs on a normal tick: when `last_seen.blocked` is absent, the watcher skips straight through.
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 — remind at the normal `1m` cadence, never stop.** The poll stays at `1m` whether or not the PR is blocked — a `1m` tick is cheap (one fingerprint check, one line out) and keeps the owner nudged and an external unblock caught within a minute. The `blocked` state changes no cadence; its only job is (a) the reason-specific one-line reminder each tick and (b) fingerprint-based auto-resume. No cadence swap, no separate `reminded` flag — while `blocked` is set, the watcher reminds every tick by definition.
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. The `1m` cron is unchanged — no swap.
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. Re-emit the one-line reminder per [`output-templates/blocked-reminder.md`](output-templates/blocked-reminder.md). 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. The `1m` cron is unchanged.
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. The cron is already `1m`, so no swap is needed: if Step 3–6 dispatches, that cancels the `1m` cron and `/muggle-do` respawns `1m` (normal single-thread); if it idles transient, the `1m` cron is already correct; if it idles back into the block, Step 7 re-flags.
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
- - Cadence is `1m` whether blocked or active — the block never changes the poll interval. There is no cadence swap, so a blocked slot is never left cron-less by one.
36
- - The poll never stops — a blocked tick keeps firing and reminding; only a terminal PR or an explicit teardown removes the cron.
37
- - Every blocked tick emits exactly one owner reminder (implied by `blocked: true`, no separate flag) and no PR-side post.
38
- - The block clears the instant any fingerprint component moves; an external unblock is caught within one `1m` tick.
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` (Step 8 dispatches `/loop` as the last action, so the id isn't observable yet — the first tick self-records it per [`record-cron-id.md`](record-cron-id.md)), `command: "/muggle:muggle-pr-followup <slug> <n>"`, `interval: "1m"`, `recorded_at: <now>`.
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 — Dispatch the first watcher
84
+ ### Step 8 — Arm the watch
85
85
 
86
- The last action of this turn:
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 `/loop` dispatch so it's visible.
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,6 +33,8 @@ 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
@@ -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 remind-or-resume gate per [`blocked-tick.md`](blocked-tick.md): recompute the fingerprint, re-emit the one-line owner reminder and stay blocked while it holds, or clear the block and fall through to Step 3 the moment it moves. While blocked the watcher keeps the normal `1m` cadence and reminds the owner each tick — the block reminds rather than backs off, and never changes the poll interval.
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
 
@@ -147,9 +149,9 @@ Any idle branch (Steps 4–6 that did not dispatch). First classify **why** this
147
149
 
148
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.
149
151
 
150
- **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`.
151
153
 
152
- **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 (the watcher reminds each tick at the normal `1m` cadence rather than backing off). From the next tick on, the Step 2.5 gate carries the block. Exit.
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.
153
155
 
154
156
  ## Output
155
157