@muggleai/works 5.36.0 → 5.37.0-staging.340

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 +2 -2
  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
@@ -13,6 +13,13 @@
13
13
  # seen without ever being reported. A re-arm keeps the review, comment and thread
14
14
  # floors the session already holds, for the same reason.
15
15
  #
16
+ # Neither may sit above feedback nobody handled. The read's own ids are not the
17
+ # handled ones: a comment posted before the slot was bootstrapped is in the read,
18
+ # so a first arm floored it, and the loop never reported it while it reported
19
+ # every rebase and red check after it. Each floor is capped just below the
20
+ # lowest feedback last_seen.json does not record as handled or escalated, and
21
+ # the drain names that feedback first, since reviews preempt CI and rebase.
22
+ #
16
23
  # A stale branch is floored only when the slot proves a rebase ran for it, and a
17
24
  # red head only once fix-ci is finished with it — escalated, or out of attempts.
18
25
  # Flooring whatever was outstanding at arm time let a session that never rebased
@@ -82,6 +89,9 @@ pending_checks="${STATE_FIELDS[7]-}"
82
89
  failed_checks="${STATE_FIELDS[8]-}"
83
90
  ci_red_key="$(watch_ci_red_key "$head_sha" "${STATE_FIELDS[10]-}")"
84
91
  latest_conversation="${STATE_FIELDS[11]-}"
92
+ body_only_review_ids="${STATE_FIELDS[12]-}"
93
+ conversation_comment_ids="${STATE_FIELDS[13]-}"
94
+ unanswered_thread_comments="${STATE_FIELDS[14]-}"
85
95
 
86
96
  if [ "$pr_state" = "MERGED" ] || [ "$pr_state" = "CLOSED" ]; then
87
97
  echo "TERMINAL pr=$pr_number state=$pr_state — nothing to arm"
@@ -114,6 +124,11 @@ rebase_attempted=0
114
124
  ci_settled=0
115
125
  blocked_digest_floor=""
116
126
  rebase_budget_exhausted=0
127
+ unhandled_review_ids=""
128
+ unhandled_conversation_ids=""
129
+ review_floor_ceiling=""
130
+ comment_floor_ceiling=""
131
+ conversation_floor_ceiling=""
117
132
  while IFS= read -r evidence_line; do
118
133
  evidence_line="${evidence_line%$'\r'}"
119
134
  case "$evidence_line" in
@@ -121,9 +136,23 @@ while IFS= read -r evidence_line; do
121
136
  CI_SETTLED=*) ci_settled="${evidence_line#CI_SETTLED=}" ;;
122
137
  BLOCKED_CIDIGEST=*) blocked_digest_floor="${evidence_line#BLOCKED_CIDIGEST=}" ;;
123
138
  REBASE_BUDGET_EXHAUSTED=*) rebase_budget_exhausted="${evidence_line#REBASE_BUDGET_EXHAUSTED=}" ;;
139
+ UNHANDLED_REVIEW_IDS=*) unhandled_review_ids="${evidence_line#UNHANDLED_REVIEW_IDS=}" ;;
140
+ UNHANDLED_CONVERSATION_IDS=*) unhandled_conversation_ids="${evidence_line#UNHANDLED_CONVERSATION_IDS=}" ;;
141
+ REVIEW_FLOOR_CEILING=*) review_floor_ceiling="${evidence_line#REVIEW_FLOOR_CEILING=}" ;;
142
+ COMMENT_FLOOR_CEILING=*) comment_floor_ceiling="${evidence_line#COMMENT_FLOOR_CEILING=}" ;;
143
+ CONVERSATION_FLOOR_CEILING=*) conversation_floor_ceiling="${evidence_line#CONVERSATION_FLOOR_CEILING=}" ;;
124
144
  esac
