@muggleai/works 5.26.0-staging.207 → 5.26.0-staging.208

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 (52) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/cli.js +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/plugin/.claude-plugin/plugin.json +1 -1
  5. package/dist/plugin/.codex-mcp.json +1 -1
  6. package/dist/plugin/.codex-plugin/plugin.json +1 -1
  7. package/dist/plugin/.cursor-plugin/plugin.json +1 -1
  8. package/dist/plugin/.mcp.json +1 -1
  9. package/dist/plugin/hooks/README.md +2 -1
  10. package/dist/plugin/hooks/codex-hooks.json +2 -2
  11. package/dist/plugin/hooks/hooks.json +1 -1
  12. package/dist/plugin/scripts/guardrail-watch-follow-through-gate.sh +48 -0
  13. package/dist/plugin/scripts/guardrails.mjs +282 -32
  14. package/dist/plugin/scripts/pr-watch-arm.sh +64 -37
  15. package/dist/plugin/scripts/pr-watch-due.sh +31 -0
  16. package/dist/plugin/scripts/pr-watch-events.sh +20 -6
  17. package/dist/plugin/scripts/pr-watch-loop.sh +21 -2
  18. package/dist/plugin/scripts/pr-watch-verdict.mjs +197 -0
  19. package/dist/plugin/skills/_shared/ci-check-to-command.md +2 -1
  20. package/dist/plugin/skills/do/fix-ci.md +24 -8
  21. package/dist/plugin/skills/do/resolve-conflicts.md +7 -3
  22. package/dist/plugin/skills/muggle-pr-followup/SKILL.md +1 -1
  23. package/dist/plugin/skills/muggle-pr-followup/arm-watcher.md +5 -3
  24. package/dist/plugin/skills/muggle-pr-followup/blocked-tick.md +2 -0
  25. package/dist/plugin/skills/muggle-pr-followup/contract.md +40 -25
  26. package/dist/plugin/skills/muggle-pr-followup/state-schemas.md +22 -8
  27. package/dist/release-manifest.json +3 -3
  28. package/package.json +1 -1
  29. package/plugin/.claude-plugin/plugin.json +1 -1
  30. package/plugin/.codex-mcp.json +1 -1
  31. package/plugin/.codex-plugin/plugin.json +1 -1
  32. package/plugin/.cursor-plugin/plugin.json +1 -1
  33. package/plugin/.mcp.json +1 -1
  34. package/plugin/hooks/README.md +2 -1
  35. package/plugin/hooks/codex-hooks.json +2 -2
  36. package/plugin/hooks/hooks.json +1 -1
  37. package/plugin/scripts/guardrail-watch-follow-through-gate.sh +48 -0
  38. package/plugin/scripts/guardrails.mjs +282 -32
  39. package/plugin/scripts/pr-watch-arm.sh +64 -37
  40. package/plugin/scripts/pr-watch-due.sh +31 -0
  41. package/plugin/scripts/pr-watch-events.sh +20 -6
  42. package/plugin/scripts/pr-watch-loop.sh +21 -2
  43. package/plugin/scripts/pr-watch-verdict.mjs +197 -0
  44. package/plugin/skills/_shared/ci-check-to-command.md +2 -1
  45. package/plugin/skills/do/fix-ci.md +24 -8
  46. package/plugin/skills/do/resolve-conflicts.md +7 -3
  47. package/plugin/skills/muggle-pr-followup/SKILL.md +1 -1
  48. package/plugin/skills/muggle-pr-followup/arm-watcher.md +5 -3
  49. package/plugin/skills/muggle-pr-followup/blocked-tick.md +2 -0
  50. package/plugin/skills/muggle-pr-followup/contract.md +40 -25
  51. package/plugin/skills/muggle-pr-followup/state-schemas.md +22 -8
  52. /package/dist/{chunk-HGN35NEP.js → chunk-HOKMW4AL.js} +0 -0
@@ -11,6 +11,11 @@
11
11
  # The floors are taken from the drain's own read rather than from a fresh fetch
12
12
  # afterwards: anything that lands between the two would otherwise be marked seen
13
13
  # without ever being reported.
14
+ #
15
+ # A stale branch or a red head is floored only when the slot proves a cycle ran
16
+ # for it. Flooring whatever was outstanding at arm time let a session that never
17
+ # rebased or fixed anything re-arm at every rollover and silence the loop each
18
+ # time; the drain line said "handled" and nothing checked.
14
19
  set -uo pipefail
15
20
 
