@muggleai/works 5.36.0-staging.335 → 5.36.0-staging.337

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 (74) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/AGENTS.md +1 -0
  3. package/README.md +2 -1
  4. package/dist/{chunk-KGTP3CED.js → chunk-HTCBHSL6.js} +132 -40
  5. package/dist/{chunk-5E46QHM6.js → chunk-OIFLV2QN.js} +499 -157
  6. package/dist/cli.js +2 -2
  7. package/dist/index.js +2 -2
  8. package/dist/plugin/.claude-plugin/plugin.json +1 -1
  9. package/dist/plugin/.codex-mcp.json +1 -1
  10. package/dist/plugin/.codex-plugin/plugin.json +1 -1
  11. package/dist/plugin/.cursor-plugin/plugin.json +1 -1
  12. package/dist/plugin/.mcp.json +1 -1
  13. package/dist/plugin/README.md +1 -0
  14. package/dist/plugin/commands/mbugreport.md +7 -0
  15. package/dist/plugin/hooks/README.md +1 -1
  16. package/dist/plugin/scripts/guardrail-watch-follow-through-gate.sh +22 -7
  17. package/dist/plugin/scripts/guardrails.mjs +21 -3
  18. package/dist/plugin/scripts/pr-watch-arm.sh +11 -6
  19. package/dist/plugin/scripts/pr-watch-loop.sh +3 -2
  20. package/dist/plugin/scripts/pr-watch-verdict.mjs +1 -0
  21. package/dist/plugin/skills/CLAUDE.md +1 -1
  22. package/dist/plugin/skills/_aliases.json +2 -1
  23. package/dist/plugin/skills/do/audit-trail.md +1 -1
  24. package/dist/plugin/skills/do/e2e-repair.md +1 -1
  25. package/dist/plugin/skills/do/open-prs/forward.md +17 -15
  26. package/dist/plugin/skills/do/open-prs.md +1 -1
  27. package/dist/plugin/skills/mbugreport/SKILL.md +9 -0
  28. package/dist/plugin/skills/mbugreport/agents/openai.yaml +7 -0
  29. package/dist/plugin/skills/muggle/SKILL.md +1 -0
  30. package/dist/plugin/skills/muggle-bug-report/SKILL.md +37 -0
  31. package/dist/plugin/skills/muggle-bug-report/ops/file.md +68 -0
  32. package/dist/plugin/skills/muggle-bug-report/ops/list.md +30 -0
  33. package/dist/plugin/skills/muggle-bug-report/ops/reply.md +38 -0
  34. package/dist/plugin/skills/muggle-bug-report/ops/status.md +45 -0
  35. package/dist/plugin/skills/muggle-pr-followup/SKILL.md +1 -1
  36. package/dist/plugin/skills/muggle-pr-followup/arm-watcher.md +2 -2
  37. package/dist/plugin/skills/muggle-pr-followup/contract.md +6 -0
  38. package/dist/plugin/skills/muggle-pr-followup/reconcile.md +1 -1
  39. package/dist/plugin/skills/muggle-pr-followup/state-schemas.md +8 -2
  40. package/dist/release-manifest.json +4 -4
  41. package/dist/{src-2OO6JDTQ.js → src-5Z6EIGHT.js} +1 -1
  42. package/package.json +1 -1
  43. package/plugin/.claude-plugin/plugin.json +1 -1
  44. package/plugin/.codex-mcp.json +1 -1
  45. package/plugin/.codex-plugin/plugin.json +1 -1
  46. package/plugin/.cursor-plugin/plugin.json +1 -1
  47. package/plugin/.mcp.json +1 -1
  48. package/plugin/README.md +1 -0
  49. package/plugin/commands/mbugreport.md +7 -0
  50. package/plugin/hooks/README.md +1 -1
  51. package/plugin/scripts/guardrail-watch-follow-through-gate.sh +22 -7
  52. package/plugin/scripts/guardrails.mjs +21 -3
  53. package/plugin/scripts/pr-watch-arm.sh +11 -6
  54. package/plugin/scripts/pr-watch-loop.sh +3 -2
  55. package/plugin/scripts/pr-watch-verdict.mjs +1 -0
  56. package/plugin/skills/CLAUDE.md +1 -1
  57. package/plugin/skills/_aliases.json +2 -1
  58. package/plugin/skills/do/audit-trail.md +1 -1
  59. package/plugin/skills/do/e2e-repair.md +1 -1
  60. package/plugin/skills/do/open-prs/forward.md +17 -15
  61. package/plugin/skills/do/open-prs.md +1 -1
  62. package/plugin/skills/mbugreport/SKILL.md +9 -0
  63. package/plugin/skills/mbugreport/agents/openai.yaml +7 -0
  64. package/plugin/skills/muggle/SKILL.md +1 -0
  65. package/plugin/skills/muggle-bug-report/SKILL.md +37 -0
  66. package/plugin/skills/muggle-bug-report/ops/file.md +68 -0
  67. package/plugin/skills/muggle-bug-report/ops/list.md +30 -0
  68. package/plugin/skills/muggle-bug-report/ops/reply.md +38 -0
  69. package/plugin/skills/muggle-bug-report/ops/status.md +45 -0
  70. package/plugin/skills/muggle-pr-followup/SKILL.md +1 -1
  71. package/plugin/skills/muggle-pr-followup/arm-watcher.md +2 -2
  72. package/plugin/skills/muggle-pr-followup/contract.md +6 -0
  73. package/plugin/skills/muggle-pr-followup/reconcile.md +1 -1
  74. package/plugin/skills/muggle-pr-followup/state-schemas.md +8 -2
