@muggleai/works 5.36.0 → 5.37.0-staging.341

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 (40) 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 +1 -1
  10. package/dist/plugin/scripts/guardrail-watch-follow-through-gate.sh +3 -2
  11. package/dist/plugin/scripts/guardrails.mjs +87 -4
  12. package/dist/plugin/scripts/pr-watch-arm.sh +75 -4
  13. package/dist/plugin/scripts/pr-watch-due.sh +16 -7
  14. package/dist/plugin/scripts/pr-watch-fetch.sh +1 -1
  15. package/dist/plugin/scripts/pr-watch-loop.sh +8 -1
  16. package/dist/plugin/scripts/pr-watch-state.jq +30 -5
  17. package/dist/plugin/scripts/pr-watch-verdict.mjs +69 -4
  18. package/dist/plugin/skills/muggle-pr-followup/arm-watcher.md +3 -3
  19. package/dist/plugin/skills/muggle-pr-followup/contract.md +1 -1
  20. package/dist/plugin/skills/muggle-pr-followup/state-schemas.md +6 -3
  21. package/dist/release-manifest.json +4 -4
  22. package/package.json +11 -11
  23. package/plugin/.claude-plugin/plugin.json +1 -1
  24. package/plugin/.codex-mcp.json +1 -1
  25. package/plugin/.codex-plugin/plugin.json +1 -1
  26. package/plugin/.cursor-plugin/plugin.json +1 -1
  27. package/plugin/.mcp.json +1 -1
  28. package/plugin/hooks/README.md +1 -1
  29. package/plugin/scripts/guardrail-watch-follow-through-gate.sh +3 -2
  30. package/plugin/scripts/guardrails.mjs +87 -4
  31. package/plugin/scripts/pr-watch-arm.sh +75 -4
  32. package/plugin/scripts/pr-watch-due.sh +16 -7
  33. package/plugin/scripts/pr-watch-fetch.sh +1 -1
  34. package/plugin/scripts/pr-watch-loop.sh +8 -1
  35. package/plugin/scripts/pr-watch-state.jq +30 -5
  36. package/plugin/scripts/pr-watch-verdict.mjs +69 -4
  37. package/plugin/skills/muggle-pr-followup/arm-watcher.md +3 -3
  38. package/plugin/skills/muggle-pr-followup/contract.md +1 -1
  39. package/plugin/skills/muggle-pr-followup/state-schemas.md +6 -3
  40. /package/dist/{chunk-HTCBHSL6.js → chunk-UWKBSNUQ.js} +0 -0
@@ -23,9 +23,14 @@ var HEAD_FLAG = "head";
23
23
  var REBASE_KEY_FLAG = "rebase-key";
24
24
  var REBASE_DUE_FLAG = "rebase-due";
25
25
  var CI_FLAG = "ci";
26
+ var BODY_REVIEWS_FLAG = "body-reviews";
27
+ var CONVERSATION_COMMENTS_FLAG = "conversation-comments";
28
+ var UNANSWERED_THREADS_FLAG = "unanswered-threads";
29
+ var STATE_LIST_SEPARATOR = ",";
30
+ var THREAD_COMMENT_REVIEW_SEPARATOR = ":";
26
31
  var REBASE_DUE_YES = "yes";
27
32
  var USAGE_EXIT_CODE = 2;
28
- 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";
33
+ var PR_WATCH_VERDICT_USAGE = "usage: pr-watch-verdict.mjs arm-floors --pr-key <owner/repo#n> --head <sha> --rebase-key <head..base-tip> [--body-reviews <ids>] [--conversation-comments <ids>] [--unanswered-threads <comment:review,...>] < 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";
29
34
 
30
35
  // src/pr-watch/attempts.ts
31
36
  function recordedCount(counts, key) {
@@ -66,14 +71,64 @@ function hasEscalatedReviewFeedback(lastSeenEntry) {
66
71
  );
67
72
  }
68
73
 
74
+ // src/pr-watch/unhandledFeedback.ts
75
+ function parseFeedbackId(text) {
76
+ const parsed = Number(text.trim());
77
+ return text.trim() !== "" && Number.isSafeInteger(parsed) && parsed > 0 ? parsed : void 0;
78
+ }
79
+ function parseFeedbackIdList(listText) {
80
+ return listText.split(STATE_LIST_SEPARATOR).map(parseFeedbackId).filter((feedbackId) => feedbackId !== void 0);
81
+ }
82
+ function parseUnansweredThreadComments(listText) {
83
+ const threadComments = [];
84
+ for (const entry of listText.split(STATE_LIST_SEPARATOR)) {
85
+ const [commentText = "", reviewText = ""] = entry.split(THREAD_COMMENT_REVIEW_SEPARATOR);
86
+ const commentId = parseFeedbackId(commentText);
87
+ if (commentId === void 0) continue;
88
+ threadComments.push({ commentId, owningReviewId: parseFeedbackId(reviewText) });
89
+ }
90
+ return threadComments;
91
+ }
92
+ function handledWatermark(recorded) {
93
+ return typeof recorded === "number" && Number.isFinite(recorded) ? recorded : void 0;
94
+ }
95
+ function floorCeilingBelow(feedbackIds) {
96
+ return feedbackIds.length > 0 ? Math.min(...feedbackIds) - 1 : void 0;
97
+ }
98
+ var ascendingUnique = (feedbackIds) => [...new Set(feedbackIds)].sort((left, right) => left - right);
99
+ function resolveUnhandledFeedback(lastSeenEntry, observation) {
100
+ const escalatedReviewIds = new Set(lastSeenEntry.escalated_review_ids ?? []);
101
+ const escalatedConversationIds = new Set(lastSeenEntry.escalated_conversation_comment_ids ?? []);
102
+ const handledBodyReviewId = handledWatermark(lastSeenEntry.lastBodyReviewId);
103
+ const handledConversationId = handledWatermark(lastSeenEntry.lastConversationCommentId);
104
+ const unhandledBodyReviewIds = handledBodyReviewId === void 0 ? [] : observation.bodyOnlyReviewIds.filter(
105
+ (reviewId) => reviewId > handledBodyReviewId && !escalatedReviewIds.has(reviewId)
106
+ );
107
+ const unansweredThreadComments = observation.unansweredThreadComments.filter(
108
+ (threadComment) => threadComment.owningReviewId === void 0 || !escalatedReviewIds.has(threadComment.owningReviewId)
109
+ );
110
+ const unhandledConversationIds = handledConversationId === void 0 ? [] : observation.conversationCommentIds.filter(
111
+ (commentId) => commentId > handledConversationId && !escalatedConversationIds.has(commentId)
112
+ );
113
+ const threadOwningReviewIds = unansweredThreadComments.map((threadComment) => threadComment.owningReviewId).filter((reviewId) => reviewId !== void 0);
114
+ return {
115
+ reviewIds: ascendingUnique([...unhandledBodyReviewIds, ...threadOwningReviewIds]),
116
+ conversationCommentIds: ascendingUnique(unhandledConversationIds),
117
+ reviewFloorCeiling: floorCeilingBelow(unhandledBodyReviewIds),
118
+ commentFloorCeiling: floorCeilingBelow(unansweredThreadComments.map((threadComment) => threadComment.commentId)),
119
+ conversationFloorCeiling: floorCeilingBelow(unhandledConversationIds)
120
+ };
121
+ }
122
+
69
123
  // src/pr-watch/armFloors.ts