16
21
  script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -33,7 +38,7 @@ if [ -z "$slot" ] || [ -z "$repo" ] || [ -z "$pr_number" ] || [ -z "$base_branch
33
38
  exit 2
34
39
  fi
35
40
 
36
- for lib in pr-watch-guards.sh pr-watch-events.sh pr-watch-fetch.sh; do
41
+ for lib in pr-watch-guards.sh pr-watch-events.sh pr-watch-fetch.sh pr-watch-due.sh; do
37
42
  if [ ! -f "${script_dir}/${lib}" ]; then
38
43
  echo "pr-watch-arm: missing ${lib} beside this script" >&2
39
44
  exit 2
@@ -42,10 +47,12 @@ for lib in pr-watch-guards.sh pr-watch-events.sh pr-watch-fetch.sh; do
42
47
  . "${script_dir}/${lib}"
43
48
  done
44
49
 
45
- if [ ! -f "${script_dir}/pr-watch-state.jq" ]; then
46
- echo "pr-watch-arm: missing pr-watch-state.jq beside this script" >&2
47
- exit 2
48
- fi
50
+ for companion in pr-watch-state.jq pr-watch-verdict.mjs; do
51
+ if [ ! -f "${script_dir}/${companion}" ]; then
52
+ echo "pr-watch-arm: missing ${companion} beside this script" >&2
53
+ exit 2
54
+ fi
55
+ done
49
56
  state_projection="$(cat "${script_dir}/pr-watch-state.jq")"
50
57
 
51
58
  mkdir -p "$slot"
@@ -75,50 +82,68 @@ if [ "$pr_state" = "MERGED" ] || [ "$pr_state" = "CLOSED" ]; then
75
82
  exit 0
76
83
  fi
77
84
 
78
- # A red head at arm time is the drain's to hand over, so it goes into the floor
79
- # and does not re-fire on the loop's first pass. Pending checks are not red yet.
80
- ci_red_floor=""
81
- if [ "${pending_checks:-0}" -eq 0 ] 2>/dev/null && [ "${failed_checks:-0}" -gt 0 ] 2>/dev/null; then
82
- ci_red_floor="$head_sha"
83
- fi
85
+ ci_red_head=""
86
+ watch_checks_settled_red "$pending_checks" "$failed_checks" && ci_red_head="$head_sha"
84
87
 
85
- # Same for staleness: keyed on the head/base-tip pair, so it re-arms when either moves.
86
- rebase_floor=""
88
+ # Keyed on the head/base-tip pair, so it re-arms when either moves.
89
+ rebase_key="${head_sha}..${base_tip_sha}"
90
+ rebase_due_key=""
87
91
  behind_count="$(watch_fetch_behind_count "$repo" "$base_branch" "$head_sha" "$slot")"
88
- if [ "$mergeable" = "CONFLICTING" ] || { [ -n "$behind_count" ] && [ "$behind_count" -gt 0 ] 2>/dev/null; }; then
89
- rebase_floor="${head_sha}..${base_tip_sha}"
90
- fi
92
+ watch_branch_needs_rebase "$mergeable" "$behind_count" && rebase_due_key="$rebase_key"
91
93
 
92
- # A slot re-armed while blocked keeps its resume probe live. Empty is the
93
- # not-blocked state, so seeding it empty here would leave the loop asleep
94
- # through the very CI move the block is waiting on.
94
+ # Whether a cycle already ran for this key and this head, and the blocked
95
+ # fingerprint's digest. A slot re-armed while blocked keeps its resume probe
96
+ # live: empty is the not-blocked state, so seeding it empty would leave the loop
97
+ # asleep through the very CI move the block is waiting on.
95
98
  #
96
- # node rather than sed or jq: the digest sits under a per-PR key, jq is not
97
- # guaranteed present, and a malformed file must read as not blocked rather than
98
- # yield a partial match. The file goes in on stdin because Windows node cannot
99
- # open the POSIX path Git Bash hands it. A digest spanning lines is dropped:
100
- # written into the line-based watermark, it could forge another floor.
99
+ # The verdict script rather than sed or jq: the fields sit under a per-PR key,
100
+ # jq is not guaranteed present, and a malformed file must read as nothing
101
+ # recorded rather than yield a partial match. The file goes in on stdin because
102
+ # Windows node cannot open the POSIX path Git Bash hands it. Any failure leaves
103
+ # every floor empty, which wakes the loop rather than silencing it.
104
+ last_seen_file="${slot}/last_seen.json"
105
+ [ -f "$last_seen_file" ] || last_seen_file=/dev/null
106
+ rebase_attempted=0
107
+ ci_attempted=0
101
108
  blocked_digest_floor=""
102
- if [ -f "${slot}/last_seen.json" ]; then
103
- blocked_digest_floor="$(PR_KEY="${repo}#${pr_number}" node -e '
104
- try {
105
- const digest = JSON.parse(require("fs").readFileSync(0, "utf8"))[process.env.PR_KEY]?.blocked?.fingerprint?.ci_digest;
106
- if (typeof digest === "string" && !/[\r\n]/.test(digest)) process.stdout.write(digest);
107
- } catch {}
108
- ' < "${slot}/last_seen.json" 2>/dev/null)"
109
- fi
109
+ while IFS= read -r evidence_line; do
110
+ evidence_line="${evidence_line%$'\r'}"
111
+ case "$evidence_line" in
112
+ REBASE_ATTEMPTED=*) rebase_attempted="${evidence_line#REBASE_ATTEMPTED=}" ;;
113
+ CI_ATTEMPTED=*) ci_attempted="${evidence_line#CI_ATTEMPTED=}" ;;
114
+ BLOCKED_CIDIGEST=*) blocked_digest_floor="${evidence_line#BLOCKED_CIDIGEST=}" ;;
115
+ esac
116
+ done < <(node "${script_dir}/pr-watch-verdict.mjs" arm-floors --pr-key "${repo}#${pr_number}" \
117
+ --head "$head_sha" --rebase-key "$rebase_key" < "$last_seen_file" 2>/dev/null)
118
+
119
+ ci_red_floor=""
120
+ [ -n "$ci_red_head" ] && [ "$ci_attempted" = "1" ] && ci_red_floor="$ci_red_head"
121
+ rebase_floor=""
122
+ [ -n "$rebase_due_key" ] && [ "$rebase_attempted" = "1" ] && rebase_floor="$rebase_due_key"
110
123
 
111
124
  thread_count=0
112
125
  [ -n "$unresolved_threads" ] && thread_count=$(printf '%s' "$unresolved_threads" | tr ';' '\n' | grep -c .)
113
126
 
114
- # Printed, not swallowed: these are the things the arming session owes a decision
115
- # on before the monitor takes over, and the monitor only ever sees what arrives
116
- # after this point.
127
+ # Printed, not swallowed: these are the things the arming session owes action on
128
+ # before the monitor takes over. Unattempted work is left unfloored, so the
129
+ # loop's first pass reports it again as an event.
117
130
  echo "DRAIN pr=$pr_number state=$pr_state head=${head_sha:0:8}"
118
131
  echo "DRAIN unresolved-threads=$thread_count latest-review=${latest_review:-0} latest-comment=${latest_comment:-0}"
119
132
  echo "DRAIN checks pending=${pending_checks:-0} failed=${failed_checks:-0} behind-base=${behind_count:-unknown} mergeable=${mergeable:-UNKNOWN}"
120
- [ -n "$ci_red_floor" ] && echo "DRAIN ci already red at arm time — handled by the arming session, floored"
121
- [ -n "$rebase_floor" ] && echo "DRAIN branch already stale at arm time — handled by the arming session, floored"
133
+ if [ -n "$ci_red_head" ]; then
134
+ if [ -n "$ci_red_floor" ]; then
135
+ echo "DRAIN ci red at arm time — a fix-ci cycle already ran for head ${head_sha:0:8}, floored"
136
+ else
137
+ echo "DRAIN ci red at arm time — no fix-ci attempt recorded for head ${head_sha:0:8}, not floored: dispatch fix-ci"
138
+ fi
139
+ fi
140
+ if [ -n "$rebase_due_key" ]; then
141
+ if [ -n "$rebase_floor" ]; then
142
+ echo "DRAIN branch stale at arm time — a rebase already ran for key ${rebase_due_key}, floored"
143
+ else
144
+ echo "DRAIN branch stale at arm time — no rebase attempt recorded for key ${rebase_due_key}, not floored: dispatch rebase"
145
+ fi
146
+ fi
122
147
 