125
145
  done < <(node "${script_dir}/pr-watch-verdict.mjs" arm-floors --pr-key "${repo}#${pr_number}" \
126
- --head "$head_sha" --rebase-key "$rebase_key" < "$last_seen_file" 2>/dev/null)
146
+ --head "$head_sha" --rebase-key "$rebase_key" \
147
+ --body-reviews "$body_only_review_ids" --conversation-comments "$conversation_comment_ids" \
148
+ --unanswered-threads "$unanswered_thread_comments" < "$last_seen_file" 2>/dev/null)
149
+
150
+ has_unhandled_feedback=""
151
+ if [ -n "$unhandled_review_ids" ] || [ -n "$unhandled_conversation_ids" ]; then
152
+ has_unhandled_feedback=1
153
+ fi
154
+ after_feedback=""
155
+ [ -n "$has_unhandled_feedback" ] && after_feedback=" after address-reviews"
127
156
 
128
157
  ci_red_floor=""
129
158
  [ -n "$ci_red_head" ] && [ "$ci_settled" = "1" ] && ci_red_floor="$ci_red_key"
@@ -149,11 +178,14 @@ thread_count=0
149
178
  echo "DRAIN pr=$pr_number state=$pr_state head=${head_sha:0:8}"
150
179
  echo "DRAIN unresolved-threads=$thread_count latest-review=${latest_review:-0} latest-comment=${latest_comment:-0} latest-conversation-comment=${latest_conversation:-0}"
151
180
  echo "DRAIN checks pending=${pending_checks:-0} failed=${failed_checks:-0} behind-base=${behind_count:-unknown} mergeable=${mergeable:-UNKNOWN}"
181
+ if [ -n "$has_unhandled_feedback" ]; then
182
+ echo "DRAIN review feedback unhandled at arm time — reviews=[${unhandled_review_ids}] conversation=[${unhandled_conversation_ids}] not recorded handled in last_seen.json, not floored: dispatch address-reviews"
183
+ fi
152
184
  if [ -n "$ci_red_head" ]; then
153
185
  if [ -n "$ci_red_floor" ]; then
154
186
  echo "DRAIN ci red at arm time — fix-ci escalated or spent its attempts on head ${head_sha:0:8}, floored"
155
187
  else
156
- echo "DRAIN ci red at arm time — fix-ci not finished with head ${head_sha:0:8}, not floored: dispatch fix-ci"
188
+ echo "DRAIN ci red at arm time — fix-ci not finished with head ${head_sha:0:8}, not floored: dispatch fix-ci${after_feedback}"
157
189
  fi
158
190
  fi
159
191
  if [ -n "$rebase_due_key" ]; then
@@ -162,7 +194,7 @@ if [ -n "$rebase_due_key" ]; then
162
194
  elif [ -n "$rebase_floor" ]; then
163
195
  echo "DRAIN branch stale at arm time — a rebase already ran for key ${rebase_due_key}, floored"
164
196
  else
165
- echo "DRAIN branch stale at arm time — no rebase attempt recorded for key ${rebase_due_key}, not floored: dispatch rebase"
197
+ echo "DRAIN branch stale at arm time — no rebase attempt recorded for key ${rebase_due_key}, not floored: dispatch rebase${after_feedback}"
166
198
  fi
167
199
  fi
168
200
 
@@ -187,6 +219,15 @@ if [ -f "${slot}/watch-watermark.env" ]; then
187
219
  "$(watch_read_slot_value "$slot" watch-watermark.env THREADS)" "$unresolved_threads")"
188
220
  fi
189
221
 
222
+ # Prints `floor`, lowered to `ceiling` when one is set and is lower.
223
+ floor_capped_at() {
224
+ local floor="${1:-0}" ceiling="$2"
225
+ if [ -n "$ceiling" ] && [ "$ceiling" -lt "$floor" ] 2>/dev/null; then printf '%s' "$ceiling"; else printf '%s' "$floor"; fi
226
+ }
227
+ review_floor="$(floor_capped_at "$review_floor" "$review_floor_ceiling")"
228
+ comment_floor="$(floor_capped_at "$comment_floor" "$comment_floor_ceiling")"
229
+ conversation_floor="$(floor_capped_at "$conversation_floor" "$conversation_floor_ceiling")"
230
+
190
231
  {
191
232
  printf 'REV=%s\n' "${review_floor:-0}"
192
233
  printf 'COM=%s\n' "${comment_floor:-0}"
@@ -198,7 +239,37 @@ fi
198
239
  printf 'REBASE_HELD="%s"\n' "$rebase_held"
199
240
  } > "${slot}/watch-watermark.env"
200
241
 
