@muggleai/works 5.36.0-staging.336 → 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.
- package/.claude-plugin/marketplace.json +1 -1
- package/dist/{chunk-X3GQII63.js → chunk-HTCBHSL6.js} +130 -38
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/dist/plugin/.claude-plugin/plugin.json +1 -1
- package/dist/plugin/.codex-mcp.json +1 -1
- package/dist/plugin/.codex-plugin/plugin.json +1 -1
- package/dist/plugin/.cursor-plugin/plugin.json +1 -1
- package/dist/plugin/.mcp.json +1 -1
- package/dist/plugin/hooks/README.md +1 -1
- package/dist/plugin/scripts/guardrail-watch-follow-through-gate.sh +22 -7
- package/dist/plugin/scripts/guardrails.mjs +21 -3
- package/dist/plugin/scripts/pr-watch-arm.sh +11 -6
- package/dist/plugin/scripts/pr-watch-loop.sh +3 -2
- package/dist/plugin/scripts/pr-watch-verdict.mjs +1 -0
- package/dist/plugin/skills/do/audit-trail.md +1 -1
- package/dist/plugin/skills/do/e2e-repair.md +1 -1
- package/dist/plugin/skills/do/open-prs/forward.md +17 -15
- package/dist/plugin/skills/do/open-prs.md +1 -1
- package/dist/plugin/skills/muggle-pr-followup/SKILL.md +1 -1
- package/dist/plugin/skills/muggle-pr-followup/arm-watcher.md +2 -2
- package/dist/plugin/skills/muggle-pr-followup/contract.md +6 -0
- package/dist/plugin/skills/muggle-pr-followup/reconcile.md +1 -1
- package/dist/plugin/skills/muggle-pr-followup/state-schemas.md +8 -2
- package/dist/release-manifest.json +4 -4
- package/package.json +1 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/.codex-mcp.json +1 -1
- package/plugin/.codex-plugin/plugin.json +1 -1
- package/plugin/.cursor-plugin/plugin.json +1 -1
- package/plugin/.mcp.json +1 -1
- package/plugin/hooks/README.md +1 -1
- package/plugin/scripts/guardrail-watch-follow-through-gate.sh +22 -7
- package/plugin/scripts/guardrails.mjs +21 -3
- package/plugin/scripts/pr-watch-arm.sh +11 -6
- package/plugin/scripts/pr-watch-loop.sh +3 -2
- package/plugin/scripts/pr-watch-verdict.mjs +1 -0
- package/plugin/skills/do/audit-trail.md +1 -1
- package/plugin/skills/do/e2e-repair.md +1 -1
- package/plugin/skills/do/open-prs/forward.md +17 -15
- package/plugin/skills/do/open-prs.md +1 -1
- package/plugin/skills/muggle-pr-followup/SKILL.md +1 -1
- package/plugin/skills/muggle-pr-followup/arm-watcher.md +2 -2
- package/plugin/skills/muggle-pr-followup/contract.md +6 -0
- package/plugin/skills/muggle-pr-followup/reconcile.md +1 -1
- package/plugin/skills/muggle-pr-followup/state-schemas.md +8 -2
|
@@ -4,7 +4,7 @@ import { ListToolsRequestSchema, CallToolRequestSchema, ListResourcesRequestSche
|
|
|
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';
|
|
@@ -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
|
|
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:
|
|
3077
|
-
{ prefix:
|
|
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
|
|
5978
|
-
const outputPath = join(slotDir, SERVICE_LOOP_OUTPUT_FILE);
|
|
5981
|
+
function readReportFile(reportPath) {
|
|
5979
5982
|
try {
|
|
5980
|
-
return parseServiceLoopReport(readFileSync(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 &&
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
|
6250
|
-
if (!
|
|
6251
|
-
if ((
|
|
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 = [
|
|
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),
|
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { src_exports as commands, createUnifiedMcpServer, server_exports as server } from './chunk-
|
|
1
|
+
export { src_exports as commands, createUnifiedMcpServer, server_exports as server } from './chunk-HTCBHSL6.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-staging.
|
|
4
|
+
"version": "5.36.0-staging.337",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Muggle AI",
|
|
7
7
|
"email": "support@muggle-ai.com"
|
|
@@ -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-staging.
|
|
5
|
+
"version": "5.36.0-staging.337",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Muggle AI",
|
|
8
8
|
"email": "support@muggle-ai.com"
|
package/dist/plugin/.mcp.json
CHANGED
|
@@ -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 | `autoRebase` | **block** the turn, naming each PR and its `/muggle-do rebase` or `fix ci` dispatch. 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` 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, 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 |
|
|
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 |
|
|
@@ -4,15 +4,18 @@ set -uo pipefail
|
|
|
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
6
|
# head — and no attempt for it is recorded, block the turn end and name the
|
|
7
|
-
# dispatch.
|
|
7
|
+
# dispatch. A muggle watch service report the session was never woken for blocks
|
|
8
|
+
# the same way, naming its tick, so a busy owner still hears every slot it owns.
|
|
9
|
+
# Released only by the attempt itself (for a report, the re-arm its tick ends
|
|
10
|
+
# on), a new head, or the user's own
|
|
8
11
|
# HOLD WATCH #<pr-number>: a session once sat on both for a day, re-arming its
|
|
9
12
|
# watch and asking "needs input" at every wake, and every prose rule against it
|
|
10
13
|
# held only as long as the session agreed with it.
|
|
11
14
|
#
|
|
12
15
|
# Synchronous (only a sync Stop hook can block the turn end) and fires on every
|
|
13
16
|
# turn end, so the pre-filter is bash builtins only: a glob over the slots for a
|
|
14
|
-
# non-empty watch-due.env (the watch loop empties it when nothing is due)
|
|
15
|
-
# owner.json names this session. No slot has one on nearly every turn, so Node
|
|
17
|
+
# non-empty watch-due.env (the watch loop empties it when nothing is due) or an
|
|
18
|
+
# undelivered service report, whose owner.json names this session. No slot has one on nearly every turn, so Node
|
|
16
19
|
# never starts. The attempt counters, preferences, and the hold are judged in
|
|
17
20
|
# guardrails.mjs, from local files alone — no provider call. Degrades to {}.
|
|
18
21
|
|
|
@@ -30,11 +33,11 @@ guardrail_wants() {
|
|
|
30
33
|
# A backslash in a glob escapes the next character, so a native Windows HOME
|
|
31
34
|
# would match nothing; forward slashes name the same directory.
|
|
32
35
|
local sessions_dir="${GUARDRAIL_HOME//\\//}/.muggle-ai/muggle-do/sessions"
|
|
33
|
-
local
|
|
34
|
-
for
|
|
35
|
-
|
|
36
|
-
slot_dir="${due_file%/watch-due.env}"
|
|
36
|
+
local slot_dir owner_json
|
|
37
|
+
for slot_dir in "$sessions_dir"/*/; do
|
|
38
|
+
slot_dir="${slot_dir%/}"
|
|
37
39
|
[[ $slot_dir == *.stopped ]] && continue
|
|
40
|
+
guardrail_slot_has_news "$slot_dir" || continue
|
|
38
41
|
[[ -f $slot_dir/owner.json ]] || continue
|
|
39
42
|
owner_json=""
|
|
40
43
|
IFS= read -r -d '' owner_json <"$slot_dir/owner.json" || true
|
|
@@ -43,6 +46,18 @@ guardrail_wants() {
|
|
|
43
46
|
return 1
|
|
44
47
|
}
|
|
45
48
|
|
|
49
|
+
# Whether a slot holds anything the gate judges: due work the watch recorded, or
|
|
50
|
+
# a muggle watch service report its owner was never woken for — queued while a
|
|
51
|
+
# fresh loop watches, or the exited service loop's own EVENT/TERMINAL line.
|
|
52
|
+
guardrail_slot_has_news() {
|
|
53
|
+
local slot_dir="$1" service_output=""
|
|
54
|
+
[[ -s $slot_dir/watch-due.env || -s $slot_dir/watch-service.queued.out ]] && return 0
|
|
55
|
+
[[ -s $slot_dir/watch-service.out ]] || return 1
|
|
56
|
+
IFS= read -r -d '' service_output <"$slot_dir/watch-service.out" || true
|
|
57
|
+
service_output=$'\n'"$service_output"
|
|
58
|
+
[[ $service_output == *$'\n'"EVENT "* || $service_output == *$'\n'"TERMINAL "* ]]
|
|
59
|
+
}
|
|
60
|
+
|
|
46
61
|
if guardrail_is_hook_script; then
|
|
47
62
|
guardrail_run_standalone "$GUARDRAIL_SUBCOMMAND"
|
|
48
63
|
fi
|
|
@@ -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 SERVICE_LOOP_OUTPUT_FILE = "watch-service.out";
|
|
937
|
+
var SERVICE_LOOP_QUEUED_WAKE_FILE = "watch-service.queued.out";
|
|
938
|
+
var SERVICE_LOOP_EVENT_LINE_PREFIX = "EVENT ";
|
|
939
|
+
var SERVICE_LOOP_TERMINAL_LINE_PREFIX = "TERMINAL ";
|
|
940
|
+
var OWNER_WAKE_LINE_PREFIXES = [SERVICE_LOOP_TERMINAL_LINE_PREFIX, SERVICE_LOOP_EVENT_LINE_PREFIX];
|
|
936
941
|
var ENV_FILE_LINE = /^([A-Z_]+)="?([^"]*)"?$/;
|
|
937
942
|
var USER_PREFERENCES_PATH_SEGMENTS = [".muggle-ai", "preferences.json"];
|
|
938
943
|
var PREFERENCE_DEFAULTS_PATH_SEGMENTS = ["config", "preference-defaults.json"];
|
|
@@ -993,6 +998,13 @@ function parseWatchDueRecord(watchDueText) {
|
|
|
993
998
|
};
|
|
994
999
|
return dueRecord.rebaseDueKey || dueRecord.ciRedHeadSha ? dueRecord : null;
|
|
995
1000
|
}
|
|
1001
|
+
function undeliveredWakeLineIn(slotPath) {
|
|
1002
|
+
for (const reportFile of [SERVICE_LOOP_QUEUED_WAKE_FILE, SERVICE_LOOP_OUTPUT_FILE]) {
|
|
1003
|
+
const wakeLine = readSlotText(join(slotPath, reportFile)).split(/\r?\n/).find((line) => OWNER_WAKE_LINE_PREFIXES.some((prefix) => line.startsWith(prefix)));
|
|
1004
|
+
if (wakeLine !== void 0) return wakeLine;
|
|
1005
|
+
}
|
|
1006
|
+
return void 0;
|
|
1007
|
+
}
|
|
996
1008
|
|
|
997
1009
|
// src/guardrails/watchArmed.ts
|
|
998
1010
|
var WATCH_SKIP_MARKER = /^\s*echo\s+["']?MUGGLE_WATCH_SKIP\b/;
|
|
@@ -1472,7 +1484,8 @@ function isDueRecordSuperseded(slotPath, slotPr, dueRecord) {
|
|
|
1472
1484
|
function owedWorkInSlot(slotPath, slug, sessionId2, preferences) {
|
|
1473
1485
|
if (slug.endsWith(STOPPED_SLOT_SUFFIX)) return [];
|
|
1474
1486
|
const dueRecord = parseWatchDueRecord(readSlotText(join(slotPath, WATCH_DUE_FILE_NAME)));
|
|
1475
|
-
|
|
1487
|
+
const undeliveredWakeLine = undeliveredWakeLineIn(slotPath);
|
|
1488
|
+
if (!dueRecord && undeliveredWakeLine === void 0) return [];
|
|
1476
1489
|
if (readJsonRecord(join(slotPath, OWNER_FILE_NAME)).session_id !== sessionId2) return [];
|
|
1477
1490
|
if (existsSync(join(slotPath, RESULT_FILE_NAME))) return [];
|
|
1478
1491
|
const slotPr = readSlotPr(slotPath);
|
|
@@ -1480,8 +1493,8 @@ function owedWorkInSlot(slotPath, slug, sessionId2, preferences) {
|
|
|
1480
1493
|
const prNumber = slotPr?.number;
|
|
1481
1494
|
if (!slotPr?.repo || typeof prUrl !== "string" || typeof prNumber !== "number") return [];
|
|
1482
1495
|
if (TERMINAL_SLOT_PR_STATES.includes((slotPr.state ?? "").toLowerCase())) return [];
|
|
1483
|
-
if (isDueRecordSuperseded(slotPath, slotPr, dueRecord)) return [];
|
|
1484
1496
|
const lastSeenEntry = lastSeenEntryFor(readSlotText(join(slotPath, LAST_SEEN_FILE_NAME)), `${slotPr.repo}#${prNumber}`);
|
|
1497
|
+
if (lastSeenEntry.forward_stages_in_flight === true) return [];
|
|
1485
1498
|
const workOn = (kind, dueOn) => ({
|
|
1486
1499
|
kind,
|
|
1487
1500
|
slug,
|
|
@@ -1490,6 +1503,8 @@ function owedWorkInSlot(slotPath, slug, sessionId2, preferences) {
|
|
|
1490
1503
|
dueOn
|
|
1491
1504
|
});
|
|
1492
1505
|
const owed = [];
|
|
1506
|
+
if (undeliveredWakeLine !== void 0) owed.push(workOn("pending-wake" /* PendingWake */, undeliveredWakeLine));
|
|
1507
|
+
if (!dueRecord || isDueRecordSuperseded(slotPath, slotPr, dueRecord)) return owed;
|
|
1493
1508
|
const isRebaseOwed = dueRecord.rebaseDueKey !== "" && preferences.autoRebase === ALWAYS_PREFERENCE_VALUE && !isRebaseBudgetExhausted(lastSeenEntry, preferences.maxCatchUpRebases) && !isRebaseKeyAttempted(lastSeenEntry, dueRecord.rebaseDueKey);
|
|
1494
1509
|
if (isRebaseOwed) owed.push(workOn("rebase" /* Rebase */, dueRecord.rebaseDueKey));
|
|
1495
1510
|
if (dueRecord.ciRedHeadSha !== "" && !isCiHeadAttempted(lastSeenEntry, dueRecord.ciRedHeadSha)) {
|
|
@@ -3461,6 +3476,9 @@ function watchGate() {
|
|
|
3461
3476
|
}
|
|
3462
3477
|
function owedWatchWorkLine(work) {
|
|
3463
3478
|
const muggleDo = muggleSkill("/muggle-do");
|
|
3479
|
+
if (work.kind === "pending-wake" /* PendingWake */) {
|
|
3480
|
+
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
|
+
}
|
|
3464
3482
|
if (work.kind === "rebase" /* Rebase */) {
|
|
3465
3483
|
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}\`.`;
|
|
3466
3484
|
}
|
|
@@ -3492,7 +3510,7 @@ function watchFollowThroughGate() {
|
|
|
3492
3510
|
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.`;
|
|
3493
3511
|
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:
|
|
3494
3512
|
${owedList}
|
|
3495
|
-
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. ${holdInstruction}` : `Watcher work still owed (reminder ${decision.blockCount}):
|
|
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}):
|
|
3496
3514
|
${owedList}
|
|
3497
3515
|
${holdInstruction}`;
|
|
3498
3516
|
return blockStop(reason, host);
|
|
@@ -23,7 +23,7 @@ set -uo pipefail
|
|
|
23
23
|
|
|
24
24
|
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
25
25
|
|
|
26
|
-
slot="" repo="" pr_number="" base_branch="" exec_loop=1
|
|
26
|
+
slot="" repo="" pr_number="" base_branch="" owner_session="" exec_loop=1
|
|
27
27
|
|
|
28
28
|
while [ $# -gt 0 ]; do
|
|
29
29
|
case "$1" in
|
|
@@ -31,13 +31,14 @@ while [ $# -gt 0 ]; do
|
|
|
31
31
|
--repo) repo="$2"; shift 2 ;;
|
|
32
32
|
--pr) pr_number="$2"; shift 2 ;;
|
|
33
33
|
--base) base_branch="$2"; shift 2 ;;
|
|
34
|
+
--owner) owner_session="$2"; shift 2 ;;
|
|
34
35
|
--no-exec) exec_loop=0; shift ;;
|
|
35
36
|
*) echo "pr-watch-arm: unknown argument $1" >&2; exit 2 ;;
|
|
36
37
|
esac
|
|
37
38
|
done
|
|
38
39
|
|
|
39
40
|
if [ -z "$slot" ] || [ -z "$repo" ] || [ -z "$pr_number" ] || [ -z "$base_branch" ]; then
|
|
40
|
-
echo "usage: pr-watch-arm.sh --slot <dir> --repo <owner/repo> --pr <n> --base <branch> [--no-exec]" >&2
|
|
41
|
+
echo "usage: pr-watch-arm.sh --slot <dir> --repo <owner/repo> --pr <n> --base <branch> [--owner <session-id>] [--no-exec]" >&2
|
|
41
42
|
exit 2
|
|
42
43
|
fi
|
|
43
44
|
|
|
@@ -199,17 +200,21 @@ fi
|
|
|
199
200
|
|
|
200
201
|
watch_record_due_work "$slot" "$head_sha" "$recorded_rebase_due_key" "$ci_red_head"
|
|
201
202
|
|
|
202
|
-
# Claim the slot for
|
|
203
|
+
# Claim the slot for its owner: the session --owner names, else this session.
|
|
204
|
+
# The muggle watch service arms outside every session, so it passes the owner
|
|
205
|
+
# the slot already records; without it every loop the service restarted left
|
|
206
|
+
# its slot unowned. watcher_lease_is_foreign reads an absent
|
|
203
207
|
# owner.json as "not foreign", so a slot armed without one leases itself to a
|
|
204
208
|
# live PID nothing can classify: once the arming session dies its watcher polls
|
|
205
209
|
# into a closed pipe, and every later arm skips the slot as already owned until
|
|
206
210
|
# the loop's monitor window ends it. An unset id writes nothing rather than a placeholder
|
|
207
211
|
# — reconcile reads any id it does not recognise as another session's claim, and
|
|
208
212
|
# a bogus one would strand the slot exactly as an absent file does.
|
|
209
|
-
|
|
213
|
+
[ -n "$owner_session" ] || owner_session="${CLAUDE_CODE_SESSION_ID:-}"
|
|
214
|
+
if [ -n "$owner_session" ]; then
|
|
210
215
|
claimed_at="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
211
216
|
printf '{\n "session_id": "%s",\n "claimed_at": "%s"\n}\n' \
|
|
212
|
-
"$
|
|
217
|
+
"$owner_session" "$claimed_at" > "${slot}/owner.json"
|
|
213
218
|
# Register the slot with the muggle watch service, which restarts the loop
|
|
214
219
|
# outside every session if it dies and wakes this owner only when that loop
|
|
215
220
|
# reports on this PR. It lives in the slot, so a stop rename or a finalize
|
|
@@ -217,7 +222,7 @@ if [ -n "${CLAUDE_CODE_SESSION_ID:-}" ]; then
|
|
|
217
222
|
printf '{\n "registered_at": "%s",\n "registered_by": "pr-watch-arm"\n}\n' \
|
|
218
223
|
"$claimed_at" > "${slot}/watch-registration.json"
|
|
219
224
|
else
|
|
220
|
-
echo "pr-watch-arm: CLAUDE_CODE_SESSION_ID unset — slot left unowned, reconcile cannot re-arm it" >&2
|
|
225
|
+
echo "pr-watch-arm: no --owner and CLAUDE_CODE_SESSION_ID unset — slot left unowned, reconcile cannot re-arm it" >&2
|
|
221
226
|
fi
|
|
222
227
|
|
|
223
228
|
echo "ARMED pr=$pr_number watermark seeded at ${slot}/watch-watermark.env"
|
|
@@ -60,11 +60,12 @@ echo "$$" > "${slot}/watch.pid"
|
|
|
60
60
|
# Who hears this loop's exit. A session hears the background command it armed;
|
|
61
61
|
# a loop the muggle watch service started is heard by the service, which wakes
|
|
62
62
|
# the owner session only when the loop reports. A session arming the slot takes
|
|
63
|
-
# it back, and its own drain covers whatever an undelivered service report held
|
|
63
|
+
# it back, and its own drain covers whatever an undelivered service report held,
|
|
64
|
+
# the ones queued while a service loop watched on included.
|
|
64
65
|
if [ -n "${MUGGLE_PR_WATCH_LISTENER:-}" ]; then
|
|
65
66
|
printf '%s\n' "$MUGGLE_PR_WATCH_LISTENER" > "${slot}/watch-listener"
|
|
66
67
|
else
|
|
67
|
-
rm -f "${slot}/watch-listener" "${slot}/watch-service.out"
|
|
68
|
+
rm -f "${slot}/watch-listener" "${slot}/watch-service.out" "${slot}/watch-service.queued.out"
|
|
68
69
|
fi
|
|
69
70
|
started=$(date +%s)
|
|
70
71
|
fails=0
|
|
@@ -105,6 +105,7 @@ var CiRollupBucket = /* @__PURE__ */ ((CiRollupBucket2) => {
|
|
|
105
105
|
// src/pr-watch/tickVerdict.ts
|
|
106
106
|
function resolveWatchTickVerdict(lastSeenEntry, observation, preferences) {
|
|
107
107
|
const { headSha, rebaseKey } = observation;
|
|
108
|
+
if (lastSeenEntry.forward_stages_in_flight === true) return "hold-forward-stages" /* HoldForwardStages */;
|
|
108
109
|
if (observation.isRebaseDue) {
|
|
109
110
|
if (isRebaseBudgetExhausted(lastSeenEntry, preferences.maxCatchUpRebases)) {
|
|
110
111
|
return "block-rebase-budget-exhausted" /* BlockRebaseBudgetExhausted */;
|