123
148
  {
124
149
  printf 'REV=%s\n' "${latest_review:-0}"
@@ -129,6 +154,8 @@ echo "DRAIN checks pending=${pending_checks:-0} failed=${failed_checks:-0} behin
129
154
  printf 'BLOCKED_CIDIGEST="%s"\n' "$blocked_digest_floor"
130
155
  } > "${slot}/watch-watermark.env"
131
156
 
157
+ watch_record_due_work "$slot" "$head_sha" "$rebase_due_key" "$ci_red_head"
158
+
132
159
  # Claim the slot for this session. watcher_lease_is_foreign reads an absent
133
160
  # owner.json as "not foreign", so a slot armed without one leases itself to a
134
161
  # live PID nothing can classify: once the arming session dies its watcher polls
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Records the work a watch has seen due on its PR — a rebase or red CI — so the
4
+ # owning session's turn-end gate can tell an event it acted on from one it sat
5
+ # on. Sourced by pr-watch-arm.sh and pr-watch-loop.sh.
6
+ #
7
+ # The gate runs in a Stop hook with about a second to answer and no network, so
8
+ # it cannot ask the provider what is due; it reads this file and the slot's
9
+ # attempt counters instead. A session once held a stale branch and a red head
10
+ # for a day by re-arming its watch, whose drain floored both as "handled", and
11
+ # answering every wake with a question. Nothing on disk said the work was due,
12
+ # so nothing could notice. This file is that record.
13
+ #
14
+ # Rewritten whole each time what is due changes; left empty when nothing is, so
15
+ # the gate's shell pre-filter reads an empty file as nothing owed.
16
+
17
+ MUGGLE_PR_WATCH_DUE_FILE="watch-due.env"
18
+
19
+ # Writes <slot>/watch-due.env: the head the observation was made on, the
20
+ # `<head>..<base-tip>` key of a rebase found due (empty when the branch is
21
+ # current), and the head whose checks settled red (empty otherwise). Builtins
22
+ # only, since the loop writes it every time what is due changes.
23
+ watch_record_due_work() {
24
+ local slot="$1" head_sha="$2" rebase_due_key="$3" ci_red_head="$4"
25
+ if [ -z "$rebase_due_key" ] && [ -z "$ci_red_head" ]; then
26
+ : > "${slot}/${MUGGLE_PR_WATCH_DUE_FILE}"
27
+ return 0
28
+ fi
29
+ printf 'HEAD="%s"\nREBASE_DUE="%s"\nCI_RED_HEAD="%s"\n' "$head_sha" "$rebase_due_key" "$ci_red_head" \
30
+ > "${slot}/${MUGGLE_PR_WATCH_DUE_FILE}"
31
+ }
@@ -71,9 +71,16 @@ watch_wake_thread() {
71
71
  echo "EVENT pr=$pr thread newly unresolved id=$thread_id"
72
72
  }
73
73
 
74
- # The head's checks having **settled** red: nothing still pending and at least
75
- # one failure. Pending-with-a-failure is not a wake — a run in flight may still
76
- # go green, and the tick would idle on it anyway.
74
+ # True when the head's checks have **settled** red: nothing still pending and at
75
+ # least one failure. Pending-with-a-failure is not red yet — a run in flight may
76
+ # still go green, and the tick would idle on it anyway.
77
+ watch_checks_settled_red() {
78
+ local pending_count="$1" failed_count="$2"
79
+ [ "${pending_count:-0}" -eq 0 ] 2>/dev/null || return 1
80
+ [ "${failed_count:-0}" -gt 0 ] 2>/dev/null
81
+ }
82
+
83
+ # The head's checks having settled red (watch_checks_settled_red).
77
84
  #
78
85
  # The floor is the head SHA rather than a monotonic id because a check rollup is
79
86
  # not monotonic: it flips green to red and resets on every push. Keying on the
@@ -82,11 +89,18 @@ watch_wake_ci_red() {
82
89
  local pr="$1" pending_count="$2" failed_count="$3" head_sha="$4" floor="$5"
83
90
  [ -n "$head_sha" ] || return 1
84
91
  [ "$head_sha" != "$floor" ] || return 1
85
- [ "${pending_count:-0}" -eq 0 ] 2>/dev/null || return 1
86
- [ "${failed_count:-0}" -gt 0 ] 2>/dev/null || return 1
92
+ watch_checks_settled_red "$pending_count" "$failed_count" || return 1
87
93
  echo "EVENT pr=$pr checks settled red head=$head_sha"
88
94
  }
89
95
 
96
+ # True when the branch needs a rebase onto its base: conflicting with it, or
97
+ # behind it by a measured, positive count. An unreadable count is not behind.
98
+ watch_branch_needs_rebase() {
99
+ local mergeable="$1" behind_count="$2"
100
+ [ "$mergeable" = "CONFLICTING" ] && return 0
101
+ [ -n "$behind_count" ] && [ "$behind_count" -gt 0 ] 2>/dev/null
102
+ }
103
+
90
104
  # The branch needing a rebase onto its base — conflicting with it, or merely
91
105
  # behind it.
92
106
  #
@@ -106,11 +120,11 @@ watch_wake_rebase() {
106
120
  local pr="$1" mergeable="$2" behind_count="$3" rebase_key="$4" floor="$5"
107
121
  [ -n "$rebase_key" ] || return 1
108
122
  [ "$rebase_key" != "$floor" ] || return 1
123
+ watch_branch_needs_rebase "$mergeable" "$behind_count" || return 1
109
124
  if [ "$mergeable" = "CONFLICTING" ]; then
110
125
  echo "EVENT pr=$pr branch conflicting with base key=$rebase_key"
111
126
  return 0
112
127
  fi
113
- [ -n "$behind_count" ] && [ "$behind_count" -gt 0 ] 2>/dev/null || return 1
114
128
  echo "EVENT pr=$pr branch behind base by $behind_count — rebase due key=$rebase_key"
115
129
  }
116
130
 
@@ -39,7 +39,7 @@ fi
39
39
  # gone. Guards missing means the plugin moved or upgraded underneath this loop —