70
- function resolveArmFloorEvidence(lastSeenEntry, headSha, rebaseKey, maxCatchUpRebases) {
124
+ function resolveArmFloorEvidence(lastSeenEntry, headSha, rebaseKey, maxCatchUpRebases, feedbackObservation) {
71
125
  const blockedCiDigest = lastSeenEntry.blocked?.fingerprint?.ci_digest;
72
126
  return {
73
127
  isRebaseKeyAttempted: rebaseKey !== "" && isRebaseKeyAttempted(lastSeenEntry, rebaseKey),
74
128
  isCiHeadSettled: headSha !== "" && isCiHeadSettled(lastSeenEntry, headSha),
75
129
  isRebaseBudgetExhausted: isRebaseBudgetExhausted(lastSeenEntry, maxCatchUpRebases),
76
- blockedCiDigest: typeof blockedCiDigest === "string" && !LINE_BREAK.test(blockedCiDigest) ? blockedCiDigest : ""
130
+ blockedCiDigest: typeof blockedCiDigest === "string" && !LINE_BREAK.test(blockedCiDigest) ? blockedCiDigest : "",
131
+ unhandledFeedback: resolveUnhandledFeedback(lastSeenEntry, feedbackObservation)
77
132
  };
78
133
  }
79
134
  function readJsonRecord(filePath) {
@@ -153,12 +208,22 @@ function runPrWatchVerdictCommand(commandLine, lastSeenJson, resolvePreferences)
153
208
  const headSha = flags[HEAD_FLAG] ?? "";
154
209
  const rebaseKey = flags[REBASE_KEY_FLAG] ?? "";
155
210
  if (subcommand === "arm-floors" /* ArmFloors */) {
156
- const evidence = resolveArmFloorEvidence(lastSeenEntry, headSha, rebaseKey, resolvePreferences().maxCatchUpRebases);
211
+ const evidence = resolveArmFloorEvidence(lastSeenEntry, headSha, rebaseKey, resolvePreferences().maxCatchUpRebases, {
212
+ bodyOnlyReviewIds: parseFeedbackIdList(flags[BODY_REVIEWS_FLAG] ?? ""),
213
+ conversationCommentIds: parseFeedbackIdList(flags[CONVERSATION_COMMENTS_FLAG] ?? ""),
214
+ unansweredThreadComments: parseUnansweredThreadComments(flags[UNANSWERED_THREADS_FLAG] ?? "")
215
+ });
216
+ const { unhandledFeedback } = evidence;
157
217
  return {
158
218
  stdout: `REBASE_ATTEMPTED=${evidence.isRebaseKeyAttempted ? 1 : 0}
159
219
  CI_SETTLED=${evidence.isCiHeadSettled ? 1 : 0}
160
220
  BLOCKED_CIDIGEST=${evidence.blockedCiDigest}
161
221
  REBASE_BUDGET_EXHAUSTED=${evidence.isRebaseBudgetExhausted ? 1 : 0}
222
+ UNHANDLED_REVIEW_IDS=${unhandledFeedback.reviewIds.join(" ")}
223
+ UNHANDLED_CONVERSATION_IDS=${unhandledFeedback.conversationCommentIds.join(" ")}
224
+ REVIEW_FLOOR_CEILING=${unhandledFeedback.reviewFloorCeiling ?? ""}
225
+ COMMENT_FLOOR_CEILING=${unhandledFeedback.commentFloorCeiling ?? ""}
226
+ CONVERSATION_FLOOR_CEILING=${unhandledFeedback.conversationFloorCeiling ?? ""}
162
227
  `,
163
228
  stderr: "",
164
229
  exitCode: 0
@@ -12,10 +12,10 @@ That command runs as a background shell command (Step 3), never a foreground Bas
12
12
 
13
13
  The same argument that forbids authoring a per-slot `watch.sh` applies to arming itself. Performed from prose, the middle step — writing `watch-watermark.env` — is the one that gets dropped, and dropping it is silent: the loop gates every wake condition on that file, so it polls nothing, reports nothing and never reaches its terminal check, while still holding its PID lease and touching its heartbeat. Eleven such watchers once ran for hours across one session, missed nine merges and a red CI run between them, and every health signal said they were fine. Running one command cannot half-happen.
14
14
 
15
- The `DRAIN` lines it prints, in the watch's output, are the outstanding work as of the arm. Review ids and threads the drain read are floored, so the loop will *not* tell you about those again. A stale branch or a red head is floored only when `last_seen.json` records a rebase or fix-ci cycle already attempted for that key or head ([`state-schemas.md`](state-schemas.md#watch-watermarkenv)); otherwise the drain line says `not floored: dispatch …` and the loop's first poll reports it as an event. A PR that spent its catch-up rebase budget is the exception: its drain line says the rebase is `held for the owner`, and nothing is dispatched — the tick would refuse it — until the owner raises [`maxCatchUpRebases`](../muggle-preferences/preference-gates/maxCatchUpRebases.md). Re-arming is never a way to set work aside — it neither handles nor silences anything. Steps 1-3 below are what the script does, and why.
15
+ The `DRAIN` lines it prints, in the watch's output, are the outstanding work as of the arm. Review feedback is floored only up to what `last_seen.json` records as handled or escalated: a body-only review or conversation comment above its handled watermark, or an unresolved thread whose newest comment muggle did not post — the tick's actionable set ([`contract.md`](contract.md) Step 3) — is listed first, as `review feedback unhandled at arm time … not floored: dispatch address-reviews`, and its floor (`REV`, `CONV`, or `COM`) is capped just below the lowest such id, so the loop's first poll reports it. The same cap applies to the slot's `watch-reported.env`: an earlier loop that reported the feedback does not make it handled, so a re-arm re-reports it until `last_seen.json` records it handled or escalated. A muggle watch service arm while a report still waits queued for the owner leaves the reported floors alone — that report already wakes the owner. Muggle's own signed posts and bot comments never count. Reviews preempt CI and rebase, so while that line is present the CI and rebase lines end `dispatch … after address-reviews`. Feedback already handled is floored, and the loop will *not* tell you about it again. A stale branch or a red head is floored only when `last_seen.json` records a rebase or fix-ci cycle already attempted for that key or head ([`state-schemas.md`](state-schemas.md#watch-watermarkenv)); otherwise the drain line says `not floored: dispatch …` and the loop's first poll reports it as an event. A PR that spent its catch-up rebase budget is the exception: its drain line says the rebase is `held for the owner`, and nothing is dispatched — the tick would refuse it — until the owner raises [`maxCatchUpRebases`](../muggle-preferences/preference-gates/maxCatchUpRebases.md). Re-arming is never a way to set work aside — it neither handles nor silences anything. Steps 1-3 below are what the script does, and why.
16
16
 
17
17
  1. **Drain.** Run one tick per [`contract.md`](contract.md). It acts on everything already outstanding — actionable threads (`gitlab`: discussions), body-only reviews past the watermark (GitHub-only — GitLab has no review envelope), conversation comments past theirs (GitHub-only), 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.
18
- 2. **Seed the watermark.** *(`pr-watch-arm.sh` does this; the reasoning is kept because the floors are subtle and wrong ones are quiet.)* Resolve the provider once per [`../_shared/vcs/detect-vcs.md`](../_shared/vcs/detect-vcs.md) — every fetch in this sequence uses that provider's recipes. Write the slot's watch watermark ([`state-schemas.md`](state-schemas.md#watch-watermarkenv)) to the ids the **drain itself read** — the max review-id, comment-id and human conversation-comment id (`CONV`) observed at the drain's own fetch (Step 1), snapshotted at that read. Never let the loop capture its own baseline — the arming session writes it; and **never** from a fresh fetch taken after the drain, which would include a comment that arrived after the drain read the wave and mark it seen unread. Seeded to the drain's floor, anything landing after that read stays above the watermark and the loop's first iteration surfaces it. Seed the CI floor (`CIRED`) from the same drain read: set it to the red key (`<head_sha>@<red-check-runs>`) only when the checks have **already settled red** at that read (no check pending, one or more in the `fail` bucket per [`../_shared/vcs/common/ci-rollup.md`](../_shared/vcs/common/ci-rollup.md)) **and** fix-ci is finished with that head — it escalated, or spent the tick's per-head budget — and empty otherwise. A lone attempt does not floor: the count is written before the fix runs, so a cycle that recorded it and changed nothing would otherwise leave the red silent. Seed the rebase floor (`REBASED`) the same way, from the drain's branch-standing read per [`../_shared/vcs/common/branch-standing.md`](../_shared/vcs/common/branch-standing.md): the current `rebase_key` (`<head_sha>..<base_tip_sha>`) only when the drain found the branch behind or conflicting **and** a rebase attempt is recorded for that key, empty otherwise. An escalation entry alone never floors anything: one with no attempt behind it records a decision nobody acted on, and flooring it is how a re-arming session once kept a stale branch and a red head silent for a day ([`state-schemas.md`](state-schemas.md#watch-watermarkenv) names the fields). Seed the blocked-CI floor (`BLOCKED_CIDIGEST`) to the blocked fingerprint's `ci_digest` when arming while `last_seen.blocked` is already set, and empty otherwise — empty is the not-blocked state, in which the loop's blocked-resume probe stays dormant. Seed the rebase hold (`REBASE_HELD`) to `1` when `last_seen.json`'s `catch_up_rebases` has reached `maxCatchUpRebases` — the same check the tick's verdict blocks on — and empty otherwise: while it is set the loop raises no rebase wake on any base move. The script reads all four facts from `last_seen.json` through [`../../scripts/pr-watch-verdict.mjs`](../../scripts/pr-watch-verdict.mjs) `arm-floors`, and records what it found due in `watch-due.env` ([`state-schemas.md`](state-schemas.md#watch-dueenv)).
18
+ 2. **Seed the watermark.** *(`pr-watch-arm.sh` does this; the reasoning is kept because the floors are subtle and wrong ones are quiet.)* Resolve the provider once per [`../_shared/vcs/detect-vcs.md`](../_shared/vcs/detect-vcs.md) — every fetch in this sequence uses that provider's recipes. Write the slot's watch watermark ([`state-schemas.md`](state-schemas.md#watch-watermarkenv)) to the ids the **drain itself read** — the max review-id, comment-id and human conversation-comment id (`CONV`) observed at the drain's own fetch (Step 1), snapshotted at that read — each capped just below the lowest feedback in that read that `last_seen.json` does not record as handled or escalated. The read's ids are not the handled ones: a comment posted before the slot was bootstrapped is in the read, and seeding past it marks it seen with nobody having answered it. A re-arm caps the floors it carries forward the same way. Never let the loop capture its own baseline — the arming session writes it; and **never** from a fresh fetch taken after the drain, which would include a comment that arrived after the drain read the wave and mark it seen unread. Seeded to the drain's floor, anything landing after that read stays above the watermark and the loop's first iteration surfaces it. Seed the CI floor (`CIRED`) from the same drain read: set it to the red key (`<head_sha>@<red-check-runs>`) only when the checks have **already settled red** at that read (no check pending, one or more in the `fail` bucket per [`../_shared/vcs/common/ci-rollup.md`](../_shared/vcs/common/ci-rollup.md)) **and** fix-ci is finished with that head — it escalated, or spent the tick's per-head budget — and empty otherwise. A lone attempt does not floor: the count is written before the fix runs, so a cycle that recorded it and changed nothing would otherwise leave the red silent. Seed the rebase floor (`REBASED`) the same way, from the drain's branch-standing read per [`../_shared/vcs/common/branch-standing.md`](../_shared/vcs/common/branch-standing.md): the current `rebase_key` (`<head_sha>..<base_tip_sha>`) only when the drain found the branch behind or conflicting **and** a rebase attempt is recorded for that key, empty otherwise. An escalation entry alone never floors anything: one with no attempt behind it records a decision nobody acted on, and flooring it is how a re-arming session once kept a stale branch and a red head silent for a day ([`state-schemas.md`](state-schemas.md#watch-watermarkenv) names the fields). Seed the blocked-CI floor (`BLOCKED_CIDIGEST`) to the blocked fingerprint's `ci_digest` when arming while `last_seen.blocked` is already set, and empty otherwise — empty is the not-blocked state, in which the loop's blocked-resume probe stays dormant. Seed the rebase hold (`REBASE_HELD`) to `1` when `last_seen.json`'s `catch_up_rebases` has reached `maxCatchUpRebases` — the same check the tick's verdict blocks on — and empty otherwise: while it is set the loop raises no rebase wake on any base move. The script reads all four facts from `last_seen.json` through [`../../scripts/pr-watch-verdict.mjs`](../../scripts/pr-watch-verdict.mjs) `arm-floors`, and records what it found due in `watch-due.env` ([`state-schemas.md`](state-schemas.md#watch-dueenv)).
19
19
  3. **Dedup, then watch.** First read `<slot>/watch.pid` ([`state-schemas.md`](state-schemas.md#watchpid)): if it names a live process (`kill -0 "$pid"` succeeds), **`owner.json` records this session**, and the slot has no [`watch-listener`](state-schemas.md#watch-listener) file, a watcher already owns this slot — **skip arming, do not start a second**. A live loop whose `watch-listener` names `muggle-watch` was started by the muggle watch service and reports to the service, not to this session: arm over it. The new loop supersedes it, takes the slot back, and deletes the service's undelivered reports, which this arm's drain covers. This is what stops orphaned watchers from accumulating: the in-session task dying does not stop the OS loop it launched (on Windows a detached Git Bash loop keeps running and polling `gh` forever after the session ends), so checking a live task list is not enough — the PID lease is.
20
20
 
21
21
  **A live lease owned by a different session does not count as owned** — check it with `watcher_lease_is_foreign` from [`../../scripts/pr-watch-guards.sh`](../../scripts/pr-watch-guards.sh). A live PID proves the loop is running, never that anything is listening: an orphan left by a dead session keeps polling and keeps touching its heartbeat while its stdout is that session's closed pipe, so every liveness signal reads healthy and the events reach nobody. Skipping on the PID alone let such a corpse block this session from arming the PR for the whole lifetime cap — seven days, since the default moved off six hours. When the guard reports a foreign lease, kill that PID, delete `watch.pid`, and arm fresh; note it in the slot's `followup.log` so the reclaim is visible.
@@ -40,7 +40,7 @@ The `DRAIN` lines it prints, in the watch's output, are the outstanding work as
40
40
 
41
41
  The task's description is `PR #<n> — <title>`. Description and command both matter: some task surfaces show one, some the other, and a slot-bearing command keeps the watch identifiable everywhere a raw script blob would not. One background task per PR at a time: it is the watch's visible handle, showing as a running task while the PR is polled, and replaced by a fresh one after each report. Its loop checks about every 60 seconds, re-reading the watermark and touching the slot's `watch-heartbeat` file each iteration — the liveness beacon that tells [`reconcile.md`](reconcile.md) a quiet watch is still alive; on a newer submitted review, a newer thread comment (`gitlab`: a newer discussion note), a newer human conversation comment (`github`: a top-level PR comment muggle did not post and no bot wrote), a thread newly unresolved (`gitlab`: discussion), **the head SHA's checks settling red** (no check pending and one or more in the `fail` bucket per [`../_shared/vcs/common/ci-rollup.md`](../_shared/vcs/common/ci-rollup.md)), **the branch falling behind or conflicting with its base** (`behind_by > 0` or the conflict signal per [`../_shared/vcs/common/branch-standing.md`](../_shared/vcs/common/branch-standing.md)), or — **only while the watch is blocked** (`BLOCKED_CIDIGEST` non-empty) — **the head's CI digest changing in any way** (not just to red) — it prints one line per finding and **exits**, recording what it reported in `watch-reported.env` ([`state-schemas.md`](state-schemas.md#watch-reportedenv)) so no later loop reports the same occurrence again. The review, comment, conversation and thread floors are monotonic ids; the other three are not. The CI-red floor is the **red key** — the head SHA plus each failed check's run id — because the check rollup is non-monotonic: it flips green↔red and resets on every push, so the key fires once per red verdict and a later push re-arms it on the new SHA. The run ids matter because a settled walkthrough comment or a rerun publishes a new run on the same head; when that run is red too, it is the verdict fix-ci is waiting on, and a head-only floor swallowed it. The rebase floor (`REBASED`) is the **`rebase_key`** — `<head_sha>..<base_tip_sha>` — because staleness is a function of both sides: keying on the pair fires once per newly-due pair and re-arms when either the head or the base moves, where a head-only key would wedge permanently the first time the base advances (the head cannot change while nobody pushes). A head whose checks are still **pending** is never a red wake, and a branch with `behind_by == 0` and `mergeable == UNKNOWN` is never a rebase wake: pending checks may yet go green and conflict state is still computing, and the tick would idle on either (Steps 5–6) regardless. The blocked-CI signal is different in kind — a **resume** probe, live only while the watch is blocked: it wakes on any move of the head's CI digest (the same bucket-plus-sorted-name/conclusion signature the blocked fingerprint records — [`blocked-tick.md`](blocked-tick.md)) away from `BLOCKED_CIDIGEST`, so a block waiting on a green pass, a rerun, or an external deploy check resumes as promptly as one waiting on red. Quiet iterations print nothing and cost nothing — no model tokens are spent while the watch is quiet.
42
42
 
43
- Each poll also rewrites the slot's `watch-due.env` whenever the due work changes — the rebase key found due and the head whose checks settled red, or an empty file when neither — so the session's turn-end gate can see work the watch reported without a provider call ([`state-schemas.md`](state-schemas.md#watch-dueenv)).
43
+ Each poll also rewrites the slot's `watch-due.env` whenever the due work changes — the rebase key found due, the head whose checks settled red, and the unhandled feedback the arm recorded, or an empty file when none — so the session's turn-end gate can see work the watch reported without a provider call ([`state-schemas.md`](state-schemas.md#watch-dueenv)).
44
44
 
45
45
  The loop is **self-terminating**, so it never becomes one of those orphans. It claims the slot's `watch.pid`, then checks the guards from [`../../scripts/pr-watch-guards.sh`](../../scripts/pr-watch-guards.sh) at the top of every iteration before any `gh` call: `watcher_superseded` steps it down silently when a newer arm takes the slot, and `watcher_lifetime_exceeded` retires it with an `EXPIRED` line so a still-open PR's owner re-arms it. `watcher_window_elapsed` acts only on a loop given a `MUGGLE_PR_WATCH_MONITOR_WINDOW`, for running under a `Monitor`: it ends the loop with a `ROLLOVER` line before the monitor stops reading, and every wait is clamped to that window. A failed fetch is never mistaken for a terminal PR — it counts toward `MUGGLE_PR_WATCH_MAX_FETCH_FAILURES` (60) with `watcher_fetch_backoff` between tries, so hours of outage are ridden out and the error lands in `<slot>/watch-fetch.log`. Terminal exit stays reserved for an observed `MERGED`/`CLOSED`.
46
46
 
@@ -115,7 +115,7 @@ The watcher does **not** classify. Classification, batching, replying, escalatio
115
115
  A wave of conversation comments alone dispatches with an empty review list: `address reviews conversation <cid1> on <pr-url> slug=<slug>`.
116
116
  4. Append a dispatching line to `followup.log` per [`output-templates/watcher-log.md`](output-templates/watcher-log.md).
117
117
  5. Emit a `tick` event with `actionable_threads: <count>` (conversation comments included), `dispatched_review_ids: [<id>, ...]`.
118
- 6. Exit. **Reviews preempt CI** — when there is actionable feedback, this tick dispatches address-reviews and never polls CI. The watcher is now stopped; the dev cycle owns the PR and restarts the watcher when it finishes. (The watcher also self-unschedules in Step 2, terminal.)
118
+ 6. Exit. **Reviews preempt CI** — when there is actionable feedback, this tick dispatches address-reviews and never polls CI. The arm's drain applies the same precedence: it lists unhandled feedback ahead of any red CI or stale branch and never floors it ([`arm-watcher.md`](arm-watcher.md)). A loop having reported the feedback is no exception: only this step's actionable rules decide what is handled, so a re-armed loop reports it again and the follow-through Stop gate keeps the turn open on it ([`../../hooks/README.md`](../../hooks/README.md)). The watcher is now stopped; the dev cycle owns the PR and restarts the watcher when it finishes. (The watcher also self-unschedules in Step 2, terminal.)
119
119
 
120
120
  ### Step 5 — No actionable feedback → read the branch's standing against its base
121
121
 
@@ -245,11 +245,13 @@ The watch loop's comparison floor — plain `KEY=VALUE` lines, one file per slot
245
245
  - `COM` — highest thread-comment id already handled
246
246
  - `CONV` — highest human conversation-comment id (top-level PR comment, Conversation tab) already handled. The loop's projection drops muggle's own posts and bot authors before taking the max, so the loop's signed reply never lifts it. A watermark without the key predates the floor: arming seeds it from the drain's read, and a loop running over such a watermark floors at its own first read until then.
247
247
  - `THREADS` — semicolon-joined ids of threads already known unresolved
248
- - `CIRED` — the red key `<head_sha>@<red-check-runs>` (each failed check's `name#run-id`, sorted — the last field of [`../../scripts/pr-watch-state.jq`](../../scripts/pr-watch-state.jq)) of a red verdict fix-ci is finished with: `head_sha` ∈ `ci_escalated_shas` with an attempt behind it, or `ci_fix_attempts[sha] >= 3`. Empty when the checks are green, still pending, unseen, or red with fix-ci not finished — the last so the loop reports it. A lone attempt never floors: the count is written before the fix runs, so it proves a cycle started, not that anything on the PR changed. The floor is a red key rather than a monotonic id because the rollup flips green↔red and resets on each push, and it carries run ids because a settled walkthrough comment or a rerun publishes a new run on the **same** head — a red verdict from that run is what fix-ci waits on, so it wakes the loop again ([`arm-watcher.md`](arm-watcher.md)).
248
+ - `CIRED` — the red key `<head_sha>@<red-check-runs>` (each failed check's `name#run-id`, sorted — the red-check-runs field of [`../../scripts/pr-watch-state.jq`](../../scripts/pr-watch-state.jq)) of a red verdict fix-ci is finished with: `head_sha` ∈ `ci_escalated_shas` with an attempt behind it, or `ci_fix_attempts[sha] >= 3`. Empty when the checks are green, still pending, unseen, or red with fix-ci not finished — the last so the loop reports it. A lone attempt never floors: the count is written before the fix runs, so it proves a cycle started, not that anything on the PR changed. The floor is a red key rather than a monotonic id because the rollup flips green↔red and resets on each push, and it carries run ids because a settled walkthrough comment or a rerun publishes a new run on the **same** head — a red verdict from that run is what fix-ci waits on, so it wakes the loop again ([`arm-watcher.md`](arm-watcher.md)).
249
249
  - `REBASED` — the `rebase_key` (`<head_sha>..<base_tip_sha>`) whose behind/conflicting state a rebase cycle already attempted (`conflict_resolve_attempts[key] >= 1`); empty when the branch is current with its base, unseen, or stale with no attempt. Keyed on the pair, not a monotonic id, because staleness depends on both sides — the loop fires once per newly-due pair and re-arms when the head or the base moves. Same key [`contract.md`](contract.md) Steps 5–6 dedup rebase dispatch on; the loop only signals a due rebase, the tick's verdict applies the budgets.
250
250
  - `BLOCKED_CIDIGEST` — the head's `ci_digest` at the moment a block was flagged (the same signature `blocked.fingerprint.ci_digest` carries); empty whenever the watch is not blocked. Non-empty arms the loop's blocked-resume probe: while set, the loop wakes on any move of the live digest away from this value, so a block resumes on a green pass, a rerun, or an external deploy check — not only on red. Written by [`blocked-tick.md`](blocked-tick.md) when a block is flagged and cleared to empty when it resumes.
251
251
  - `REBASE_HELD` — `1` when the PR has spent its catch-up rebase budget (`catch_up_rebases` has reached [`maxCatchUpRebases`](../muggle-preferences/preference-gates/maxCatchUpRebases.md)), empty otherwise. While set, the loop raises no rebase wake and records no rebase as due however far the base moves: the tick's verdict refuses every rebase until the owner raises the cap, so a wake would only ask for work it turns down. Every arm recomputes it, so a raised cap lifts the hold at the next re-arm.
252
252
 
253
+ Arming never seeds `REV`, `COM` or `CONV` past feedback `last_seen.json` does not record as handled or escalated: each is capped one below the lowest unhandled body-only review, unanswered thread comment, or conversation comment the arm read, so the loop's first poll reports it ([`arm-watcher.md`](arm-watcher.md)). It caps [`watch-reported.env`](#watch-reportedenv) the same way.
254
+
253
255
  Written whole-file by the orchestrating session — the review/comment/CI/rebase floors seeded at arm time (`REV`/`COM`/`CONV`/`THREADS` to the **drain's own observed max** on a first arm, and carried forward from this file on a re-arm, dropping threads since resolved, so a review that landed after the session's last read stays above them; `CIRED`/`REBASED` to the red head and stale key a cycle already attempted, `REBASE_HELD` from the rebase budget) and advanced after every cycle to the **handled wave's snapshot** (the max review-id, comment-id and conversation-comment id the cycle read at the start of handling, captured before replies were posted); `BLOCKED_CIDIGEST` is set and cleared by the blocked-tick flag/resume path, and every arm re-seeds it from `last_seen.blocked.fingerprint.ci_digest` so a re-arm keeps the resume probe live. **Never** derived from a fresh fetch taken after the drain or after replies land: a later fetch includes ids that arrived in the handling window and were never read, and marking them seen swallows them ([`arm-watcher.md`](arm-watcher.md)). The advance also never moves any floor past an unresolved thread the cycle left unaddressed. Read by the watch loop each iteration; the loop never writes it. A stale watermark makes the next reported event the loop's own reply.
254
256
 
255
257
  **Never `source` this file, and quote or extract values.** `THREADS` holds bare semicolons: sourced unquoted, the shell splits the line at the first `;` and silently drops every id after it — the loop then re-reports known threads as new. The watch loop must extract values verbatim (e.g. `grep '^THREADS=' | cut -d= -f2- | tr -d '"\r'`), tolerating quotes and CRLF; writers should quote the value anyway.
@@ -261,8 +263,9 @@ The work the watch last saw due on its PR, for the owning session's turn-end gat
261
263
  - `HEAD` — the head SHA the observation was made on.
262
264
  - `REBASE_DUE` — the `rebase_key` found behind or conflicting with the base; empty when the branch is current.
263
265
  - `CI_RED_HEAD` — the head whose checks settled red; empty when CI is green or still pending.
266
+ - `FEEDBACK_REVIEWS` / `FEEDBACK_CONVERSATION` / `FEEDBACK_THREADS` — the arm read's body-only review ids, conversation comment ids and unanswered `<comment>:<review>` threads, comma-joined as [`../../scripts/pr-watch-state.jq`](../../scripts/pr-watch-state.jq) lists them; written only when the arm found any of them unhandled, empty otherwise. The loop carries them through its rewrites, and the next arm replaces them.
264
267
 
265
- The file is **empty** when nothing is due. Written by [`../../scripts/pr-watch-arm.sh`](../../scripts/pr-watch-arm.sh) from the drain's read and rewritten by the loop whenever what is due changes; the session never writes it. The follow-through Stop gate ([`../../hooks/README.md`](../../hooks/README.md)) blocks the turn end while a non-empty record in a slot this session owns names work with no matching attempt in `last_seen.json`: a `REBASE_DUE` key with no `conflict_resolve_attempts` entry (under `autoRebase=always`, budget left), or a `CI_RED_HEAD` with no `ci_fix_attempts` entry. A later tick's `prs.json` naming another head supersedes the record.
268
+ The file is **empty** when nothing is due. Written by [`../../scripts/pr-watch-arm.sh`](../../scripts/pr-watch-arm.sh) from the drain's read and rewritten by the loop whenever what is due changes; the session never writes it. The follow-through Stop gate ([`../../hooks/README.md`](../../hooks/README.md)) blocks the turn end while a non-empty record in a slot this session owns names work with no matching attempt in `last_seen.json`: a `REBASE_DUE` key with no `conflict_resolve_attempts` entry (under `autoRebase=always`, budget left), a `CI_RED_HEAD` with no `ci_fix_attempts` entry, or feedback the arm's actionable rules still find unhandled — a body-only review above `lastBodyReviewId` or a conversation comment above `lastConversationCommentId`, not escalated, or a thread comment above the watermark's `COM` whose review is not escalated. Whether a loop already reported that feedback does not matter. A later tick's `prs.json` naming another head supersedes the rebase and CI fields, never the feedback: a reply is owed to the comment, not the commit.
266
269
 
267
270
  ## `watch-reported.env`
268
271
 
@@ -273,7 +276,7 @@ What the slot's loops already reported to the session — `KEY="value"` lines li
273
276
  - `CIRED` / `REBASED` — the red key and the rebase key a loop reported.
274
277
  - `BLOCKED_CIDIGEST` / `BLOCKED_FOR` — the CI digest a blocked-resume wake reported, and the watermark's `BLOCKED_CIDIGEST` it was reported under. It quiets only that block, so the same digest can resume a later one.
275
278
 
276
- A loop fires only on what sits above both this file and [`watch-watermark.env`](#watch-watermarkenv). Every report ends a loop, so no floor can live in its memory: without this file, anything the session saw and chose not to act on — a comment needing no reply, a red check under `HOLD WATCH` — would end every fresh loop on its first poll. Read it as the watermark is read, never by `source`.
279
+ A loop fires only on what sits above both this file and [`watch-watermark.env`](#watch-watermarkenv). Every report ends a loop, so no floor can live in its memory: without this file, anything the session saw and chose not to act on — a red check under `HOLD WATCH` — would end every fresh loop on its first poll. Reported is not handled, though: every arm caps `REV`, `COM` and `CONV` here exactly as it caps the watermark's, one below the lowest feedback `last_seen.json` records neither handled nor escalated, so a re-armed loop reports it again. Feedback the cycle handled or escalated has no cap and stays quiet. The one exception is a muggle watch service arm while a report waits in `watch-service.queued.out`: that report already wakes the owner. Read it as the watermark is read, never by `source`.
277
280
 
278
281
  ## `watch.pid`
279
282
 
@@ -1,7 +1,7 @@
1
1
  {
2
- "release": "5.36.0",
3
- "buildId": "run-338-1",
4
- "commitSha": "02b73fc36335d2669486cc032604d82d09a6ae0b",
5
- "buildTime": "2026-11-12T04:23:53Z",
2
+ "release": "5.37.0-staging.341",
3
+ "buildId": "run-341-1",
4
+ "commitSha": "0bf18e64e58e04a7cddbe4af9b690dd96c63af28",
5
+ "buildTime": "2026-11-12T07:45:22Z",
6
6
  "serviceName": "muggle-ai-works-mcp"
7
7
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@muggleai/works",
3
3
  "mcpName": "io.github.multiplex-ai/muggleai",
4
- "version": "5.36.0",
4
+ "version": "5.37.0-staging.341",
5
5
  "description": "Acceptance test agent for coding agents: real-browser tests, with screenshots on the PR.",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
@@ -66,21 +66,21 @@
66
66
  "typecheck:browser-bench": "tsc --noEmit -p internal/browser-bench/tsconfig.json"
67
67
  },
68
68
  "muggleConfig": {
69
- "electronAppVersion": "1.24.16",
69
+ "electronAppVersion": "1.25.2",
70
70
  "downloadBaseUrl": "https://github.com/multiplex-ai/muggle-ai-works/releases/download",
71
- "runtimeTargetDefault": "production",
71
+ "runtimeTargetDefault": "staging",
72
72
  "checksumsByStream": {
73
73
  "production": {
74
- "win32-x64": "9645ed8e777fada8893c9f61abc1cdad827808385a68a462c4c087c02dcbaea0",
75
- "linux-x64": "7067dc5b8fc805c72f615237c6a91f9b5b39381f1b39ce24618b67b2d38fbfe3",
76
- "darwin-arm64": "19389b118394f576ae206737a129f797b386cd8d138f2f4d58e0ad121e89a174",
77
- "darwin-x64": "258a27c4474bd875b441d432f1c5d992b1ce485f72a1ac4849e4dd3af1fa2c4f"
74
+ "win32-x64": "71a6affdea586ce59d915f63096120019f55052d72ce693c4d219bd03206e830",
75
+ "linux-x64": "c7f0c5184a4021cc8b639e727e7666cc09e55165e9a29fcfb1219b14ccf9b5b1",
76
+ "darwin-arm64": "385ce152f58d7016fedc2844face2945042b5913717da3aff3e6410ec8c3383b",
77
+ "darwin-x64": "ff244891f092a8882806d9847103b8a24a89de64bb398917314128a998d49abd"
78
78
  },
79
79
  "staging": {
80
- "darwin-arm64": "2c408bae15a83eb1ddf2946fa82c1108ec9cdb918753f539e66c0fddbb0d3091",
81
- "linux-x64": "5fe31d7544c2b89714730afe583ceaf1365247496815757a3c6fd7d4703ac8a7",
82
- "win32-x64": "28ba946a81e4bc1aa70aa3597bfa102c54ff006d4b787e5ea4710db7e26b7764",
83
- "darwin-x64": "87806b5ca988aeb4cce35a12ae7d1e79a6b8387ee5bf24d0af64fd08d32ee98a"
80
+ "darwin-arm64": "d4d8fd58d2ac5bcc3e65a3acb28869be63fbba658e20cd0f791f9e0cecec568c",
81
+ "linux-x64": "af3a2cf182a96cc5066c5e603b96b3231d22946969ce30ea2bf67d737335e6fd",
82
+ "win32-x64": "b328bfad315f9c5ec772ab6756fae26884b462c840435583c2e73a4220d0f18c",
83
+ "darwin-x64": "1942d331d86fd011e75f644f2dadacf19280610f9f50648c5e4ed76a84662c9b"
84
84
  }
85
85
  },
86
86
  "electronAppSignedFromVersion": "1.10.0",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "muggle",
3
3
  "description": "Acceptance test agent for coding agents: real-browser tests, with screenshots on the PR.",
4
- "version": "5.36.0",
4
+ "version": "5.37.0-staging.341",
5
5
  "author": {
6
6
  "name": "Muggle AI",
7
7
  "email": "support@muggle-ai.com"
@@ -4,7 +4,7 @@
4
4
  "command": "npx",
5
5
  "args": [
6
6
  "-y",
7
- "@muggleai/works@5.36.0",
7
+ "@muggleai/works@5.37.0-staging.341",
8
8
  "serve"
9
9
  ],
10
10
  "env": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muggle",
3
- "version": "5.36.0",
3
+ "version": "5.37.0-staging.341",
4
4
  "description": "Acceptance test agent for coding agents: real-browser tests, with screenshots on the PR.",
5
5
  "author": {
6
6
  "name": "Muggle AI",
@@ -2,7 +2,7 @@
2
2
  "name": "muggle",
3
3
  "displayName": "Muggle AI",
4
4
  "description": "Acceptance test agent for coding agents: real-browser tests, with screenshots on the PR.",
5
- "version": "5.36.0",
5
+ "version": "5.37.0-staging.341",
6
6
  "author": {
7
7
  "name": "Muggle AI",
8
8
  "email": "support@muggle-ai.com"
package/plugin/.mcp.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "command": "npx",
5
5
  "args": [
6
6
  "-y",
7
- "@muggleai/works@5.36.0",
7
+ "@muggleai/works@5.37.0-staging.341",
8
8
  "serve"
9
9
  ]
10
10
  }
@@ -52,7 +52,7 @@ Pre-filters are bash builtins only (`guardrail-lib.sh`), so an irrelevant event
52
52
  | `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, leaving the PR's walkthrough comment unsettled). Quiet while a background acceptance-tester is in flight |
53
53
  | `Stop` | `guardrail-terminal-gate.sh` | **enforce** | a PR went terminal this session and the next-options offer hasn't run since — an AskUserQuestion, or, while the session owns an open PR's watch slot, a closing message that asks the user | — | **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) |
54
54
  | `Stop` | `guardrail-watch-gate.sh` | **enforce** | a PR opened this session that is still open and has no live watch — no session slot for it is terminal, stopped by its owner, or carries a `watch-heartbeat` touched within 15 minutes; a slot that is only seeded does not count | `autoWatchPR` | **block** the turn until the watch is armed per `muggle-pr-followup`'s `arm-watcher.md` or a `MUGGLE_WATCH_SKIP` marker records a legitimate skip (releases after 3 blocks). A PR clears once the session sees it go terminal or a provider lookup reports it merged or closed — what lets a PR whose slot post-merge cleanup deleted through. The lookup runs in a detached scan queued at turn end; a PR it has not reached yet still blocks, and one it could not reach fails open |
55
- | `Stop` | `guardrail-watch-follow-through-gate.sh` | **enforce** | a `muggle-pr-followup` watch this session owns (the slot's `owner.json`) recorded due work in `watch-due.env` — a branch behind or conflicting with its base, or a head whose checks settled red — and `last_seen.json` records no attempt for it: no `conflict_resolve_attempts` entry for the rebase key (enforced under `autoRebase=always` while catch-up budget is left), no `ci_fix_attempts` entry for the red head. An escalation entry with no attempt behind it counts for nothing, and re-arming the watch changes nothing. Also fires when the slot holds a muggle watch service report the session was never woken for (`watch-service.queued.out`, or an `EVENT`/`TERMINAL` line in an exited service loop's `watch-service.out`). A PR whose `last_seen.json` sets `forward_stages_in_flight` owes nothing | `autoRebase` | **block** the turn, naming each PR and its `/muggle-do rebase` or `fix ci` dispatch, or for an undelivered report its `/muggle:muggle-pr-followup <slug> <n> --wake=follow-through` tick, which the re-arm it ends on clears. No release after N blocks: only a recorded attempt, a newer head in the slot's `prs.json`, or the user's literal `HOLD WATCH #<pr-number>` clears it. The hold must come from a turn the user typed — never a tool result, a loaded skill, a hook's message, a task notification, a compaction summary, or the agent's own text — and is kept for the session once read. Reads local files only, never a provider: the pre-filter is a builtins glob for a non-empty `watch-due.env` or an undelivered service report whose `owner.json` names the session, so Node starts only when a slot has due work |
55
+ | `Stop` | `guardrail-watch-follow-through-gate.sh` | **enforce** | a `muggle-pr-followup` watch this session owns (the slot's `owner.json`) recorded due work in `watch-due.env` — a branch behind or conflicting with its base, a head whose checks settled red, or review feedback the arm found unhandled — and `last_seen.json` records no attempt for it: no `conflict_resolve_attempts` entry for the rebase key (enforced under `autoRebase=always` while catch-up budget is left), no `ci_fix_attempts` entry for the red head, and for feedback no `lastBodyReviewId` / `lastConversationCommentId` (or watermark `COM`, for a thread) reaching it and no escalation. A loop having reported the feedback does not clear it. An escalation entry with no attempt behind it counts for nothing, and re-arming the watch changes nothing. Also fires when the slot holds a muggle watch service report the session was never woken for (`watch-service.queued.out`, or an `EVENT`/`TERMINAL` line in an exited service loop's `watch-service.out`). A PR whose `last_seen.json` sets `forward_stages_in_flight` owes nothing | `autoRebase` | **block** the turn, naming each PR and its `/muggle-do rebase` or `fix ci` dispatch, for unhandled feedback its `/muggle:muggle-pr-followup <slug> <n> --wake=follow-through` tick, or for an undelivered report its `/muggle:muggle-pr-followup <slug> <n> --wake=follow-through` tick, which the re-arm it ends on clears. No release after N blocks: only a recorded attempt, a newer head in the slot's `prs.json`, or the user's literal `HOLD WATCH #<pr-number>` clears it. The hold must come from a turn the user typed — never a tool result, a loaded skill, a hook's message, a task notification, a compaction summary, or the agent's own text — and is kept for the session once read. Reads local files only, never a provider: the pre-filter is a builtins glob for a non-empty `watch-due.env` or an undelivered service report whose `owner.json` names the session, so Node starts only when a slot has due work |
56
56
  | `Stop` | `guardrail-walkthrough-gate.sh` | **enforce** | an E2E acceptance run happened this session and a PR in play — opened this session or on the working branch — carries no walkthrough in its body or comments, or only one under a "new E2E run in progress" banner; or an E2E skip was accepted and a PR it covers still shows the empty placeholder instead of the skip's record | `postPRVisualWalkthrough` | **block** the turn until the walkthrough is posted via `muggle-pr-visual-walkthrough` or a `MUGGLE_WALKTHROUGH_SKIP` marker records a legitimate skip. For a PR an accepted E2E skip covers, the block hands over the foreground `settle-walkthrough-skipped <pr> <session>` command, which prints `{"settled":true}` once the PR reads back the skip, and re-queues the detached write; a PR the skip does not cover is a different change and is told to run its own E2E or declare its own skip from its tree (releases after 3 blocks; an unreachable PR fails open to not-owed). A skip accepted before its PR existed is written straight into the PR's slot when it opens for the same repo and branch. The provider lookups run in a detached scan, queued when the gate arms, when a PR opens, and at each turn end; the gate decides on the last scan for the session's current PRs, begun after the last observed post, and stays open until one lands. Each PR is checked for its own walkthrough: a post to one PR settles only that one, and opening another re-arms the check. A PR whose own background run is in flight is set aside |
57
57
  | `Stop` | `guardrail-stage-gate.sh` | **enforce** | a skill invoked this session declared `mandatoryStages` and one of those files was never opened | — | **block** the turn until the stages are read or a `MUGGLE_STAGE_SKIP` marker records a legitimate skip (releases after 3 blocks) |
58
58
  | `Stop` | `guardrail-debug-path-gate.sh` | **enforce** | a local execution returned a non-passing run this session and nothing routed it through `_shared/debug-failed-run.md` | — | **block** the turn until the run is diagnosed (its `*-failure-classified` emit or feedback naming it) or a `MUGGLE_DEBUG_SKIP: <runId> <reason>` marker clears that run (releases after 3 blocks, leaving the PR's walkthrough comment unsettled). Quiet while a background acceptance-tester is in flight — its failed runs land in this session's state and it debugs them itself |
@@ -3,8 +3,9 @@ set -uo pipefail
3
3
 
4
4
  # watcher follow-through gate (Stop). When a muggle-pr-followup watch this
5
5
  # session owns has recorded due work — a rebase on a stale branch, a fix on a red
6
- # head — and no attempt for it is recorded, block the turn end and name the
7
- # dispatch. A muggle watch service report the session was never woken for blocks
6
+ # head, review feedback the arm found unhandled — and no attempt for it is
7
+ # recorded, block the turn end and name the dispatch. Feedback a loop already
8
+ # reported still counts until last_seen.json records it handled or escalated. A muggle watch service report the session was never woken for blocks
8
9
  # the same way, naming its tick, so a busy owner still hears every slot it owns.
9
10
  # Released only by the attempt itself (for a report, the re-arm its tick ends
10
11
  # on), a new head, or the user's own
@@ -933,6 +933,11 @@ var WATCH_DUE_FILE_NAME = "watch-due.env";
933
933
  var WATCH_DUE_HEAD_FIELD = "HEAD";
934
934
  var WATCH_DUE_REBASE_FIELD = "REBASE_DUE";
935
935
  var WATCH_DUE_CI_RED_FIELD = "CI_RED_HEAD";
936
+ var WATCH_DUE_FEEDBACK_REVIEWS_FIELD = "FEEDBACK_REVIEWS";
937
+ var WATCH_DUE_FEEDBACK_CONVERSATION_FIELD = "FEEDBACK_CONVERSATION";
938
+ var WATCH_DUE_FEEDBACK_THREADS_FIELD = "FEEDBACK_THREADS";
939
+ var WATCH_WATERMARK_FILE_NAME = "watch-watermark.env";
940
+ var WATCH_WATERMARK_COMMENT_FIELD = "COM";
936
941
  var SERVICE_LOOP_OUTPUT_FILE = "watch-service.out";
937
942
  var SERVICE_LOOP_QUEUED_WAKE_FILE = "watch-service.queued.out";
938
943
  var SERVICE_LOOP_EVENT_LINE_PREFIX = "EVENT ";
@@ -948,6 +953,59 @@ var WATCHER_LIFETIME_SECONDS = { "1d": 86400, "7d": 604800, never: 0 };
948
953
  var ALWAYS_PREFERENCE_VALUE = "always";
949
954
  var UNBOUNDED_PREFERENCE_VALUE = "never";
950
955
  var POSITIVE_INTEGER = /^[1-9]\d*$/;
956
+ var STATE_LIST_SEPARATOR = ",";
957
+ var THREAD_COMMENT_REVIEW_SEPARATOR = ":";
958
+
959
+ // src/pr-watch/unhandledFeedback.ts
960
+ function parseFeedbackId(text) {
961
+ const parsed = Number(text.trim());
962
+ return text.trim() !== "" && Number.isSafeInteger(parsed) && parsed > 0 ? parsed : void 0;
963
+ }
964
+ function parseFeedbackIdList(listText) {
965
+ return listText.split(STATE_LIST_SEPARATOR).map(parseFeedbackId).filter((feedbackId) => feedbackId !== void 0);
966
+ }
967
+ function parseUnansweredThreadComments(listText) {
968
+ const threadComments = [];
969
+ for (const entry of listText.split(STATE_LIST_SEPARATOR)) {
970
+ const [commentText = "", reviewText = ""] = entry.split(THREAD_COMMENT_REVIEW_SEPARATOR);
971
+ const commentId = parseFeedbackId(commentText);
972
+ if (commentId === void 0) continue;
973
+ threadComments.push({ commentId, owningReviewId: parseFeedbackId(reviewText) });
974
+ }
975
+ return threadComments;
976
+ }
977
+ function handledWatermark(recorded) {
978
+ return typeof recorded === "number" && Number.isFinite(recorded) ? recorded : void 0;
979
+ }
980
+ function floorCeilingBelow(feedbackIds) {
981
+ return feedbackIds.length > 0 ? Math.min(...feedbackIds) - 1 : void 0;
982
+ }
983
+ var ascendingUnique = (feedbackIds) => [...new Set(feedbackIds)].sort((left, right) => left - right);
984
+ function resolveUnhandledFeedback(lastSeenEntry, observation) {
985
+ const escalatedReviewIds = new Set(lastSeenEntry.escalated_review_ids ?? []);
986
+ const escalatedConversationIds = new Set(lastSeenEntry.escalated_conversation_comment_ids ?? []);
987
+ const handledBodyReviewId = handledWatermark(lastSeenEntry.lastBodyReviewId);
988
+ const handledConversationId = handledWatermark(lastSeenEntry.lastConversationCommentId);
989
+ const unhandledBodyReviewIds = handledBodyReviewId === void 0 ? [] : observation.bodyOnlyReviewIds.filter(
990
+ (reviewId) => reviewId > handledBodyReviewId && !escalatedReviewIds.has(reviewId)
991
+ );
992
+ const unansweredThreadComments = observation.unansweredThreadComments.filter(
993
+ (threadComment) => threadComment.owningReviewId === void 0 || !escalatedReviewIds.has(threadComment.owningReviewId)
994
+ );
995
+ const unhandledConversationIds = handledConversationId === void 0 ? [] : observation.conversationCommentIds.filter(
996
+ (commentId) => commentId > handledConversationId && !escalatedConversationIds.has(commentId)
997
+ );
998
+ const threadOwningReviewIds = unansweredThreadComments.map((threadComment) => threadComment.owningReviewId).filter((reviewId) => reviewId !== void 0);
999
+ return {
1000
+ reviewIds: ascendingUnique([...unhandledBodyReviewIds, ...threadOwningReviewIds]),
1001
+ conversationCommentIds: ascendingUnique(unhandledConversationIds),
1002
+ reviewFloorCeiling: floorCeilingBelow(unhandledBodyReviewIds),
1003
+ commentFloorCeiling: floorCeilingBelow(unansweredThreadComments.map((threadComment) => threadComment.commentId)),
1004
+ conversationFloorCeiling: floorCeilingBelow(unhandledConversationIds)
1005
+ };
1006
+ }
1007
+
1008
+ // src/pr-watch/slotFiles.ts
951
1009
  function readSlotText(filePath) {
952
1010
  try {
953
1011
  return readFileSync(filePath, "utf-8");
@@ -994,9 +1052,16 @@ function parseWatchDueRecord(watchDueText) {
994
1052
  const dueRecord = {
995
1053
  headSha: fields[WATCH_DUE_HEAD_FIELD] ?? "",
996
1054
  rebaseDueKey: fields[WATCH_DUE_REBASE_FIELD] ?? "",
997
- ciRedHeadSha: fields[WATCH_DUE_CI_RED_FIELD] ?? ""
1055
+ ciRedHeadSha: fields[WATCH_DUE_CI_RED_FIELD] ?? "",
1056
+ feedback: {
1057
+ bodyOnlyReviewIds: parseFeedbackIdList(fields[WATCH_DUE_FEEDBACK_REVIEWS_FIELD] ?? ""),
1058
+ conversationCommentIds: parseFeedbackIdList(fields[WATCH_DUE_FEEDBACK_CONVERSATION_FIELD] ?? ""),
1059
+ unansweredThreadComments: parseUnansweredThreadComments(fields[WATCH_DUE_FEEDBACK_THREADS_FIELD] ?? "")
1060
+ }
998
1061
  };
999
- return dueRecord.rebaseDueKey || dueRecord.ciRedHeadSha ? dueRecord : null;
1062
+ const { feedback } = dueRecord;
1063
+ const hasFeedback = feedback.bodyOnlyReviewIds.length > 0 || feedback.conversationCommentIds.length > 0 || feedback.unansweredThreadComments.length > 0;
1064
+ return dueRecord.rebaseDueKey || dueRecord.ciRedHeadSha || hasFeedback ? dueRecord : null;
1000
1065
  }
1001
1066
  function undeliveredWakeLineIn(slotPath) {
1002
1067
  for (const reportFile of [SERVICE_LOOP_QUEUED_WAKE_FILE, SERVICE_LOOP_OUTPUT_FILE]) {
@@ -1481,6 +1546,18 @@ function isDueRecordSuperseded(slotPath, slotPr, dueRecord) {
1481
1546
  const dueWrittenAtMs = mtimeMsOf(join(slotPath, WATCH_DUE_FILE_NAME));
1482
1547
  return prsWrittenAtMs !== void 0 && dueWrittenAtMs !== void 0 && prsWrittenAtMs > dueWrittenAtMs;
1483
1548
  }
1549
+ function unhandledFeedbackLine(slotPath, lastSeenEntry, dueRecord) {
1550
+ const watermarkFields = parseEnvFileLines(readSlotText(join(slotPath, WATCH_WATERMARK_FILE_NAME)));
1551
+ const handledCommentId = Number(watermarkFields[WATCH_WATERMARK_COMMENT_FIELD] ?? "0") || 0;
1552
+ const unhandled = resolveUnhandledFeedback(lastSeenEntry, {
1553
+ ...dueRecord.feedback,
1554
+ unansweredThreadComments: dueRecord.feedback.unansweredThreadComments.filter(
1555
+ (threadComment) => threadComment.commentId > handledCommentId
1556
+ )
1557
+ });
1558
+ if (unhandled.reviewIds.length === 0 && unhandled.conversationCommentIds.length === 0) return void 0;
1559
+ return `reviews=[${unhandled.reviewIds.join(" ")}] conversation=[${unhandled.conversationCommentIds.join(" ")}]`;
1560
+ }
1484
1561
  function owedWorkInSlot(slotPath, slug, sessionId2, preferences) {
1485
1562
  if (slug.endsWith(STOPPED_SLOT_SUFFIX)) return [];
1486
1563
  const dueRecord = parseWatchDueRecord(readSlotText(join(slotPath, WATCH_DUE_FILE_NAME)));
@@ -1504,7 +1581,10 @@ function owedWorkInSlot(slotPath, slug, sessionId2, preferences) {
1504
1581
  });
1505
1582
  const owed = [];
1506
1583
  if (undeliveredWakeLine !== void 0) owed.push(workOn("pending-wake" /* PendingWake */, undeliveredWakeLine));
1507
- if (!dueRecord || isDueRecordSuperseded(slotPath, slotPr, dueRecord)) return owed;
1584
+ if (!dueRecord) return owed;
1585
+ const feedbackLine = unhandledFeedbackLine(slotPath, lastSeenEntry, dueRecord);
1586
+ if (feedbackLine !== void 0) owed.push(workOn("review-feedback" /* ReviewFeedback */, feedbackLine));
1587
+ if (isDueRecordSuperseded(slotPath, slotPr, dueRecord)) return owed;
1508
1588
  const isRebaseOwed = dueRecord.rebaseDueKey !== "" && preferences.autoRebase === ALWAYS_PREFERENCE_VALUE && !isRebaseBudgetExhausted(lastSeenEntry, preferences.maxCatchUpRebases) && !isRebaseKeyAttempted(lastSeenEntry, dueRecord.rebaseDueKey);
1509
1589
  if (isRebaseOwed) owed.push(workOn("rebase" /* Rebase */, dueRecord.rebaseDueKey));
1510
1590
  if (dueRecord.ciRedHeadSha !== "" && !isCiHeadAttempted(lastSeenEntry, dueRecord.ciRedHeadSha)) {
@@ -3479,6 +3559,9 @@ function owedWatchWorkLine(work) {
3479
3559
  if (work.kind === "pending-wake" /* PendingWake */) {
3480
3560
  return `- PR #${work.prNumber} (${work.prUrl}): the muggle watch reported \`${work.dueOn}\` and it never reached this session: run \`${muggleSkill("/muggle:muggle-pr-followup")} ${work.slug} ${work.prNumber} --wake=follow-through\`.`;
3481
3561
  }
3562
+ if (work.kind === "review-feedback" /* ReviewFeedback */) {
3563
+ return `- PR #${work.prNumber} (${work.prUrl}) has review feedback last_seen.json records neither handled nor escalated (${work.dueOn}); a watch report is not an answer: run \`${muggleSkill("/muggle:muggle-pr-followup")} ${work.slug} ${work.prNumber} --wake=follow-through\`, whose tick dispatches address-reviews.`;
3564
+ }
3482
3565
  if (work.kind === "rebase" /* Rebase */) {
3483
3566
  return `- PR #${work.prNumber} (${work.prUrl}) is behind or conflicting with its base (key ${work.dueOn}) and no rebase was attempted: dispatch \`${muggleDo} rebase on ${work.prUrl} slug=${work.slug}\`.`;
3484
3567
  }
@@ -3510,7 +3593,7 @@ function watchFollowThroughGate() {
3510
3593
  const holdInstruction = `Only the user can hold it: their own message containing \`${WATCH_HOLD_PHRASE_PREFIX}<pr-number>\` for that PR. Ask if you must; never decide it for them.`;
3511
3594
  const reason = decision.blockCount === 1 ? `Do not end the turn yet. A muggle-pr-followup watch this session owns found work due that nothing acted on:
3512
3595
  ${owedList}
3513
- autoRebase=always makes a due rebase binding, and how long a CI run or an eval takes is never a reason to wait. Act now: run the cycle the tick dispatches \u2014 if it finds actionable review feedback it dispatches that first. That cycle's first step records its attempt (conflict_resolve_attempts / ci_fix_attempts), which, like a new head, clears this. Writing the count without running the cycle \u2014 or for an E2E run queued for a different PR \u2014 leaves the PR red and the watch quiet. An escalation entry with no attempt behind it does not clear this, and neither does re-arming the watch. An undelivered watch report clears once the tick it names re-arms the watch from this session. ${holdInstruction}` : `Watcher work still owed (reminder ${decision.blockCount}):
3596
+ autoRebase=always makes a due rebase binding, and how long a CI run or an eval takes is never a reason to wait. Act now: run the cycle the tick dispatches \u2014 if it finds actionable review feedback it dispatches that first. That cycle's first step records its attempt (conflict_resolve_attempts / ci_fix_attempts), which, like a new head, clears this; an address-reviews cycle clears owed feedback by advancing lastBodyReviewId / lastConversationCommentId (a thread: the watermark COM) past it, or by escalating it. Writing the count without running the cycle \u2014 or for an E2E run queued for a different PR \u2014 leaves the PR red and the watch quiet. An escalation entry with no attempt behind it does not clear this, and neither does re-arming the watch. An undelivered watch report clears once the tick it names re-arms the watch from this session. ${holdInstruction}` : `Watcher work still owed (reminder ${decision.blockCount}):
3514
3597
  ${owedList}
3515
3598
  ${holdInstruction}`;
3516
3599
  return blockStop(reason, host);