201
- watch_record_due_work "$slot" "$head_sha" "$recorded_rebase_due_key" "$ci_red_head"
242
+ # The loop fires only above both this watermark and watch-reported.env, so a
243
+ # reported floor past the same feedback silences it just as surely: a loop that
244
+ # once reported a comment nobody answered left the next loop quiet on it, and
245
+ # only the drain line, which a busy session reads past, still named it. Being
246
+ # reported is not being handled, so the reported floors are capped the same way.
247
+ # A service arm over a report still queued for the owner leaves them: that
248
+ # report already wakes the owner, and repeating it each service tick would only
249
+ # churn the loop.
250
+ if [ -f "${slot}/${MUGGLE_PR_WATCH_REPORTED_FILE}" ] && [ -n "$has_unhandled_feedback" ] \
251
+ && ! { [ -n "${MUGGLE_PR_WATCH_LISTENER:-}" ] && [ -s "${slot}/watch-service.queued.out" ]; }; then
252
+ watch_record_reported "$slot" \
253
+ "$(floor_capped_at "$(watch_read_slot_value "$slot" "$MUGGLE_PR_WATCH_REPORTED_FILE" REV)" "$review_floor_ceiling")" \
254
+ "$(floor_capped_at "$(watch_read_slot_value "$slot" "$MUGGLE_PR_WATCH_REPORTED_FILE" COM)" "$comment_floor_ceiling")" \
255
+ "$(floor_capped_at "$(watch_read_slot_value "$slot" "$MUGGLE_PR_WATCH_REPORTED_FILE" CONV)" "$conversation_floor_ceiling")" \
256
+ "$(watch_read_slot_value "$slot" "$MUGGLE_PR_WATCH_REPORTED_FILE" THREADS)" \
257
+ "$(watch_read_slot_value "$slot" "$MUGGLE_PR_WATCH_REPORTED_FILE" CIRED)" \
258
+ "$(watch_read_slot_value "$slot" "$MUGGLE_PR_WATCH_REPORTED_FILE" REBASED)" \
259
+ "$(watch_read_slot_value "$slot" "$MUGGLE_PR_WATCH_REPORTED_FILE" BLOCKED_CIDIGEST)" \
260
+ "$(watch_read_slot_value "$slot" "$MUGGLE_PR_WATCH_REPORTED_FILE" BLOCKED_FOR)"
261
+ fi
262
+
263
+ # Unhandled feedback goes on the due record with the arm read's lists, so the
264
+ # turn-end gate keeps it owed until last_seen.json records it handled.
265
+ due_feedback_reviews="" due_feedback_conversation="" due_feedback_threads=""
266
+ if [ -n "$has_unhandled_feedback" ]; then
267
+ due_feedback_reviews="$body_only_review_ids"
268
+ due_feedback_conversation="$conversation_comment_ids"
269
+ due_feedback_threads="$unanswered_thread_comments"
270
+ fi
271
+ watch_record_due_work "$slot" "$head_sha" "$recorded_rebase_due_key" "$ci_red_head" \
272
+ "$due_feedback_reviews" "$due_feedback_conversation" "$due_feedback_threads"
202
273
 
203
274
  # Claim the slot for its owner: the session --owner names, else this session.
204
275
  # The muggle watch service arms outside every session, so it passes the owner
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env bash
2
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.
3
+ # Records the work a watch has seen due on its PR — review feedback nobody
4
+ # handled, a rebase or red CI — so the owning session's turn-end gate can tell
5
+ # an event it acted on from one it sat on. Sourced by pr-watch-arm.sh and
6
+ # pr-watch-loop.sh.
6
7
  #
7
8
  # The gate runs in a Stop hook with about a second to answer and no network, so
8
9
  # it cannot ask the provider what is due; it reads this file and the slot's
@@ -18,14 +19,22 @@ MUGGLE_PR_WATCH_DUE_FILE="watch-due.env"
18
19
 
19
20
  # Writes <slot>/watch-due.env: the head the observation was made on, the
20
21
  # `<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.