40
40
  # a newer version's watcher owns the slot now, so step down rather than run on
41
41
  # without the supersede check.
42
- for lib in pr-watch-guards.sh pr-watch-events.sh pr-watch-fetch.sh; do
42
+ for lib in pr-watch-guards.sh pr-watch-events.sh pr-watch-fetch.sh pr-watch-due.sh; do
43
43
  [ -f "${script_dir}/${lib}" ] || exit 0
44
44
  # shellcheck source=/dev/null
45
45
  . "${script_dir}/${lib}"
@@ -66,6 +66,11 @@ floor_ci_red=""
66
66
  floor_rebase=""
67
67
  floor_blocked_digest=""
68
68
 
69
+ # What watch-due.env last recorded, so the file is rewritten only when the due
70
+ # work changes rather than every poll.
71
+ due_rebase_key=""
72
+ recorded_due_work="unrecorded"
73
+
69
74
  # Pin the token once: a detached loop can lose access to gh's OS keyring
70
75
  # mid-run, which surfaces as empty fetches rather than an error.
71
76
  pinned_token="$(gh auth token 2>/dev/null)"
@@ -202,13 +207,27 @@ while :; do
202
207
  fi
203
208
 
204
209
  rebase_key="${head_sha}..${base_tip_sha}"
205
- if [ "$rebase_key" != "$watermark_rebase" ] && [ "$rebase_key" != "$floor_rebase" ]; then
210
+ if [ "$rebase_key" = "$watermark_rebase" ] || [ "$rebase_key" = "$floor_rebase" ]; then
211
+ # Only a key already found due is ever floored, and the pair's standing
212
+ # cannot change until the head or the base moves, which mints a new key.
213
+ due_rebase_key="$rebase_key"
214
+ else
206
215
  behind_count=$(watch_fetch_behind_count "$repo" "$base_branch" "$head_sha" "$slot")
216
+ due_rebase_key=""
207
217
  if watch_wake_rebase "$pr_number" "$mergeable" "$behind_count" "$rebase_key" ""; then
208
218
  floor_rebase="$rebase_key"
219
+ due_rebase_key="$rebase_key"
209
220
  fi
210
221
  fi
211
222
 
223
+ ci_red_head=""
224
+ watch_checks_settled_red "$pending_checks" "$failed_checks" && ci_red_head="$head_sha"
225
+ due_work="${head_sha} ${due_rebase_key} ${ci_red_head}"
226
+ if [ "$due_work" != "$recorded_due_work" ]; then
227
+ watch_record_due_work "$slot" "$head_sha" "$due_rebase_key" "$ci_red_head"
228
+ recorded_due_work="$due_work"
229
+ fi
230
+
212
231
  # The tick owns clearing the block, and it may not run for a while. Holding
213
232
  # the emitted digest stops the loop repeating itself every iteration in the
214
233
  # meantime — the repeat nagging the design rules out — while a further move
