@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
@@ -10,7 +10,7 @@
10
10
  "name": "muggleai",
11
11
  "source": "./plugin",
12
12
  "description": "Acceptance test agent for coding agents: real-browser tests, with screenshots on the PR.",
13
- "version": "5.36.0"
13
+ "version": "5.37.0-staging.340"
14
14
  }
15
15
  ]
16
16
  }
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { runCli } from './chunk-HTCBHSL6.js';
2
+ import { runCli } from './chunk-UWKBSNUQ.js';
3
3
  import './chunk-OIFLV2QN.js';
4
4
 
5
5
  // src/cli/main.ts
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { src_exports as commands, createUnifiedMcpServer, server_exports as server } from './chunk-HTCBHSL6.js';
1
+ export { src_exports as commands, createUnifiedMcpServer, server_exports as server } from './chunk-UWKBSNUQ.js';
2
2
  export { createChildLogger, e2e_exports as e2e, getConfig, getLocalQaTools, getLogger, getQaTools, local_exports as localQa, mcp_exports as mcp, e2e_exports as qa, src_exports as shared } from './chunk-OIFLV2QN.js';
@@ -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.340",
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.340",
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.340",
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.340",
6
6
  "author": {
7
7
  "name": "Muggle AI",
8
8
  "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.340",
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);
@@ -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