@@ -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-staging.335"
13
+ "version": "5.36.0-staging.337"
14
14
  }
15
15
  ]
16
16
  }
package/AGENTS.md CHANGED
@@ -91,6 +91,7 @@ Claude Code: `/muggle:<name>` or the alias. Codex: `$muggle:<name>`. Source: `pl
91
91
  | `muggle-pr-visual-walkthrough` | `/mpr` | Post existing results to a PR |
92
92
  | `muggle-pr-followup` | `/mprfollowup` | Watch a PR and address new review comments, red CI and base drift |
93
93
  | `muggle-feedback` | `/mfeedback` | Flag a generated script or step as wrong so it is regenerated |
94
+ | `muggle-bug-report` | `/mbugreport` | Report a bug in Muggle AI itself, then follow or answer the ticket |
94
95
  | `muggle-run-view` | `/mrun` | Show a local run's steps beside its frames |
95
96
  | `muggle-preferences` | `/mprefs` | View, set or reset preferences |
96
97
  | `muggle-init` | `/minit` | First-time onboarding |
package/README.md CHANGED
@@ -146,6 +146,7 @@ Every skill has a short alias. Both spellings work in Claude Code. In Codex, men
146
146
  | `/muggle:muggle-pr-visual-walkthrough` | `/mpr` | Post screenshots and a pass/fail summary to a PR |
147
147
  | `/muggle:muggle-pr-followup` | `/mprfollowup` | Watch a PR's reviews, CI, and base drift |
148
148
  | `/muggle:muggle-feedback` | `/mfeedback` | Flag a generated script or step as wrong |
149
+ | `/muggle:muggle-bug-report` | `/mbugreport` | Report a bug in Muggle AI and follow the ticket |
149
150
  | `/muggle:muggle-preferences` | `/mprefs` | View, set, or reset preferences |
150
151
  | `/muggle:muggle-status` | `/mstatus` | Health check: runner, MCP server, auth |
151
152
  | `/muggle:muggle-repair` | `/mrepair` | Diagnose and fix a broken install |
@@ -359,7 +360,7 @@ Bulk-preview submissions return a `jobId` immediately. Poll `muggle-remote-bulk-
359
360
 
360
361
  **Reporting** — `muggle-remote-report-stats-summary-get`, `-cost-query`, `-final-generate` (PDF/HTML/Markdown), `-preferences-upsert`.
361
362
 
362
- **Administration** — `muggle-remote-prd-file-*` (upload, list and delete requirements docs), `muggle-remote-secret-*` (credentials for test environments, with `-secret-group-*` and `-secret-type-list`), `muggle-remote-wallet-*` (top-ups, payment methods, auto-topup), `muggle-remote-recommend-cicd-setup` / `-recommend-schedule`, `muggle-remote-user-feedback-*`.
363
+ **Administration** — `muggle-remote-prd-file-*` (upload, list and delete requirements docs), `muggle-remote-secret-*` (credentials for test environments, with `-secret-group-*` and `-secret-type-list`), `muggle-remote-wallet-*` (top-ups, payment methods, auto-topup), `muggle-remote-recommend-cicd-setup` / `-recommend-schedule`, `muggle-remote-user-feedback-*`, `muggle-remote-bug-report-*` (file, list, read and reply to bug reports about Muggle AI, with `muggle-local-bug-report-context-get` gathering the harness context they carry).
363
364
 
364
365
  **Resources** — `muggle://docs/agents` ([AGENTS.md](AGENTS.md)) and `muggle://docs/llms` ([llms.txt](llms.txt)), read from the installed package through `resources/list` and `resources/read`.
365
366
 