22
+ # current), the head whose checks settled red (empty otherwise), and — only
23
+ # when the arm found feedback unhandled — the arm read's feedback lists in the
24
+ # state projection's spelling: body-only review ids, conversation comment ids,
25
+ # and unanswered threads as `<comment>:<review>`. A loop reporting that
26
+ # feedback does not handle it, so the gate judges the lists against
27
+ # last_seen.json rather than against what was reported. Builtins only, since
28
+ # the loop writes it every time what is due changes.
23
29
  watch_record_due_work() {
24
30
  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
31
+ local feedback_reviews="${5-}" feedback_conversation="${6-}" feedback_threads="${7-}"
32
+ if [ -z "$rebase_due_key" ] && [ -z "$ci_red_head" ] && [ -z "$feedback_reviews" ] \
33
+ && [ -z "$feedback_conversation" ] && [ -z "$feedback_threads" ]; then
26
34
  : > "${slot}/${MUGGLE_PR_WATCH_DUE_FILE}"
27
35
  return 0
28
36
  fi
29
- printf 'HEAD="%s"\nREBASE_DUE="%s"\nCI_RED_HEAD="%s"\n' "$head_sha" "$rebase_due_key" "$ci_red_head" \
37
+ printf 'HEAD="%s"\nREBASE_DUE="%s"\nCI_RED_HEAD="%s"\nFEEDBACK_REVIEWS="%s"\nFEEDBACK_CONVERSATION="%s"\nFEEDBACK_THREADS="%s"\n' \
38
+ "$head_sha" "$rebase_due_key" "$ci_red_head" "$feedback_reviews" "$feedback_conversation" "$feedback_threads" \
30
39
  > "${slot}/${MUGGLE_PR_WATCH_DUE_FILE}"
31
40
  }
@@ -33,7 +33,7 @@ query($owner: String!, $name: String!, $number: Int!) {
33
33
  }
34
34
  }
35
35
  }