@@ -0,0 +1,197 @@
1
+ import { readFileSync } from 'fs';
2
+ import { homedir } from 'os';
3
+ import { join, dirname } from 'path';
4
+ import { fileURLToPath } from 'url';
5
+
6
+ // src/pr-watch/cli.ts
7
+
8
+ // src/pr-watch/constants.ts
9
+ var MAX_REBASE_ATTEMPTS_PER_KEY = 2;
10
+ var MAX_CI_FIX_ATTEMPTS_PER_HEAD = 3;
11
+ var REBASE_KEY_SEPARATOR = "..";
12
+ var USER_PREFERENCES_PATH_SEGMENTS = [".muggle-ai", "preferences.json"];
13
+ var PREFERENCE_DEFAULTS_PATH_SEGMENTS = ["config", "preference-defaults.json"];
14
+ var AUTO_REBASE_PREFERENCE_KEY = "autoRebase";
15
+ var MAX_CATCH_UP_REBASES_PREFERENCE_KEY = "maxCatchUpRebases";
16
+ var UNBOUNDED_PREFERENCE_VALUE = "never";
17
+ var POSITIVE_INTEGER = /^[1-9]\d*$/;
18
+ var LINE_BREAK = /[\r\n]/;
19
+ var PR_KEY_FLAG = "pr-key";
20
+ var HEAD_FLAG = "head";
21
+ var REBASE_KEY_FLAG = "rebase-key";
22
+ var REBASE_DUE_FLAG = "rebase-due";
23
+ var CI_FLAG = "ci";
24
+ var REBASE_DUE_YES = "yes";
25
+ var USAGE_EXIT_CODE = 2;
26
+ var PR_WATCH_VERDICT_USAGE = "usage: pr-watch-verdict.mjs arm-floors --pr-key <owner/repo#n> --head <sha> --rebase-key <head..base-tip> < last_seen.json\n pr-watch-verdict.mjs tick --pr-key <owner/repo#n> --head <sha> --rebase-key <head..base-tip> --rebase-due <yes|no> --ci <red|pending|green> < last_seen.json";
27
+
28
+ // src/pr-watch/attempts.ts
29
+ function recordedCount(counts, key) {
30
+ const recorded = counts?.[key];
31
+ return typeof recorded === "number" && Number.isFinite(recorded) ? recorded : 0;
32
+ }
33
+ function rebaseAttemptsFor(lastSeenEntry, rebaseKey) {
34
+ return recordedCount(lastSeenEntry.conflict_resolve_attempts, rebaseKey);
35
+ }
36
+ function ciFixAttemptsFor(lastSeenEntry, headSha) {
37
+ return recordedCount(lastSeenEntry.ci_fix_attempts, headSha);
38
+ }
39
+ function isRebaseKeyAttempted(lastSeenEntry, rebaseKey) {
40
+ return rebaseAttemptsFor(lastSeenEntry, rebaseKey) >= 1;
41
+ }
42
+ function isCiHeadAttempted(lastSeenEntry, headSha) {
43
+ return ciFixAttemptsFor(lastSeenEntry, headSha) >= 1;
44
+ }
45
+ function isRebaseKeyEscalated(lastSeenEntry, rebaseKey) {
46
+ return rebaseKey.includes(REBASE_KEY_SEPARATOR) && (lastSeenEntry.conflict_escalated_keys ?? []).includes(rebaseKey) && isRebaseKeyAttempted(lastSeenEntry, rebaseKey);
47
+ }
48
+ function isCiHeadEscalated(lastSeenEntry, headSha) {
49
+ return (lastSeenEntry.ci_escalated_shas ?? []).includes(headSha) && isCiHeadAttempted(lastSeenEntry, headSha);
50
+ }
51
+ function isRebaseBudgetExhausted(lastSeenEntry, maxCatchUpRebases) {
52
+ const catchUpRebases = lastSeenEntry.catch_up_rebases;
53
+ return maxCatchUpRebases !== null && typeof catchUpRebases === "number" && catchUpRebases >= maxCatchUpRebases;
54
+ }
55
+
56
+ // src/pr-watch/armFloors.ts
57
+ function resolveArmFloorEvidence(lastSeenEntry, headSha, rebaseKey) {
58
+ const blockedCiDigest = lastSeenEntry.blocked?.fingerprint?.ci_digest;
59
+ return {
60
+ isRebaseKeyAttempted: rebaseKey !== "" && isRebaseKeyAttempted(lastSeenEntry, rebaseKey),
61
+ isCiHeadAttempted: headSha !== "" && isCiHeadAttempted(lastSeenEntry, headSha),
62
+ blockedCiDigest: typeof blockedCiDigest === "string" && !LINE_BREAK.test(blockedCiDigest) ? blockedCiDigest : ""
63
+ };
64
+ }
65
+ function readJsonRecord(filePath) {
66
+ try {
67
+ return asRecord(JSON.parse(readFileSync(filePath, "utf-8")));
68
+ } catch {
69
+ return {};
70
+ }
71
+ }
72
+ function asRecord(candidate) {
73
+ return candidate !== null && typeof candidate === "object" && !Array.isArray(candidate) ? candidate : {};
74
+ }
75
+ function lastSeenEntryFor(lastSeenJson, prKey) {
76
+ try {
77
+ return asRecord(asRecord(JSON.parse(lastSeenJson))[prKey]);
78
+ } catch {
79
+ return {};
80
+ }
81
+ }
82
+
83
+ // src/pr-watch/types.ts
84
+ var CiRollupBucket = /* @__PURE__ */ ((CiRollupBucket2) => {
85
+ CiRollupBucket2["Red"] = "red";
86
+ CiRollupBucket2["Pending"] = "pending";
87
+ CiRollupBucket2["Green"] = "green";
88
+ return CiRollupBucket2;
89
+ })(CiRollupBucket || {});
90
+
91
+ // src/pr-watch/tickVerdict.ts
92
+ function resolveWatchTickVerdict(lastSeenEntry, observation, preferences) {
93
+ const { headSha, rebaseKey } = observation;
94
+ if (observation.isRebaseDue) {
95
+ if (isRebaseBudgetExhausted(lastSeenEntry, preferences.maxCatchUpRebases)) {
96
+ return "block-rebase-budget-exhausted" /* BlockRebaseBudgetExhausted */;
97
+ }
98
+ const isRebaseKeyBudgetLeft = rebaseAttemptsFor(lastSeenEntry, rebaseKey) < MAX_REBASE_ATTEMPTS_PER_KEY;
99
+ if (isRebaseKeyBudgetLeft && !isRebaseKeyEscalated(lastSeenEntry, rebaseKey)) return "dispatch-rebase" /* DispatchRebase */;
100
+ }
101
+ if (observation.ciBucket === "red" /* Red */) {
102
+ const isCiHeadBudgetLeft = ciFixAttemptsFor(lastSeenEntry, headSha) < MAX_CI_FIX_ATTEMPTS_PER_HEAD;
103
+ if (isCiHeadBudgetLeft && !isCiHeadEscalated(lastSeenEntry, headSha)) return "dispatch-fix-ci" /* DispatchFixCi */;
104
+ }
105
+ if (isRebaseKeyEscalated(lastSeenEntry, rebaseKey)) return "block-conflict-escalated" /* BlockConflictEscalated */;
106
+ if (isCiHeadEscalated(lastSeenEntry, headSha)) return "block-ci-escalated" /* BlockCiEscalated */;
107
+ if ((lastSeenEntry.escalated_review_ids ?? []).length > 0) return "block-reviews-escalated" /* BlockReviewsEscalated */;
108
+ return "idle" /* Idle */;
109
+ }
110
+
111
+ // src/pr-watch/verdictCommand.ts
112
+ function parseVerdictArguments(flagTokens) {
113
+ const parsed = {};
114
+ for (let index = 0; index < flagTokens.length; index += 1) {
115
+ const token = flagTokens[index];
116
+ if (!token.startsWith("--")) continue;
117
+ const next = flagTokens[index + 1];
118
+ const hasValue = next !== void 0 && !next.startsWith("--");
119
+ parsed[token.slice(2)] = hasValue ? next : "";
120
+ if (hasValue) index += 1;
121
+ }
122
+ return parsed;
123
+ }
124
+ var usageFailure = (problem) => ({
125
+ stdout: "",
126
+ stderr: `pr-watch-verdict: ${problem}
127
+ ${PR_WATCH_VERDICT_USAGE}
128
+ `,
129
+ exitCode: USAGE_EXIT_CODE
130
+ });
131
+ function runPrWatchVerdictCommand(commandLine, lastSeenJson, resolvePreferences) {
132
+ const [subcommand, ...flagTokens] = commandLine;
133
+ const flags = parseVerdictArguments(flagTokens);
134
+ const prKey = flags[PR_KEY_FLAG];
135
+ if (!prKey) return usageFailure(`--${PR_KEY_FLAG} is required`);
136
+ const lastSeenEntry = lastSeenEntryFor(lastSeenJson, prKey);
137
+ const headSha = flags[HEAD_FLAG] ?? "";
138
+ const rebaseKey = flags[REBASE_KEY_FLAG] ?? "";
139
+ if (subcommand === "arm-floors" /* ArmFloors */) {
140
+ const evidence = resolveArmFloorEvidence(lastSeenEntry, headSha, rebaseKey);
141
+ return {
142
+ stdout: `REBASE_ATTEMPTED=${evidence.isRebaseKeyAttempted ? 1 : 0}
143
+ CI_ATTEMPTED=${evidence.isCiHeadAttempted ? 1 : 0}
144
+ BLOCKED_CIDIGEST=${evidence.blockedCiDigest}
145
+ `,
146
+ stderr: "",
147
+ exitCode: 0
148
+ };
149
+ }
150
+ if (subcommand === "tick" /* Tick */) {
151
+ const ciBucket = Object.values(CiRollupBucket).find((bucket) => bucket === flags[CI_FLAG]);
152
+ if (!ciBucket) return usageFailure(`--${CI_FLAG} must be one of ${Object.values(CiRollupBucket).join(", ")}`);
153
+ if (!headSha || !rebaseKey) return usageFailure(`--${HEAD_FLAG} and --${REBASE_KEY_FLAG} are required`);
154
+ const verdict = resolveWatchTickVerdict(
155
+ lastSeenEntry,
156
+ { headSha, rebaseKey, isRebaseDue: flags[REBASE_DUE_FLAG] === REBASE_DUE_YES, ciBucket },
157
+ resolvePreferences()
158
+ );
159
+ return { stdout: `VERDICT=${verdict}
160
+ `, stderr: "", exitCode: 0 };
161
+ }
162
+ return usageFailure(`unknown subcommand ${subcommand ?? "(none)"}`);
163
+ }
164
+ function resolvePluginRoot(env = process.env) {
165
+ return env.CLAUDE_PLUGIN_ROOT || env.CURSOR_PLUGIN_ROOT || dirname(dirname(fileURLToPath(import.meta.url)));
166
+ }
167
+
168
+ // src/pr-watch/watchPreferences.ts
169
+ function parseMaxCatchUpRebases(configuredValue) {
170
+ if (configuredValue === UNBOUNDED_PREFERENCE_VALUE) return null;
171
+ const spelled = typeof configuredValue === "number" ? String(configuredValue) : configuredValue;
172
+ return typeof spelled === "string" && POSITIVE_INTEGER.test(spelled) ? Number(spelled) : void 0;
173
+ }
174
+ function resolveWatchPreferences(homeDir = homedir(), pluginRoot = resolvePluginRoot()) {
175
+ const shippedDefaults = readJsonRecord(join(pluginRoot, ...PREFERENCE_DEFAULTS_PATH_SEGMENTS));
176
+ const userPreferences = asRecord(readJsonRecord(join(homeDir, ...USER_PREFERENCES_PATH_SEGMENTS)).preferences);
177
+ const autoRebase = userPreferences[AUTO_REBASE_PREFERENCE_KEY] ?? shippedDefaults[AUTO_REBASE_PREFERENCE_KEY];
178
+ const userCap = parseMaxCatchUpRebases(userPreferences[MAX_CATCH_UP_REBASES_PREFERENCE_KEY]);
179
+ const shippedCap = parseMaxCatchUpRebases(shippedDefaults[MAX_CATCH_UP_REBASES_PREFERENCE_KEY]);
180
+ return {
181
+ autoRebase: typeof autoRebase === "string" ? autoRebase : void 0,
182
+ maxCatchUpRebases: userCap !== void 0 ? userCap : shippedCap ?? null
183
+ };
184
+ }
185
+
186
+ // src/pr-watch/cli.ts
187
+ function readLastSeenFromStdin() {
188
+ try {
189
+ return readFileSync(0, "utf-8");
190
+ } catch {
191
+ return "";
192
+ }
193
+ }
194
+ var outcome = runPrWatchVerdictCommand(process.argv.slice(2), readLastSeenFromStdin(), () => resolveWatchPreferences());
195
+ process.stderr.write(outcome.stderr);
196
+ process.stdout.write(outcome.stdout);
197
+ process.exitCode = outcome.exitCode;
@@ -8,4 +8,5 @@ Map a red CI check to the local command that reproduces and fixes it. Repo-agnos
8
8
  | typecheck | Run the typecheck script; read the errors; edit the types. |