@@ -1,10 +1,10 @@
1
- import { __export, getLogger, TelemetryEnvironment, getConfig, createChildLogger, buildElectronAppReleaseAssetUrl, getActiveRuntimeTarget, getAuthService, hasApiKey, getElectronAppVersion, getElectronAppDir, getPlatformKey, reconcileProjectPreferences, getDataDir2, PREFERENCES_FILE_NAME, isFirstRun, writePreferences, DEFAULT_PREFERENCES, isElectronAppInstalled, getElectronAppChecksums, getChecksumForPlatform, getElectronAppSignedFromVersion, getReleaseSignerIdentityUri, verifyFileChecksum, resolveElectronAppExecutablePath, calculateFileChecksum, initTelemetry, Surface, ServiceName, track, EventName, getQaTools, getLocalQaTools, performLogout, assertDeviceCodeClientProvisioned, performLogin, getActiveElectronAppReleaseStream, buildToolInputJsonSchema, toolRequiresAuth, getCallerCredentials, parseElectronAppDirName, getElectronAppReleaseTagPrefix, hasShownDisclosure, markDisclosureShown, getBundledElectronAppVersion, getElectronAppVersionSource, getCredentialsFilePath, ElectronAppReleaseStream, __require, getDisclosureCopy, buildOnboardingPlan, applyOnboardingAnswers, needsOnboarding, buildLlmSourcePlan, describeLlmSourceStatus, resolveLlmSourceStatus, e2e_exports, readRunView, RunViewError, renderRunViewText, writeRunViewHtml, openBrowserUrl, evaluateCheckoutFreshness, runGitCommand, BLOCKING_FRESHNESS_VERDICTS, claimServiceStack, BUSY_EXIT_CODE, checkServiceStack, releaseServiceStack, readServiceStackStatus, resolvePreferences, buildElectronAppChecksumsUrl, OnboardingBlanketChoice, PreferenceKey, LlmSource, applyLlmSourceSelection, describeStackMismatch, ELECTRON_APP_CHECKSUMS_ASSET_NAME, getDataDir, DEFAULT_LOCAL_LLM_BASE_URL, isValidLocalBaseUrl, local_exports } from './chunk-5E46QHM6.js';
1
+ import { __export, getLogger, TelemetryEnvironment, getConfig, createChildLogger, buildElectronAppReleaseAssetUrl, getActiveRuntimeTarget, getAuthService, hasApiKey, getElectronAppVersion, getElectronAppDir, getPlatformKey, reconcileProjectPreferences, getDataDir2, PREFERENCES_FILE_NAME, isFirstRun, writePreferences, DEFAULT_PREFERENCES, isElectronAppInstalled, getElectronAppChecksums, getChecksumForPlatform, getElectronAppSignedFromVersion, getReleaseSignerIdentityUri, verifyFileChecksum, resolveElectronAppExecutablePath, calculateFileChecksum, initTelemetry, Surface, ServiceName, track, EventName, getQaTools, getLocalQaTools, performLogout, assertDeviceCodeClientProvisioned, performLogin, getActiveElectronAppReleaseStream, buildToolInputJsonSchema, toolRequiresAuth, getCallerCredentials, parseElectronAppDirName, getElectronAppReleaseTagPrefix, hasShownDisclosure, markDisclosureShown, getBundledElectronAppVersion, getElectronAppVersionSource, getCredentialsFilePath, ElectronAppReleaseStream, __require, getDisclosureCopy, buildOnboardingPlan, applyOnboardingAnswers, needsOnboarding, buildLlmSourcePlan, describeLlmSourceStatus, resolveLlmSourceStatus, e2e_exports, readRunView, RunViewError, renderRunViewText, writeRunViewHtml, openBrowserUrl, evaluateCheckoutFreshness, runGitCommand, BLOCKING_FRESHNESS_VERDICTS, claimServiceStack, BUSY_EXIT_CODE, checkServiceStack, releaseServiceStack, readServiceStackStatus, resolvePreferences, buildElectronAppChecksumsUrl, OnboardingBlanketChoice, PreferenceKey, LlmSource, applyLlmSourceSelection, describeStackMismatch, ELECTRON_APP_CHECKSUMS_ASSET_NAME, getDataDir, DEFAULT_LOCAL_LLM_BASE_URL, isValidLocalBaseUrl, local_exports } from './chunk-OIFLV2QN.js';
2
2
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
3
3
  import { ListToolsRequestSchema, CallToolRequestSchema, ListResourcesRequestSchema, ReadResourceRequestSchema } from '@modelcontextprotocol/sdk/types.js';
4
4
  import { v4 } from 'uuid';
5
5
  import { z, ZodError } from 'zod';
6
6
  import * as fs from 'fs';
7
- import { readFileSync, existsSync, rmSync, readdirSync, mkdirSync, writeFileSync, renameSync, createWriteStream, statSync, readlinkSync, realpathSync, openSync, closeSync, writeSync, unlinkSync, copyFileSync, appendFileSync, readSync, fstatSync } from 'fs';
7
+ import { readFileSync, existsSync, rmSync, readdirSync, mkdirSync, writeFileSync, renameSync, createWriteStream, statSync, readlinkSync, realpathSync, openSync, closeSync, writeSync, unlinkSync, copyFileSync, appendFileSync, utimesSync, readSync, fstatSync } from 'fs';
8
8
  import * as path2 from 'path';
9
9
  import path2__default, { join, dirname, resolve, win32, basename } from 'path';
10
10
  import { fileURLToPath, pathToFileURL } from 'url';