36
- reviews(last: 20, states: [COMMENTED, APPROVED, CHANGES_REQUESTED, DISMISSED]) { nodes { databaseId body } }
36
+ reviews(last: 20, states: [COMMENTED, APPROVED, CHANGES_REQUESTED, DISMISSED]) { nodes { databaseId body state comments { totalCount } } }
37
37
  reviewThreads(first: 100) {
38
38
  nodes {
39
39
  id
@@ -79,6 +79,12 @@ has_iterated=""
79
79
  # work changes rather than every poll.
80
80
  due_rebase_key=""
81
81
  recorded_due_work="unrecorded"
82
+ # The feedback the arm recorded due. The loop has no last_seen.json to judge it
83
+ # against, and reporting it does not handle it, so every rewrite carries it on
84
+ # until the next arm reads it handled.
85
+ due_feedback_reviews="$(watch_read_slot_value "$slot" "$MUGGLE_PR_WATCH_DUE_FILE" FEEDBACK_REVIEWS)"
86
+ due_feedback_conversation="$(watch_read_slot_value "$slot" "$MUGGLE_PR_WATCH_DUE_FILE" FEEDBACK_CONVERSATION)"
87
+ due_feedback_threads="$(watch_read_slot_value "$slot" "$MUGGLE_PR_WATCH_DUE_FILE" FEEDBACK_THREADS)"
82
88
 
83
89
  # Pin the token once: a detached loop can lose access to gh's OS keyring
84
90
  # mid-run, which surfaces as empty fetches rather than an error.
@@ -263,7 +269,8 @@ while :; do
263
269
  watch_checks_settled_red "$pending_checks" "$failed_checks" && ci_red_head="$head_sha"
264
270
  due_work="${head_sha} ${due_rebase_key} ${ci_red_head}"
265
271
  if [ "$due_work" != "$recorded_due_work" ]; then
266
- watch_record_due_work "$slot" "$head_sha" "$due_rebase_key" "$ci_red_head"
272
+ watch_record_due_work "$slot" "$head_sha" "$due_rebase_key" "$ci_red_head" \
273
+ "$due_feedback_reviews" "$due_feedback_conversation" "$due_feedback_threads"
267
274
  recorded_due_work="$due_work"
268
275
  fi
269
276
 
@@ -6,7 +6,8 @@
6
6
  # Field order is the contract pr-watch-loop.sh reads positionally:
7
7
  # state, headRefOid, base-tip, mergeable, latest-review, latest-comment,
8
8
  # unresolved-thread-ids, pending-checks, failed-checks, check-digest,
9
- # red-check-runs, latest-conversation-comment
9
+ # red-check-runs, latest-conversation-comment, body-only-review-ids,
10
+ # conversation-comment-ids, unanswered-thread-comments
10
11
  #
11
12
  # red-check-runs names each failed check with its run id (`name#id`, sorted).
12
13
  # A settle, a rerun or a comment-triggered re-check publishes a new run on the
@@ -21,7 +22,18 @@
21
22
  # an empty field rather than a missing one, so no later field shifts.
22
23
  #
23
24
  # latest-conversation-comment is the newest top-level PR comment (the
24
- # Conversation tab) a human wrote. Last, so every earlier reader keeps its index.
25
+ # Conversation tab) a human wrote.
26
+ #
27
+ # The last three fields list, rather than take the maximum of, the feedback the
28
+ # arm step checks against what last_seen.json records as handled: one escalated
29
+ # id above the handled watermark must not hide an unhandled one below it.
30
+ # body-only-review-ids — submitted reviews with a body and no line comments,
31
+ # comma-joined: the reviews the tick dispatches against lastBodyReviewId.
32
+ # conversation-comment-ids — the ids latest-conversation-comment ranges over.
33
+ # unanswered-thread-comments — `<newest-comment-id>:<owning-review-id>` for
34
+ # each unresolved thread, outdated or not, whose newest comment muggle did
35
+ # not post: the threads the tick finds actionable.
36
+ # Appended after every earlier field, so each earlier reader keeps its index.
25
37
 
26
38
  def loop_marked: ((.body // "") | contains("<!-- muggle-do:bot -->"));
27
39
 
@@ -67,15 +79,23 @@ def bot_authored:
67
79
  # it answers a comment, and the tick it triggers can only idle.
68
80
  | ($liveComments | map(select(loop_marked) | .pullRequestReview.databaseId | values)) as $loopOwnedReviews
69
81
  | ($liveComments | map(select(loop_marked | not) | .pullRequestReview.databaseId | values)) as $humanOwnedReviews
82
+ | def is_body_only_review:
83
+ ((.comments.totalCount // 0) == 0)
84
+ and ((.state // "") != "DISMISSED")
85
+ and ((.body // "") | test("\\S"))
86
+ and (muggle_posted | not);
70
87
  # `index` evaluates its argument against the array it is indexing, so the review
71
88
  # has to be bound before either membership test can name its id.
72
- | def is_echo_review:
89
+ def is_echo_review:
73
90
  . as $review
74
91
  | ((($review.body // "") == "") or ($review | loop_marked))
75
92
  and (($loopOwnedReviews | index($review.databaseId)) != null)
76
93
  and (($humanOwnedReviews | index($review.databaseId)) == null);
77
94
 
78
- [
95
+ (($pr.comments.nodes // []) | map(select((muggle_posted | not) and (bot_authored | not)) | .databaseId))
96
+ as $humanConversationIds
97
+
98
+ | [
79
99
  $pr.state,
80
100
  $pr.headRefOid,
81
101
  ($pr.baseRef.target.oid // ""),
@@ -88,5 +108,10 @@ def bot_authored:
88
108
  ($failedChecks | length),
89
109
  ($checks | sort_by(.name) | map(.name + ":" + .verdict) | join(",")),
90
110
  ($failedChecks | map(.name + "#" + (.runId | tostring)) | sort | join(",")),
91
- ((($pr.comments.nodes // []) | map(select((muggle_posted | not) and (bot_authored | not)) | .databaseId) | max) // 0)
111
+ ($humanConversationIds | max // 0),
112
+ ([$pr.reviews.nodes[] | select(is_body_only_review) | .databaseId] | sort | map(tostring) | join(",")),
113
+ ($humanConversationIds | sort | map(tostring) | join(",")),
114
+ ([$pr.reviewThreads.nodes[] | select(.isResolved == false) | .comments.nodes[-1] // empty
115
+ | select((.pullRequestReview.state // "SUBMITTED") != "PENDING") | select(muggle_posted | not)
116
+ | "\(.databaseId):\(.pullRequestReview.databaseId // "")"] | join(","))
92
117
  ] | @tsv
@@ -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
 
File without changes