9
9
  | unit / test | Run the suite; read the failures; fix the code or the test. |
10
10
  | `muggle-walkthrough` — the Muggle E2E walkthrough check | In scope. Its check-run summary names each failed or inconclusive case with the failing step and a link to the run; the walkthrough comment's hidden `muggle-e2e-result` record carries the same cases with their test case ids. Repair each, re-run the **whole** E2E suite, and settle the walkthrough comment with the new result — editing the comment re-runs the check. A summary saying the comment is still empty means no run was ever posted: run the suite and post it. |
11
- | out of scope — any other E2E-in-CI, build/deploy infra, flaky / non-deterministic, or unknown | Do **not** attempt; record for escalation. |
11
+ | non-deterministic — an LLM-judged eval gate (e.g. `skill-routing-eval`, `skill-gate-eval`, `agent-gate-eval`) or another check whose verdict can flip with nothing changed | Re-run its failed jobs once per head, without a push: `gh run rerun <run-id> --failed` (GitLab: retry the failed job). The re-run counts as a fix attempt. Escalate only if it fails again on the same head. How long the check takes is never a reason to skip the re-run. |
12
+ | out of scope — any other E2E-in-CI, build/deploy infra, or unknown | Do **not** attempt; record for escalation. |
@@ -14,7 +14,7 @@ Resolve red CI on a PR's head — lint/format, typecheck, failing unit tests, an
14
14
 
15
15
  ## Inputs from disk
16
16
 
17
- From `~/.muggle-ai/muggle-do/sessions/<slug>/`: `prs.json` (PR + local checkout / branch), `last_seen.json` (`ci_fix_attempts`, `ci_escalated_shas`, `pushed_shas`), `state.md` (worktree path, validation strategy).
17
+ From `~/.muggle-ai/muggle-do/sessions/<slug>/`: `prs.json` (PR + local checkout / branch), `last_seen.json` (`ci_fix_attempts`, `ci_escalated_shas`, `ci_rerun_shas`, `pushed_shas`), `state.md` (worktree path, validation strategy).
18
18
 
19
19
  ## Procedure
20
20
 