@@ -1341,7 +1341,7 @@ async function resolveGsScreenshotUrls(report, opts) {
1341
1341
  if (gsUrls.length === 0) {
1342
1342
  return report;
1343
1343
  }
1344
- const mcps = await import('./src-2OO6JDTQ.js');
1344
+ const mcps = await import('./src-5Z6EIGHT.js');
1345
1345
  const credentials = await mcps.getCallerCredentialsAsync();
1346
1346
  if (!credentials.bearerToken && !credentials.apiKey) {
1347
1347
  stderrWrite(
@@ -2998,6 +2998,23 @@ function helpCommand() {
2998
2998
  console.log(getHelpGuidance());
2999
2999
  }
3000
3000
 
3001
+ // src/pr-watch/constants.ts
3002
+ var REBASE_KEY_SEPARATOR = "..";
3003
+ var LAST_SEEN_FILE_NAME = "last_seen.json";
3004
+ var SERVICE_LOOP_OUTPUT_FILE = "watch-service.out";
3005
+ var SERVICE_LOOP_DELIVERED_FILE = "watch-service.delivered.out";
3006
+ var SERVICE_LOOP_QUEUED_WAKE_FILE = "watch-service.queued.out";
3007
+ var SERVICE_LOOP_EVENT_LINE_PREFIX = "EVENT ";
3008
+ var SERVICE_LOOP_TERMINAL_LINE_PREFIX = "TERMINAL ";
3009
+ var USER_PREFERENCES_PATH_SEGMENTS = [".muggle-ai", "preferences.json"];
3010
+ var PREFERENCE_DEFAULTS_PATH_SEGMENTS = ["config", "preference-defaults.json"];
3011
+ var AUTO_REBASE_PREFERENCE_KEY = "autoRebase";
3012
+ var MAX_CATCH_UP_REBASES_PREFERENCE_KEY = "maxCatchUpRebases";
3013
+ var WATCHER_LIFETIME_PREFERENCE_KEY = "watcherLifetime";
3014
+ var WATCHER_LIFETIME_SECONDS = { "1d": 86400, "7d": 604800, never: 0 };
3015
+ var UNBOUNDED_PREFERENCE_VALUE = "never";
3016
+ var POSITIVE_INTEGER = /^[1-9]\d*$/;
3017
+
3001
3018
  // src/watch/types.ts
3002
3019
  var ClaudeSessionKind = /* @__PURE__ */ ((ClaudeSessionKind2) => {
3003
3020
  ClaudeSessionKind2["Background"] = "background";
@@ -3066,15 +3083,14 @@ var RECOVERY_COOLDOWN_MS = 30 * 6e4;
3066
3083
  var RECOVERY_MAX_ATTEMPTS = 3;
3067
3084
  var RECOVERY_ATTEMPT_WINDOW_MS = 24 * 60 * 6e4;
3068
3085
  var PR_FOLLOWUP_COMMAND = "/muggle:muggle-pr-followup";
3069
- var SERVICE_LOOP_OUTPUT_FILE = "watch-service.out";
3070
- var SERVICE_LOOP_DELIVERED_FILE = "watch-service.delivered.out";
3086
+ var OWNER_WAKE_ALSO_FLAG = "--also=";
3071
3087
  var WATCH_LISTENER_FILE = "watch-listener";
3072
3088
  var SERVICE_WATCH_LISTENER = "muggle-watch";
3073
3089
  var PR_WATCH_ARM_SCRIPT_RELATIVE_PATH = join("plugin", "scripts", "pr-watch-arm.sh");
3074
3090
  var MAX_SERVICE_ARMS_PER_TICK = 5;
3075
3091
  var SERVICE_LOOP_REPORT_PREFIXES = [
3076
- { prefix: "TERMINAL ", kind: "terminal" /* Terminal */ },
3077
- { prefix: "EVENT ", kind: "event" /* Event */ },
3092
+ { prefix: SERVICE_LOOP_TERMINAL_LINE_PREFIX, kind: "terminal" /* Terminal */ },
3093
+ { prefix: SERVICE_LOOP_EVENT_LINE_PREFIX, kind: "event" /* Event */ },
3078
3094
  { prefix: "WATCH-FAIL ", kind: "failed" /* Failed */ },
3079
3095
  { prefix: "ARM-FAIL ", kind: "failed" /* Failed */ },
3080
3096
  { prefix: "EXPIRED ", kind: "expired" /* Expired */ },
@@ -5808,18 +5824,6 @@ function findClaudeSessionCwd(projectsDir, sessionId) {
5808
5824
  return head === void 0 ? void 0 : cwdFromSessionHead(head);
5809
5825
  }
5810
5826
 
5811
- // src/pr-watch/constants.ts
5812
- var REBASE_KEY_SEPARATOR = "..";
5813
- var LAST_SEEN_FILE_NAME = "last_seen.json";
5814
- var USER_PREFERENCES_PATH_SEGMENTS = [".muggle-ai", "preferences.json"];
5815
- var PREFERENCE_DEFAULTS_PATH_SEGMENTS = ["config", "preference-defaults.json"];
5816
- var AUTO_REBASE_PREFERENCE_KEY = "autoRebase";
5817
- var MAX_CATCH_UP_REBASES_PREFERENCE_KEY = "maxCatchUpRebases";
5818
- var WATCHER_LIFETIME_PREFERENCE_KEY = "watcherLifetime";
5819
- var WATCHER_LIFETIME_SECONDS = { "1d": 86400, "7d": 604800, never: 0 };
5820
- var UNBOUNDED_PREFERENCE_VALUE = "never";
5821
- var POSITIVE_INTEGER = /^[1-9]\d*$/;
5822
-
5823
5827
  // src/pr-watch/attempts.ts
5824
5828
  function recordedCount(counts, key) {
5825
5829
  const recorded = counts?.[key];
@@ -5974,25 +5978,68 @@ function parseServiceLoopReport(outputText, writtenAtMs) {
5974
5978
  }
5975
5979
  return { kind, reportLines, writtenAtMs };
5976
5980
  }
5977
- function readServiceLoopReport(slotDir) {
5978
- const outputPath = join(slotDir, SERVICE_LOOP_OUTPUT_FILE);
5981
+ function readReportFile(reportPath) {
5979
5982
  try {
5980
- return parseServiceLoopReport(readFileSync(outputPath, "utf-8"), statSync(outputPath).mtimeMs);
5983
+ return parseServiceLoopReport(readFileSync(reportPath, "utf-8"), statSync(reportPath).mtimeMs);
5981
5984
  } catch {
5982
5985
  return void 0;
5983
5986
  }
5984
5987
  }
5988
+ function readServiceLoopReport(slotDir) {
5989
+ return readReportFile(join(slotDir, SERVICE_LOOP_OUTPUT_FILE));
5990
+ }
5991
+ function readQueuedWakeReport(slotDir) {
5992
+ const queued = readReportFile(join(slotDir, SERVICE_LOOP_QUEUED_WAKE_FILE));
5993
+ return isOwnerWakeReport(queued) ? queued : void 0;
5994
+ }
5985
5995
  function isOwnerWakeReport(report) {
5986
5996
  return report?.kind === "event" /* Event */ || report?.kind === "terminal" /* Terminal */;
5987
5997
  }
5998
+ function undeliveredWakeOf(assessment) {
5999
+ const report = assessment.serviceLoopReport;
6000
+ if (report !== void 0 && isOwnerWakeReport(report) && assessment.watcher !== "polling" /* Polling */) {
6001
+ return { report, ageMs: assessment.serviceLoopReportAgeMs };
6002
+ }
6003
+ if (assessment.queuedWakeReport === void 0) return void 0;
6004
+ return { report: assessment.queuedWakeReport, ageMs: assessment.queuedWakeReportAgeMs };
6005
+ }
6006
+ function removeIfPresent(filePath) {
6007
+ try {
6008
+ rmSync(filePath, { force: true });
6009
+ return true;
6010
+ } catch {
6011
+ return false;
6012
+ }
6013
+ }
6014
+ function queueServiceLoopWakeReport(slotDir) {
6015
+ const outputPath = join(slotDir, SERVICE_LOOP_OUTPUT_FILE);
6016
+ const report = readReportFile(outputPath);
6017
+ if (report === void 0 || !isOwnerWakeReport(report)) return true;
6018
+ const outputText = readSlotText(outputPath);
6019
+ if (!removeIfPresent(outputPath)) return false;
6020
+ const queuedPath = join(slotDir, SERVICE_LOOP_QUEUED_WAKE_FILE);
6021
+ const isFirstQueued = !existsSync(queuedPath);
6022
+ appendFileSync(queuedPath, outputText.endsWith("\n") ? outputText : `${outputText}
6023
+ `);
6024
+ if (isFirstQueued) utimesSync(queuedPath, report.writtenAtMs / 1e3, report.writtenAtMs / 1e3);
6025
+ return true;
6026
+ }
5988
6027
  function markServiceLoopReportDelivered(slotDir) {
5989
6028
  const outputPath = join(slotDir, SERVICE_LOOP_OUTPUT_FILE);
5990
- if (existsSync(outputPath)) renameSync(outputPath, join(slotDir, SERVICE_LOOP_DELIVERED_FILE));
6029
+ const queuedPath = join(slotDir, SERVICE_LOOP_QUEUED_WAKE_FILE);
6030
+ const outputText = readSlotText(outputPath);
6031
+ const isOutputUndelivered = isOwnerWakeReport(parseServiceLoopReport(outputText, 0));
6032
+ const deliveredText = `${readSlotText(queuedPath)}${isOutputUndelivered ? outputText : ""}`;
6033
+ if (deliveredText === "") return;
6034
+ writeFileSync(join(slotDir, SERVICE_LOOP_DELIVERED_FILE), deliveredText);
6035
+ removeIfPresent(queuedPath);
6036
+ if (isOutputUndelivered) removeIfPresent(outputPath);
5991
6037
  }
5992
6038
  function isServiceArmDue(assessment, nowMs, ownerSession) {
5993
6039
  const report = assessment.serviceLoopReport;
5994
6040
  const isFailureCoolingDown = report?.kind === "failed" /* Failed */ && nowMs - report.writtenAtMs < RECOVERY_COOLDOWN_MS;
5995
- return assessment.isRegistered && (assessment.watcher === "dead" /* Dead */ || assessment.watcher === "deaf" /* Deaf */) && assessment.live?.state === "OPEN" /* Open */ && assessment.live.baseBranch !== void 0 && assessment.ownerSessionId !== void 0 && ownerSession?.turnStatus !== "busy" /* Busy */ && !isOwnerWakeReport(report) && !isFailureCoolingDown;
6041
+ const isLeftToOwnerTurn = ownerSession?.turnStatus === "busy" /* Busy */ && undeliveredWakeOf(assessment) === void 0;
6042
+ return assessment.isRegistered && (assessment.watcher === "dead" /* Dead */ || assessment.watcher === "deaf" /* Deaf */) && assessment.live?.state === "OPEN" /* Open */ && assessment.live.baseBranch !== void 0 && assessment.ownerSessionId !== void 0 && !isLeftToOwnerTurn && !isFailureCoolingDown;
5996
6043
  }
5997
6044
  function startServiceLoops(assessments, nowMs, isPollingDisabled, ownerSessionOf, launchServiceLoop) {
5998
6045
  if (isPollingDisabled) return { serviceArms: [], events: [] };
@@ -6010,7 +6057,16 @@ function startServiceLoops(assessments, nowMs, isPollingDisabled, ownerSessionOf
6010
6057
  serviceArms.push({ slug: assessment.slug, prUrl: assessment.pr.url, outcome: "deferred-by-tick-cap" /* DeferredByTickCap */ });
6011
6058
  continue;
6012
6059
  }
6013
- const isStarted = launchServiceLoop(assessment.slotDir, assessment.pr, assessment.live?.baseBranch);
6060
+ if (!queueServiceLoopWakeReport(assessment.slotDir)) {
6061
+ serviceArms.push({ slug: assessment.slug, prUrl: assessment.pr.url, outcome: "deferred-by-report-in-use" /* DeferredByReportInUse */ });
6062
+ continue;
6063
+ }
6064
+ const isStarted = launchServiceLoop(
6065
+ assessment.slotDir,
6066
+ assessment.pr,
6067
+ assessment.live?.baseBranch,
6068
+ assessment.ownerSessionId
6069
+ );
6014
6070
  serviceArms.push({ slug: assessment.slug, prUrl: assessment.pr.url, outcome: isStarted ? "armed" /* Armed */ : "arm-failed" /* ArmFailed */ });
6015
6071
  events.push({
6016
6072
  at,
@@ -6046,7 +6102,7 @@ function resumeSession(target, runCommand, waitForExit, isSessionRunning2, pinSe
6046
6102
  function isOwnerWakeDue(assessment, ownerSession) {
6047
6103
  const isOwnerEnded = ownerSession === void 0 && assessment.isOwnerSessionActive === false;
6048
6104
  const isOwnerReachable = isOwnerEnded ? assessment.live?.state === "OPEN" /* Open */ : ownerSession !== void 0 && isIdleBackgroundSession(ownerSession);
6049
- return assessment.isRegistered && isOwnerWakeReport(assessment.serviceLoopReport) && assessment.watcher !== "polling" /* Polling */ && assessment.ownerSessionId !== void 0 && assessment.live !== void 0 && (assessment.live.state === "OPEN" /* Open */ || isTerminalPrState(assessment.live.state)) && isOwnerReachable;
6105
+ return assessment.isRegistered && undeliveredWakeOf(assessment) !== void 0 && assessment.ownerSessionId !== void 0 && assessment.live !== void 0 && (assessment.live.state === "OPEN" /* Open */ || isTerminalPrState(assessment.live.state)) && isOwnerReachable;
6050
6106
  }
6051
6107
  function isSlotCloseOutDue(assessment) {
6052
6108
  return isTerminalPrState(assessment.live?.state) && assessment.watcher === "dead" /* Dead */ && assessment.isOwnerSessionActive !== true;
@@ -6055,13 +6111,27 @@ function findRunningOwner(sessionsById, ownerSessionId) {
6055
6111
  const ownerShortId = shortSessionId(ownerSessionId);
6056
6112
  return sessionsById.get(ownerSessionId) ?? [...sessionsById.values()].find((session) => session.shortId === ownerShortId);
6057
6113
  }
6058
- function composeOwnerWakePrompt(slotSlug, prNumber, reportKind) {
6059
- return `${PR_FOLLOWUP_COMMAND} ${slotSlug} ${prNumber} --wake=${reportKind}`;
6114
+ function composeOwnerWakePrompt(slotSlug, prNumber, reportKind, otherPendingWakes = []) {
6115
+ const command = `${PR_FOLLOWUP_COMMAND} ${slotSlug} ${prNumber} --wake=${reportKind}`;
6116
+ if (otherPendingWakes.length === 0) return command;
6117
+ const also = otherPendingWakes.map((pending) => `${pending.slotSlug}:${pending.prNumber}:${pending.reportKind}`).join(",");
6118
+ return `${command} ${OWNER_WAKE_ALSO_FLAG}${also}`;
6119
+ }
6120
+ function otherPendingWakesOf(assessments, chosen) {
6121
+ const others = [];
6122
+ for (const assessment of assessments) {
6123
+ if (assessment.ownerSessionId !== chosen.ownerSessionId || assessment.slotDir === chosen.slotDir) continue;
6124
+ const undelivered = undeliveredWakeOf(assessment);
6125
+ if (undelivered === void 0 || others.some((other) => other.slotSlug === assessment.slug)) continue;
6126
+ others.push({ slotSlug: assessment.slug, prNumber: assessment.pr.number, reportKind: undelivered.report.kind });
6127
+ }
6128
+ return others.sort((left, right) => left.slotSlug.localeCompare(right.slotSlug));
6060
6129
  }
6061
6130
  function planWatcherRecoveries(assessments, attemptsByOwner, nowMs, isPollingDisabled, sessionsById = /* @__PURE__ */ new Map(), isUsageLimitInForce = false) {
6062
6131
  if (isPollingDisabled) return [];
6063
6132
  const dueByOwner = /* @__PURE__ */ new Map();
6064
- for (const assessment of [...assessments].sort((left, right) => left.slug.localeCompare(right.slug))) {
6133
+ const sortedAssessments = [...assessments].sort((left, right) => left.slug.localeCompare(right.slug));
6134
+ for (const assessment of sortedAssessments) {
6065
6135
  const ownerSession = assessment.ownerSessionId === void 0 ? void 0 : findRunningOwner(sessionsById, assessment.ownerSessionId);
6066
6136
  if (!isOwnerWakeDue(assessment, ownerSession)) continue;
6067
6137
  const ownerSessionId = assessment.ownerSessionId;
@@ -6080,15 +6150,17 @@ function planWatcherRecoveries(assessments, attemptsByOwner, nowMs, isPollingDis
6080
6150
  else if (nowMs - lastAttemptMs < RECOVERY_COOLDOWN_MS) outcome = "cooling-down" /* CoolingDown */;
6081
6151
  else if (resumesPlanned >= MAX_RESUMES_PER_TICK) outcome = "deferred-by-tick-cap" /* DeferredByTickCap */;
6082
6152
  if (outcome === "resume-due" /* ResumeDue */) resumesPlanned++;
6153
+ const otherPendingWakes = otherPendingWakesOf(sortedAssessments, assessment);
6083
6154
  recoveries.push({
6084
6155
  ownerSessionId,
6085
6156
  slotSlug: assessment.slug,
6086
6157
  slotDir: assessment.slotDir,
6087
6158
  prNumber: assessment.pr.number,
6088
- reportKind: assessment.serviceLoopReport?.kind,
6159
+ reportKind: undeliveredWakeOf(assessment)?.report.kind,
6089
6160
  outcome,
6090
6161
  ...runningOwner?.shortId === void 0 ? {} : { ownerShortId: runningOwner.shortId },
6091
- ...runningOwner === void 0 || runningOwner.sessionId === ownerSessionId ? {} : { ownerRunningSessionId: runningOwner.sessionId }
6162
+ ...runningOwner === void 0 || runningOwner.sessionId === ownerSessionId ? {} : { ownerRunningSessionId: runningOwner.sessionId },
6163
+ ...otherPendingWakes.length === 0 ? {} : { otherPendingWakes }
6092
6164
  });
6093
6165
  }
6094
6166
  return recoveries;
@@ -6109,7 +6181,7 @@ function executeWatcherRecoveries(planned, attemptsByOwner, deps) {
6109
6181
  const cwd = findClaudeSessionCwd(deps.claudeProjectsDir, recovery.ownerSessionId);
6110
6182
  if (!cwd || !existsSync(cwd)) return { ...recovery, outcome: "transcript-missing" /* TranscriptMissing */ };
6111
6183
  const subject = `session ${shortSessionId(recovery.ownerSessionId)}`;
6112
- const prompt = composeOwnerWakePrompt(recovery.slotSlug, recovery.prNumber, recovery.reportKind);
6184
+ const prompt = composeOwnerWakePrompt(recovery.slotSlug, recovery.prNumber, recovery.reportKind, recovery.otherPendingWakes);
6113
6185
  if (recovery.ownerShortId !== void 0 && !deps.canRestartIn(cwd)) {
6114
6186
  countAttempt(recovery.ownerSessionId);
6115
6187
  events.push({
@@ -6175,6 +6247,7 @@ function assessWatchSlots(slots, processes, activeSessionIds, liveStatusesByUrl,
6175
6247
  const isLoopDroppedByOwner = ownerIdleSinceMs !== void 0 && loop?.ageMs !== void 0 && ownerIdleSinceMs >= nowMs - loop.ageMs;
6176
6248
  const watcher = resolveWatcherLiveness(loop, heartbeatAgeMs, isOwnerSessionActive, processes !== null, slot.isHeardByService, isLoopDroppedByOwner);
6177
6249
  const reportAgeMs = slot.serviceLoopReport === void 0 ? void 0 : Math.max(0, nowMs - slot.serviceLoopReport.writtenAtMs);
6250
+ const queuedReportAgeMs = slot.queuedWakeReport === void 0 ? void 0 : Math.max(0, nowMs - slot.queuedWakeReport.writtenAtMs);
6178
6251
  for (const pr of slot.openPrs) {
6179
6252
  const live = liveStatusesByUrl.get(pr.url);
6180
6253
  assessments.push({
@@ -6193,7 +6266,9 @@ function assessWatchSlots(slots, processes, activeSessionIds, liveStatusesByUrl,
6193
6266
  ownerEscalation: resolveOwnerEscalation(slot.lastSeenJson, slot.followupLogLines, pr, live?.headSha),
6194
6267
  isHeardByService: slot.isHeardByService,
6195
6268
  serviceLoopReport: slot.serviceLoopReport,
6196
- serviceLoopReportAgeMs: reportAgeMs
6269
+ serviceLoopReportAgeMs: reportAgeMs,
6270
+ queuedWakeReport: slot.queuedWakeReport,
6271
+ queuedWakeReportAgeMs: queuedReportAgeMs
6197
6272
  });
6198
6273
  }
6199
6274
  }
@@ -6246,9 +6321,10 @@ function watcherFinding(assessment, subject) {
6246
6321
  return void 0;
6247
6322
  }
6248
6323
  function ownerWakeFinding(assessment, subject) {
6249
- const report = assessment.serviceLoopReport;
6250
- if (!report || !isOwnerWakeReport(report) || assessment.watcher === "polling" /* Polling */) return void 0;
6251
- if ((assessment.serviceLoopReportAgeMs ?? 0) <= WATCHER_REARM_GRACE_MS || assessment.ownerSessionId === void 0) return void 0;
6324
+ const undelivered = undeliveredWakeOf(assessment);
6325
+ if (!undelivered) return void 0;
6326
+ if ((undelivered.ageMs ?? 0) <= WATCHER_REARM_GRACE_MS || assessment.ownerSessionId === void 0) return void 0;
6327
+ const report = undelivered.report;
6252
6328
  const command = composeOwnerWakePrompt(assessment.slug, assessment.pr.number, report.kind);
6253
6329
  return finding(
6254
6330
  "OWNER_WAKE_PENDING" /* OwnerWakePending */,
@@ -6902,7 +6978,7 @@ function toBashPath(nativePath) {
6902
6978
  return nativePath.replace(/\\/g, "/");
6903
6979
  }
6904
6980
  function createServiceLoopLauncher(platform4, runCommand, env = process.env) {
6905
- return (slotDir, pr, baseBranch) => {
6981
+ return (slotDir, pr, baseBranch, ownerSessionId) => {
6906
6982
  const bash = resolveLoopBash(platform4, runCommand, env);
6907
6983
  const armScript = findShippedFile(PR_WATCH_ARM_SCRIPT_RELATIVE_PATH);
6908
6984
  if (!bash || !armScript) return false;
@@ -6912,7 +6988,19 @@ function createServiceLoopLauncher(platform4, runCommand, env = process.env) {
6912
6988
  if (loopEnv.MUGGLE_PR_WATCH_MAX_LIFETIME === void 0 && lifetimeSeconds !== void 0) {
6913
6989
  loopEnv.MUGGLE_PR_WATCH_MAX_LIFETIME = String(lifetimeSeconds);
6914
6990
  }
6915
- const args = [toBashPath(armScript), "--slot", toBashPath(slotDir), "--repo", pr.repo, "--pr", String(pr.number), "--base", baseBranch];
6991
+ const args = [
6992
+ toBashPath(armScript),
6993
+ "--slot",
6994
+ toBashPath(slotDir),
6995
+ "--repo",
6996
+ pr.repo,
6997
+ "--pr",
6998
+ String(pr.number),
6999
+ "--base",
7000
+ baseBranch,
7001
+ "--owner",
7002
+ ownerSessionId
7003
+ ];
6916
7004
  let outputFd;
6917
7005
  try {
6918
7006
  outputFd = openSync(join(slotDir, SERVICE_LOOP_OUTPUT_FILE), "w");
@@ -7138,7 +7226,8 @@ function readOpenWatchSlots(slotsDir) {
7138
7226
  lastSeenJson: readSlotText(join(slotDir, LAST_SEEN_FILE_NAME)),
7139
7227
  followupLogLines: readSlotText(join(slotDir, FOLLOWUP_LOG_FILE)).split(/\r?\n/),
7140
7228
  isHeardByService: readSlotText(join(slotDir, WATCH_LISTENER_FILE)).trim() === SERVICE_WATCH_LISTENER,
7141
- serviceLoopReport: readServiceLoopReport(slotDir)
7229
+ serviceLoopReport: readServiceLoopReport(slotDir),
7230
+ queuedWakeReport: readQueuedWakeReport(slotDir)
7142
7231
  });
7143
7232
  }
7144
7233
  return slots;
@@ -7422,8 +7511,11 @@ function runTickUnlocked(deps) {
7422
7511
  recoveries = executed.recoveries;
7423
7512
  recoveryAttemptsByOwner = executed.attemptsByOwner;
7424
7513
  events.push(...executed.events);
7514
+ const wokenSlotDirs = new Set(
7515
+ recoveries.filter((recovery) => recovery.outcome === "resumed" /* Resumed */).map((recovery) => recovery.slotDir)
7516
+ );
7425
7517
  const started = startServiceLoops(
7426
- assessments,
7518
+ assessments.filter((assessment) => !wokenSlotDirs.has(assessment.slotDir)),
7427
7519
  deps.nowMs,
7428
7520
  isPollingDisabled,
7429
7521
  (ownerSessionId) => findRunningOwner(sessionsById, ownerSessionId),