@@ -22,9 +22,13 @@ From `~/.muggle-ai/muggle-do/sessions/<slug>/`: `prs.json` (PR + local checkout
22
22
 
23
23
  Check out the PR branch in the session's working tree (per `state.md`). Capture `red_sha = prs.json[0].head_sha` — this cycle's `pre_cycle_sha` ([`cycle-size.md`](cycle-size.md)).
24
24
 
25
+ Then increment `last_seen.ci_fix_attempts[red_sha]` — before any fix, re-run or escalation, as a whole-file rewrite (Read → change field → Write) per [`../_shared/session-state-writes.md`](../_shared/session-state-writes.md), never the Edit tool. Every dispatched cycle is an attempt, including one that only re-runs a check or escalates without pushing. That count is the only record the watcher and its turn-end gate accept that this red head was acted on; an escalation written without it is ignored and fix-ci is dispatched again ([`../muggle-pr-followup/state-schemas.md`](../muggle-pr-followup/state-schemas.md#last_seenjson)).
26
+
25
27
  ### Step 2 — Map each failing check to a local command
26
28
 
27
- Per [`../_shared/ci-check-to-command.md`](../_shared/ci-check-to-command.md). Fix the in-scope checks in the working tree; record out-of-scope checks for escalation (Step 6). A red `muggle-walkthrough` check takes Step 2.5.
29
+ Per [`../_shared/ci-check-to-command.md`](../_shared/ci-check-to-command.md). Fix the in-scope checks in the working tree; record out-of-scope checks for escalation (Step 6). A red `muggle-walkthrough` check takes Step 2.5; a red non-deterministic check takes Step 2.6.
30
+
31
+ How long a check takes to run — a 45-minute eval included — is never a reason to skip, defer or escalate it. A held fix needs the user's own words: a message they typed containing `HOLD WATCH #<pr-number>`.
28
32
 
29
33
  ### Step 2.5 — Red E2E walkthrough check
30
34
 
@@ -36,6 +40,18 @@ Per [`../_shared/ci-check-to-command.md`](../_shared/ci-check-to-command.md). Fi
36
40
 
37
41
  An empty-comment failure (no run ever posted) skips items 1–2: run the suite and settle the comment. Under a `unit-only` or `skip` validation in `state.md`, settle it with the verified skip code instead.
38
42
 
43
+ ### Step 2.6 — Red non-deterministic check: re-run once per head
44
+
45
+ A check whose verdict can change with nothing changed — an LLM-judged eval gate such as `skill-routing-eval`, `skill-gate-eval` or `agent-gate-eval` — gets one automatic re-run per head before anything escalates:
46
+
47
+ - **A deterministic check is also red and in scope** → skip the re-run. Fix that check (Steps 3–4); the push re-runs every check on the new head.
48
+ - **`red_sha` ∉ `last_seen.ci_rerun_shas`** → re-run the failed jobs of each such check's run, without pushing — the run id is the `/actions/runs/<run-id>/` segment of the check's `link` ([`../_shared/vcs/github/pr-checks.md`](../_shared/vcs/github/pr-checks.md)):
49
+ ```bash
50
+ gh run rerun <run-id> --failed --repo <owner>/<repo>
51
+ ```
52
+ GitLab retries the failed job instead ([`../_shared/vcs/gitlab/mr-pipeline.md`](../_shared/vcs/gitlab/mr-pipeline.md)). Append `red_sha` to `last_seen.ci_rerun_shas` (whole-file rewrite), skip Steps 3–4, and go to Step 5. The attempt was counted in Step 1; the watcher wakes on the re-run's verdict like any other.
53
+ - **`red_sha` ∈ `ci_rerun_shas`** — it already had its re-run and failed again → escalate per Step 6.
54
+
39
55
  ### Step 3 — Verify before push
40
56
 
41
57
  - Build (typecheck + lint on the changed surface) + unit suite must pass.
@@ -47,16 +63,15 @@ A fix that can't be made green locally is not pushed → Step 6.
47
63
 
48
64
  Commit per the `fix(ci): <check> — <what>` convention ([`../_shared/pr-followup-helpers/reply-routing.md`](../_shared/pr-followup-helpers/reply-routing.md)). Push. Append the new SHA to `last_seen.pushed_shas`. Then finish the tail [`cycle-size.md`](cycle-size.md) picked: a full fix reposts the walkthrough (a Step 2.5 repair settles it there instead), a minor one declares the skip. **No PR replies** — the fix commit is the response.
49
65
 
50
- ### Step 5 — Update state + respawn
66
+ ### Step 5 — Respawn
51
67
 
52
- - Increment `last_seen.ci_fix_attempts[red_sha]` — a whole-file rewrite (Read → change field → Write) per [`../_shared/session-state-writes.md`](../_shared/session-state-writes.md), never the Edit tool.
53
- - Respawn the watcher per [`respawn-watcher.md`](respawn-watcher.md). CI on the new SHA is the verify loop — a still-red SHA returns as a fresh dispatch, bounded by the per-SHA fix budget (Step 6).
68
+ Respawn the watcher per [`respawn-watcher.md`](respawn-watcher.md). CI on the new SHA — or the re-run's fresh verdict on the same one — is the verify loop: a still-red SHA returns as a fresh dispatch, bounded by the per-SHA fix budget (Step 6).
54
69
 
55
70
  ### Step 6 — Escalate (budget spent or out of scope)
56
71
 
57
- When the failing checks are all out of scope, or `ci_fix_attempts[red_sha]` has reached 3 with CI still red:
72
+ When the failing checks are all out of scope, a non-deterministic check is red again after its re-run on this head (Step 2.6), or this is the head's third cycle (`ci_fix_attempts[red_sha]` reached 3 in Step 1) and it could not push a fix:
58
73
 
59
- 1. Add `red_sha` to `last_seen.ci_escalated_shas` so the SHA is not re-fixed.
74
+ 1. Add `red_sha` to `last_seen.ci_escalated_shas` so the SHA is not re-fixed. This cycle's Step 1 attempt is what makes the entry count.
60
75
  2. Emit one terminal message naming the unresolved checks.
61
76
  3. Emit the cycle event with `outcome: "ci-escalated"` (Step 7).
62
77
  4. **Respawn the watcher** per [`respawn-watcher.md`](respawn-watcher.md). Escalation stops fix-ci from re-dispatching this SHA — but the poller must keep running: it reminds on the `ci_escalated` block and catches a new push, a new review, or the user's own fix. Skipping respawn here is the silent-stop bug the helper exists to prevent.
@@ -67,5 +82,6 @@ Emit one `muggle-do:cycle` event ([`../_shared/telemetry-events/muggle-do-cycle.
67
82
 
68
83
  ## Guardrails
69
84
 
70
- - Max 3 fix attempts per SHA; out-of-scope checks escalate immediately rather than churn. A walkthrough repair that pushes nothing keeps the head SHA, so the same budget bounds it.
85
+ - Max 3 fix attempts per SHA; out-of-scope checks escalate immediately rather than churn. A walkthrough repair or a re-run that pushes nothing keeps the head SHA, so the same budget bounds it.
86
+ - A non-deterministic check is re-run once per head before it escalates — never escalated on its first red, never re-run twice on one head.
71
87
  - No PR replies; the fix commit is the response.
@@ -22,6 +22,10 @@ From `~/.muggle-ai/muggle-do/sessions/<slug>/`: `prs.json` (PR + branch + `head_
22
22
 
23
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
+ Then increment `last_seen.conflict_resolve_attempts[rebase_key]` — before rebasing, as a whole-file rewrite (Read → change field → Write) per [`../_shared/session-state-writes.md`](../_shared/session-state-writes.md), never the Edit tool. Every dispatched rebase is an attempt, including one that escalates on a conflict under `autoResolveConflicts=never` or fails verification. That count is the only record the watcher and its turn-end gate accept that this key was acted on; an entry in `conflict_escalated_keys` without it is ignored and the rebase is dispatched again ([`../muggle-pr-followup/state-schemas.md`](../muggle-pr-followup/state-schemas.md#last_seenjson)).
26
+
27
+ `autoRebase=always` makes this rebase binding. The CI or evals a force-push re-runs — however long they take — are never a reason to hold it; the only hold is the user's own message containing `HOLD WATCH #<pr-number>`.
28
+
25
29
  ### Step 2 — Rebase onto base (resolve conflicts if any)
26
30
 
27
31
  Run the rebase from [`../_shared/sync-branch-with-base.md`](../_shared/sync-branch-with-base.md) against the base branch, taking its `always` path unconditionally — this programmatic mode never asks, so skip the `autoRebase` prompt (the watcher already decided a rebase is due).
@@ -37,13 +41,13 @@ Build (typecheck + lint on the changed surface) + unit suite must pass. Size the
37
41
 
38
42
  ### Step 4 — Force-push + respawn
39
43
 
40
- Force-push per [`../_shared/vcs/common/push-to-branch.md`](../_shared/vcs/common/push-to-branch.md) (tool-agnostic instruction; handles the signing gate for rebased commits and directs to provider-specific force-push paths). Use `git push --force-with-lease` for the force operation. Append the new SHA to `last_seen.pushed_shas`; increment `last_seen.conflict_resolve_attempts[rebase_key]` **and** `last_seen.catch_up_rebases` — all whole-file rewrites (Read → change field → Write) per [`../_shared/session-state-writes.md`](../_shared/session-state-writes.md), never the Edit tool. The second counter is unkeyed on purpose: `rebase_key` carries the base tip, so it mints a fresh budget every time the base moves and cannot bound a PR on an active base. Increment it on every push here, including one that later escalates, or a branch that fails the same way twenty times reads as having spent nothing. Finish the tail [`cycle-size.md`](cycle-size.md) picked — a full rebase reposts the walkthrough, a minor one declares the skip — then 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.
44
+ Force-push per [`../_shared/vcs/common/push-to-branch.md`](../_shared/vcs/common/push-to-branch.md) (tool-agnostic instruction; handles the signing gate for rebased commits and directs to provider-specific force-push paths). Use `git push --force-with-lease` for the force operation. Append the new SHA to `last_seen.pushed_shas` and increment `last_seen.catch_up_rebases` (the per-key attempt was counted in Step 1) — both whole-file rewrites (Read → change field → Write) per [`../_shared/session-state-writes.md`](../_shared/session-state-writes.md), never the Edit tool. That counter is unkeyed on purpose: `rebase_key` carries the base tip, so it mints a fresh budget every time the base moves and cannot bound a PR on an active base. Increment it on every push here, including one that later escalates, or a branch that fails the same way twenty times reads as having spent nothing. Finish the tail [`cycle-size.md`](cycle-size.md) picked — a full rebase reposts the walkthrough, a minor one declares the skip — then 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
45
 
42
46
  ### Step 5 — Escalate (can't resolve / budget spent)
43
47
 
44
- When `autoResolveConflicts=never`, the resolution failed verification, or `conflict_resolve_attempts[rebase_key]` has reached 2:
48
+ When `autoResolveConflicts=never`, the resolution failed verification, or this is the key's second attempt (`conflict_resolve_attempts[rebase_key]` reached 2 in Step 1) and it did not push:
45
49
 
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.
50
+ 1. Add `rebase_key` to `last_seen.conflict_escalated_keys` so the watcher does not re-dispatch this head against this base. Step 1's attempt is what makes the entry count. 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
51
  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
52
  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
53
 
@@ -45,7 +45,7 @@ The skill recognizes its mode by inspecting `$ARGUMENTS` and falling back to on-
45
45
  | `reconcile` / `sweep` (optional `<slug>`) | — | **reconcile** → [`reconcile.md`](reconcile.md) |
46
46
  | `adopt` (optional `<slug>`) | — | **adopt** → [`adopt.md`](adopt.md) — take over a slot owned by a dead session; no slug lists the adoptable ones |
47
47
 
48
- **`--wake=<event>`** is passed only by an event wake's dispatch ([`arm-watcher.md`](arm-watcher.md) step 5) — it asserts the monitor already saw something new, so the tick's poll is justified. Manual invocations never pass it; with a live watcher they get watch-status, because a poll that nothing prompted is a main-session poll wasted. Recovery fires need no flag — a recoverable slot's watcher is dead by definition, so the gate falls through to tick. A stale cron firing against a re-armed slot hits the live-`watch.pid` branch and is absorbed as a status line, no provider calls.
48
+ **`--wake=<event>`** is passed only by an event wake's dispatch ([`arm-watcher.md`](arm-watcher.md) step 5), or by the follow-through Stop gate's instruction (`--wake=follow-through`) when the watch recorded due work nothing attempted — either asserts something is waiting, so the tick's poll is justified. Manual invocations never pass it; with a live watcher they get watch-status, because a poll that nothing prompted is a main-session poll wasted. Recovery fires need no flag — a recoverable slot's watcher is dead by definition, so the gate falls through to tick. A stale cron firing against a re-armed slot hits the live-`watch.pid` branch and is absorbed as a status line, no provider calls.
49
49
 
50
50
  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 this session's own open slots 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 — and never re-arms one this session does not own. A no-arg invocation is a request to track *your* PRs, so it can only ever end with the session watching PRs it pushed plus watchers it already had.
51
51