@muggleai/works 5.26.0-staging.207 → 5.26.0-staging.209
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/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/agents/acceptance-tester.md +18 -2
- package/dist/plugin/hooks/README.md +7 -5
- package/dist/plugin/hooks/codex-hooks.json +4 -4
- package/dist/plugin/hooks/hooks.json +3 -3
- package/dist/plugin/scripts/guardrail-record-delegation.sh +25 -0
- package/dist/plugin/scripts/guardrail-walkthrough-gate.sh +6 -6
- package/dist/plugin/scripts/guardrail-watch-follow-through-gate.sh +48 -0
- package/dist/plugin/scripts/guardrails.mjs +443 -64
- package/dist/plugin/scripts/pr-watch-arm.sh +64 -37
- package/dist/plugin/scripts/pr-watch-due.sh +31 -0
- package/dist/plugin/scripts/pr-watch-events.sh +20 -6
- package/dist/plugin/scripts/pr-watch-loop.sh +21 -2
- package/dist/plugin/scripts/pr-watch-verdict.mjs +197 -0
- package/dist/plugin/skills/_shared/ci-check-to-command.md +2 -1
- package/dist/plugin/skills/do/background-e2e.md +89 -0
- package/dist/plugin/skills/do/e2e-acceptance.md +4 -0
- package/dist/plugin/skills/do/e2e-repair.md +1 -1
- package/dist/plugin/skills/do/fix-ci.md +24 -8
- package/dist/plugin/skills/do/open-prs/forward.md +3 -3
- package/dist/plugin/skills/do/pre-flight.md +4 -3
- package/dist/plugin/skills/do/resolve-conflicts.md +7 -3
- package/dist/plugin/skills/do/wave-e2e.md +3 -3
- package/dist/plugin/skills/do/wave-or-stream.md +51 -0
- package/dist/plugin/skills/muggle-do/SKILL.md +6 -2
- package/dist/plugin/skills/muggle-pr-followup/SKILL.md +1 -1
- package/dist/plugin/skills/muggle-pr-followup/arm-watcher.md +5 -3
- package/dist/plugin/skills/muggle-pr-followup/blocked-tick.md +2 -0
- package/dist/plugin/skills/muggle-pr-followup/contract.md +40 -25
- package/dist/plugin/skills/muggle-pr-followup/state-schemas.md +22 -8
- package/dist/release-manifest.json +3 -3
- 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/agents/acceptance-tester.md +18 -2
- package/plugin/hooks/README.md +7 -5
- package/plugin/hooks/codex-hooks.json +4 -4
- package/plugin/hooks/hooks.json +3 -3
- package/plugin/scripts/guardrail-record-delegation.sh +25 -0
- package/plugin/scripts/guardrail-walkthrough-gate.sh +6 -6
- package/plugin/scripts/guardrail-watch-follow-through-gate.sh +48 -0
- package/plugin/scripts/guardrails.mjs +443 -64
- package/plugin/scripts/pr-watch-arm.sh +64 -37
- package/plugin/scripts/pr-watch-due.sh +31 -0
- package/plugin/scripts/pr-watch-events.sh +20 -6
- package/plugin/scripts/pr-watch-loop.sh +21 -2
- package/plugin/scripts/pr-watch-verdict.mjs +197 -0
- package/plugin/skills/_shared/ci-check-to-command.md +2 -1
- package/plugin/skills/do/background-e2e.md +89 -0
- package/plugin/skills/do/e2e-acceptance.md +4 -0
- package/plugin/skills/do/e2e-repair.md +1 -1
- package/plugin/skills/do/fix-ci.md +24 -8
- package/plugin/skills/do/open-prs/forward.md +3 -3
- package/plugin/skills/do/pre-flight.md +4 -3
- package/plugin/skills/do/resolve-conflicts.md +7 -3
- package/plugin/skills/do/wave-e2e.md +3 -3
- package/plugin/skills/do/wave-or-stream.md +51 -0
- package/plugin/skills/muggle-do/SKILL.md +6 -2
- package/plugin/skills/muggle-pr-followup/SKILL.md +1 -1
- package/plugin/skills/muggle-pr-followup/arm-watcher.md +5 -3
- package/plugin/skills/muggle-pr-followup/blocked-tick.md +2 -0
- package/plugin/skills/muggle-pr-followup/contract.md +40 -25
- package/plugin/skills/muggle-pr-followup/state-schemas.md +22 -8
- /package/dist/{chunk-HGN35NEP.js → chunk-PQVRAFNE.js} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readFileSync, existsSync, readdirSync, mkdirSync, statSync, writeFileSync, renameSync,
|
|
1
|
+
import { readFileSync, existsSync, readdirSync, mkdirSync, openSync, fstatSync, readSync, closeSync, statSync, writeFileSync, renameSync, writeSync, unlinkSync } from 'fs';
|
|
2
2
|
import { join, basename, isAbsolute, resolve, dirname } from 'path';
|
|
3
3
|
import { homedir, hostname } from 'os';
|
|
4
4
|
import { execFileSync, spawn } from 'child_process';
|
|
@@ -34,6 +34,9 @@ var MAX_WATCH_BLOCKS = 3;
|
|
|
34
34
|
var WATCH_HEARTBEAT_STALE_MS = 15 * 6e4;
|
|
35
35
|
var TERMINAL_SLOT_PR_STATES = ["merged", "closed"];
|
|
36
36
|
var STOPPED_SLOT_SUFFIX = ".stopped";
|
|
37
|
+
var WATCH_HOLD_PHRASE_PREFIX = "HOLD WATCH #";
|
|
38
|
+
var WATCH_HOLD_INSTRUCTION = /HOLD WATCH #(\d+)\b/g;
|
|
39
|
+
var WATCH_HOLD_TRANSCRIPT_TAIL_BYTES = 4e6;
|
|
37
40
|
var MAX_BUILD_BLOCKS = 3;
|
|
38
41
|
var MAX_WALKTHROUGH_BLOCKS = 3;
|
|
39
42
|
var GH_LOOKUP_TIMEOUT_MS = 1e4;
|
|
@@ -75,6 +78,12 @@ var CALL_FAILURE_SIGNALS = [
|
|
|
75
78
|
var FORGE_TERMINAL_CMD = /\b(?:gh\s+pr\s+(?:merge|close|reopen)|glab\s+mr\s+(?:merge|close|reopen))\b/;
|
|
76
79
|
var WATCH_TERMINAL_CMD = /pr-watch-(?:loop|arm)\.sh/;
|
|
77
80
|
var MERGED_GATE_OUTPUT_SEPARATOR = "\n\n";
|
|
81
|
+
var GITHUB_PR_URL = /https:\/\/github\.com\/[^/\s]+\/[^/\s]+\/pull\/\d+/;
|
|
82
|
+
var GITLAB_MR_URL = /https?:\/\/[^/\s]+\/[^\s]+\/-\/merge_requests\/\d+/;
|
|
83
|
+
var SUBAGENT_DISPATCH_TOOL_NAMES = ["Agent", "Task"];
|
|
84
|
+
var ACCEPTANCE_TESTER_SUBAGENT_TYPE = /(?:^|:)acceptance-tester$/;
|
|
85
|
+
var ACCEPTANCE_REPORT_MARKERS = ["## Test Summary", "**Overall:**"];
|
|
86
|
+
var DELEGATED_E2E_WINDOW_MS = 60 * 6e4;
|
|
78
87
|
|
|
79
88
|
// src/guardrails/store/fileLock.ts
|
|
80
89
|
function isProcessAlive(pid) {
|
|
@@ -207,6 +216,7 @@ var GuardrailBackgroundJob = /* @__PURE__ */ ((GuardrailBackgroundJob2) => {
|
|
|
207
216
|
GuardrailBackgroundJob2["ScanWalkthroughs"] = "scan-walkthroughs";
|
|
208
217
|
GuardrailBackgroundJob2["ReserveWalkthroughComment"] = "reserve-walkthrough-comment";
|
|
209
218
|
GuardrailBackgroundJob2["SettleWalkthroughSkipped"] = "settle-walkthrough-skipped";
|
|
219
|
+
GuardrailBackgroundJob2["SettleBranchWalkthroughSkipped"] = "settle-branch-walkthrough-skipped";
|
|
210
220
|
GuardrailBackgroundJob2["SettleWalkthroughUnreasoned"] = "settle-walkthrough-unreasoned";
|
|
211
221
|
GuardrailBackgroundJob2["SettleWalkthroughNoAppLogicChange"] = "settle-walkthrough-no-app-logic-change";
|
|
212
222
|
GuardrailBackgroundJob2["ScanWatchPrStates"] = "scan-watch-pr-states";
|
|
@@ -245,8 +255,6 @@ function isShellToolCall(input2) {
|
|
|
245
255
|
}
|
|
246
256
|
|
|
247
257
|
// src/guardrails/prOpened.ts
|
|
248
|
-
var PR_URL = /https:\/\/github\.com\/[^/\s]+\/[^/\s]+\/pull\/\d+/;
|
|
249
|
-
var MR_URL = /https?:\/\/[^/\s]+\/[^\s]+\/-\/merge_requests\/\d+/;
|
|
250
258
|
var CREATE_CMD = /\bgh\s+pr\s+(create|ready)\b/;
|
|
251
259
|
var MR_CREATE_CMD = /\bglab\s+mr\s+create\b|\bglab\s+mr\s+update\b.*--ready\b/;
|
|
252
260
|
function detectPrOpened(input2) {
|
|
@@ -255,7 +263,7 @@ function detectPrOpened(input2) {
|
|
|
255
263
|
if (!CREATE_CMD.test(cmd) && !MR_CREATE_CMD.test(cmd)) return null;
|
|
256
264
|
const out = `${input2.tool_response?.stdout ?? ""}
|
|
257
265
|
${input2.tool_response?.output ?? ""}`;
|
|
258
|
-
const m = out.match(
|
|
266
|
+
const m = out.match(GITHUB_PR_URL) ?? out.match(GITLAB_MR_URL);
|
|
259
267
|
return m ? m[0] : null;
|
|
260
268
|
}
|
|
261
269
|
|
|
@@ -370,6 +378,11 @@ function lastAssistantText(transcriptJsonl) {
|
|
|
370
378
|
}
|
|
371
379
|
return "";
|
|
372
380
|
}
|
|
381
|
+
function resolvePluginRoot(env = process.env) {
|
|
382
|
+
return env.CLAUDE_PLUGIN_ROOT || env.CURSOR_PLUGIN_ROOT || dirname(dirname(fileURLToPath(import.meta.url)));
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// src/guardrails/mandatoryStages.ts
|
|
373
386
|
var FRONTMATTER = /^---\r?\n([\s\S]*?)\r?\n---/;
|
|
374
387
|
var SEQUENCE_ENTRY = /^\s*-\s*(.+?)\s*$/;
|
|
375
388
|
var FLOW_LIST = /^\s*\[(.*)\]\s*$/;
|
|
@@ -413,9 +426,7 @@ function stageLabel(normalizedStagePath) {
|
|
|
413
426
|
return normalizedStagePath.slice(insideSkills + SKILLS_PATH_SEGMENT.length);
|
|
414
427
|
}
|
|
415
428
|
function resolvePluginSkillsRoot() {
|
|
416
|
-
|
|
417
|
-
if (pluginRoot) return join(pluginRoot, SKILLS_DIR_NAME);
|
|
418
|
-
return join(dirname(dirname(fileURLToPath(import.meta.url))), SKILLS_DIR_NAME);
|
|
429
|
+
return join(resolvePluginRoot(), SKILLS_DIR_NAME);
|
|
419
430
|
}
|
|
420
431
|
function resolveSkillNameFromToolInput(toolInput) {
|
|
421
432
|
if (!toolInput) return void 0;
|
|
@@ -632,6 +643,38 @@ function classificationGateDecision(state, input2) {
|
|
|
632
643
|
return { deny: true, testCaseId };
|
|
633
644
|
}
|
|
634
645
|
|
|
646
|
+
// src/guardrails/prUrls.ts
|
|
647
|
+
function extractPrUrls(text) {
|
|
648
|
+
const githubPrUrls = [...text.matchAll(new RegExp(GITHUB_PR_URL.source, "g"))];
|
|
649
|
+
const gitlabMrUrls = [...text.matchAll(new RegExp(GITLAB_MR_URL.source, "g"))];
|
|
650
|
+
return [...new Set([...githubPrUrls, ...gitlabMrUrls].map((match) => match[0]))];
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
// src/guardrails/delegatedE2e.ts
|
|
654
|
+
function carriesAcceptanceReport(input2) {
|
|
655
|
+
const response = JSON.stringify(input2.tool_response ?? "");
|
|
656
|
+
return ACCEPTANCE_REPORT_MARKERS.some((marker) => response.includes(marker));
|
|
657
|
+
}
|
|
658
|
+
function detectBackgroundAcceptanceDispatch(input2) {
|
|
659
|
+
if (!SUBAGENT_DISPATCH_TOOL_NAMES.includes(input2.tool_name ?? "")) return null;
|
|
660
|
+
if (!ACCEPTANCE_TESTER_SUBAGENT_TYPE.test(input2.tool_input?.subagent_type ?? "")) return null;
|
|
661
|
+
if (callFailed(input2) || carriesAcceptanceReport(input2)) return null;
|
|
662
|
+
return extractPrUrls(input2.tool_input?.prompt ?? "");
|
|
663
|
+
}
|
|
664
|
+
function liveDelegations(state, now) {
|
|
665
|
+
return (state.e2eDelegations ?? []).filter((delegation) => now - delegation.dispatchedAt < DELEGATED_E2E_WINDOW_MS);
|
|
666
|
+
}
|
|
667
|
+
function applyE2eDelegation(state, delegation) {
|
|
668
|
+
return { ...state, e2eDelegations: [...liveDelegations(state, delegation.dispatchedAt), delegation] };
|
|
669
|
+
}
|
|
670
|
+
function isE2eDelegationInFlight(state, now) {
|
|
671
|
+
return liveDelegations(state, now).length > 0;
|
|
672
|
+
}
|
|
673
|
+
function withoutDelegatedPrs(prUrls, state, now) {
|
|
674
|
+
const delegatedPrUrls = new Set(liveDelegations(state, now).flatMap((delegation) => delegation.prUrls));
|
|
675
|
+
return prUrls.filter((prUrl) => !delegatedPrUrls.has(prUrl));
|
|
676
|
+
}
|
|
677
|
+
|
|
635
678
|
// src/guardrails/debugPath.ts
|
|
636
679
|
var DEBUG_SKIP_MARKER = /^\s*echo\s+["']?MUGGLE_DEBUG_SKIP\b/;
|
|
637
680
|
var serialize = (input2) => `${JSON.stringify(input2.tool_input ?? {})}
|
|
@@ -685,10 +728,10 @@ function undebuggedFailedRuns(state) {
|
|
|
685
728
|
const debugged = new Set(state.debuggedRuns ?? []);
|
|
686
729
|
return (state.failedRuns ?? []).filter((runId) => !debugged.has(runId));
|
|
687
730
|
}
|
|
688
|
-
function debugGateDecision(state, maxBlocks = MAX_DEBUG_BLOCKS) {
|
|
731
|
+
function debugGateDecision(state, maxBlocks = MAX_DEBUG_BLOCKS, now = Date.now()) {
|
|
689
732
|
const blockCount = state.debugBlockCount ?? 0;
|
|
690
733
|
const undebugged = undebuggedFailedRuns(state);
|
|
691
|
-
if (state.debugSkipped === true || undebugged.length === 0) {
|
|
734
|
+
if (state.debugSkipped === true || undebugged.length === 0 || isE2eDelegationInFlight(state, now)) {
|
|
692
735
|
return { action: "none" /* None */, blockCount, undebugged };
|
|
693
736
|
}
|
|
694
737
|
if (blockCount >= maxBlocks) {
|
|
@@ -817,9 +860,11 @@ function applyRecordedRun(state, run) {
|
|
|
817
860
|
}
|
|
818
861
|
return next;
|
|
819
862
|
}
|
|
820
|
-
function e2eGateDecision(state, maxBlocks = MAX_E2E_BLOCKS) {
|
|
863
|
+
function e2eGateDecision(state, maxBlocks = MAX_E2E_BLOCKS, now = Date.now()) {
|
|
821
864
|
const blockCount = state.e2eBlockCount ?? 0;
|
|
822
|
-
if (!shouldRunE2E(state)
|
|
865
|
+
if (!shouldRunE2E(state) || isE2eDelegationInFlight(state, now)) {
|
|
866
|
+
return { action: "none" /* None */, blockCount };
|
|
867
|
+
}
|
|
823
868
|
if (blockCount >= maxBlocks) return { action: "release" /* Release */, blockCount };
|
|
824
869
|
return { action: "block" /* Block */, blockCount: blockCount + 1 };
|
|
825
870
|
}
|
|
@@ -849,7 +894,7 @@ var SHORT_SHA_LENGTH = 7;
|
|
|
849
894
|
var GH_COMMENT_TIMEOUT_MS = 1e4;
|
|
850
895
|
|
|
851
896
|
// src/pr-walkthrough/gh.ts
|
|
852
|
-
var
|
|
897
|
+
var GITHUB_PR_URL2 = /^https:\/\/github\.com\/([^/\s]+)\/([^/\s]+)\/pull\/(\d+)/;
|
|
853
898
|
var GH_CALLS_ENV = "MUGGLE_GUARDRAIL_GH_CALLS";
|
|
854
899
|
var defaultGhRunner = (args, input2) => {
|
|
855
900
|
if (process.env[GH_CALLS_ENV] === "off") return null;
|
|
@@ -868,7 +913,7 @@ var defaultGhRunner = (args, input2) => {
|
|
|
868
913
|
}
|
|
869
914
|
};
|
|
870
915
|
function parsePrUrl(prUrl) {
|
|
871
|
-
const parts = prUrl.match(
|
|
916
|
+
const parts = prUrl.match(GITHUB_PR_URL2);
|
|
872
917
|
if (!parts) return null;
|
|
873
918
|
return { repo: `${parts[1]}/${parts[2]}`, prNumber: Number(parts[3]) };
|
|
874
919
|
}
|
|
@@ -916,6 +961,75 @@ function patchPrComment(pr, commentId, body, run) {
|
|
|
916
961
|
);
|
|
917
962
|
}
|
|
918
963
|
|
|
964
|
+
// src/pr-watch/constants.ts
|
|
965
|
+
var MUGGLE_DO_SESSIONS_PATH_SEGMENTS = [".muggle-ai", "muggle-do", "sessions"];
|
|
966
|
+
var PRS_FILE_NAME = "prs.json";
|
|
967
|
+
var OWNER_FILE_NAME = "owner.json";
|
|
968
|
+
var LAST_SEEN_FILE_NAME = "last_seen.json";
|
|
969
|
+
var RESULT_FILE_NAME = "result.md";
|
|
970
|
+
var WATCH_DUE_FILE_NAME = "watch-due.env";
|
|
971
|
+
var WATCH_DUE_HEAD_FIELD = "HEAD";
|
|
972
|
+
var WATCH_DUE_REBASE_FIELD = "REBASE_DUE";
|
|
973
|
+
var WATCH_DUE_CI_RED_FIELD = "CI_RED_HEAD";
|
|
974
|
+
var ENV_FILE_LINE = /^([A-Z_]+)="?([^"]*)"?$/;
|
|
975
|
+
var USER_PREFERENCES_PATH_SEGMENTS = [".muggle-ai", "preferences.json"];
|
|
976
|
+
var PREFERENCE_DEFAULTS_PATH_SEGMENTS = ["config", "preference-defaults.json"];
|
|
977
|
+
var AUTO_REBASE_PREFERENCE_KEY = "autoRebase";
|
|
978
|
+
var MAX_CATCH_UP_REBASES_PREFERENCE_KEY = "maxCatchUpRebases";
|
|
979
|
+
var ALWAYS_PREFERENCE_VALUE = "always";
|
|
980
|
+
var UNBOUNDED_PREFERENCE_VALUE = "never";
|
|
981
|
+
var POSITIVE_INTEGER = /^[1-9]\d*$/;
|
|
982
|
+
function readSlotText(filePath) {
|
|
983
|
+
try {
|
|
984
|
+
return readFileSync(filePath, "utf-8");
|
|
985
|
+
} catch {
|
|
986
|
+
return "";
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
function readSlotPr(slotPath) {
|
|
990
|
+
try {
|
|
991
|
+
const parsed = JSON.parse(readFileSync(join(slotPath, PRS_FILE_NAME), "utf-8"));
|
|
992
|
+
const slotPr = Array.isArray(parsed) ? parsed[0] : parsed;
|
|
993
|
+
return slotPr !== null && typeof slotPr === "object" ? slotPr : void 0;
|
|
994
|
+
} catch {
|
|
995
|
+
return void 0;
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
function readJsonRecord(filePath) {
|
|
999
|
+
try {
|
|
1000
|
+
return asRecord(JSON.parse(readFileSync(filePath, "utf-8")));
|
|
1001
|
+
} catch {
|
|
1002
|
+
return {};
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
function asRecord(candidate) {
|
|
1006
|
+
return candidate !== null && typeof candidate === "object" && !Array.isArray(candidate) ? candidate : {};
|
|
1007
|
+
}
|
|
1008
|
+
function lastSeenEntryFor(lastSeenJson, prKey) {
|
|
1009
|
+
try {
|
|
1010
|
+
return asRecord(asRecord(JSON.parse(lastSeenJson))[prKey]);
|
|
1011
|
+
} catch {
|
|
1012
|
+
return {};
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
function parseEnvFileLines(envFileText) {
|
|
1016
|
+
const fields = {};
|
|
1017
|
+
for (const rawLine of envFileText.split("\n")) {
|
|
1018
|
+
const fieldMatch = ENV_FILE_LINE.exec(rawLine.replace(/\r$/, ""));
|
|
1019
|
+
if (fieldMatch) fields[fieldMatch[1]] = fieldMatch[2];
|
|
1020
|
+
}
|
|
1021
|
+
return fields;
|
|
1022
|
+
}
|
|
1023
|
+
function parseWatchDueRecord(watchDueText) {
|
|
1024
|
+
const fields = parseEnvFileLines(watchDueText);
|
|
1025
|
+
const dueRecord = {
|
|
1026
|
+
headSha: fields[WATCH_DUE_HEAD_FIELD] ?? "",
|
|
1027
|
+
rebaseDueKey: fields[WATCH_DUE_REBASE_FIELD] ?? "",
|
|
1028
|
+
ciRedHeadSha: fields[WATCH_DUE_CI_RED_FIELD] ?? ""
|
|
1029
|
+
};
|
|
1030
|
+
return dueRecord.rebaseDueKey || dueRecord.ciRedHeadSha ? dueRecord : null;
|
|
1031
|
+
}
|
|
1032
|
+
|
|
919
1033
|
// src/guardrails/watchArmed.ts
|
|
920
1034
|
var WATCH_SKIP_MARKER = /^\s*echo\s+["']?MUGGLE_WATCH_SKIP\b/;
|
|
921
1035
|
function isWatchSkipMarker(cmd) {
|
|
@@ -943,7 +1057,7 @@ function readHeartbeatMtimeMs(slotPath) {
|
|
|
943
1057
|
}
|
|
944
1058
|
function findUnwatchedHandledPrs(handledUrls, sessionsDirOverride) {
|
|
945
1059
|
if (handledUrls.length === 0) return [];
|
|
946
|
-
const sessionsDir = join(homedir(),
|
|
1060
|
+
const sessionsDir = join(homedir(), ...MUGGLE_DO_SESSIONS_PATH_SEGMENTS);
|
|
947
1061
|
let slugs;
|
|
948
1062
|
try {
|
|
949
1063
|
slugs = readdirSync(sessionsDir);
|
|
@@ -954,18 +1068,12 @@ function findUnwatchedHandledPrs(handledUrls, sessionsDirOverride) {
|
|
|
954
1068
|
const watchedUrls = /* @__PURE__ */ new Set();
|
|
955
1069
|
for (const slug of slugs) {
|
|
956
1070
|
const slotPath = join(sessionsDir, slug);
|
|
957
|
-
|
|
958
|
-
try {
|
|
959
|
-
const parsed = JSON.parse(readFileSync(join(slotPath, "prs.json"), "utf-8"));
|
|
960
|
-
slotPr = Array.isArray(parsed) ? parsed[0] : parsed;
|
|
961
|
-
} catch {
|
|
962
|
-
continue;
|
|
963
|
-
}
|
|
1071
|
+
const slotPr = readSlotPr(slotPath);
|
|
964
1072
|
const slotUrl = slotPr?.url;
|
|
965
1073
|
if (typeof slotUrl !== "string" || !handledUrls.includes(slotUrl)) continue;
|
|
966
1074
|
const evidence = {
|
|
967
1075
|
isStopped: slug.endsWith(STOPPED_SLOT_SUFFIX),
|
|
968
|
-
isFinalized: existsSync(join(slotPath,
|
|
1076
|
+
isFinalized: existsSync(join(slotPath, RESULT_FILE_NAME)),
|
|
969
1077
|
recordedPrState: typeof slotPr?.state === "string" ? slotPr.state : void 0,
|
|
970
1078
|
heartbeatMtimeMs: readHeartbeatMtimeMs(slotPath)
|
|
971
1079
|
};
|
|
@@ -1023,6 +1131,166 @@ function watchGateDecision(state, unwatchedPrUrls, maxBlocks = MAX_WATCH_BLOCKS)
|
|
|
1023
1131
|
};
|
|
1024
1132
|
}
|
|
1025
1133
|
|
|
1134
|
+
// src/pr-watch/attempts.ts
|
|
1135
|
+
function recordedCount(counts, key) {
|
|
1136
|
+
const recorded = counts?.[key];
|
|
1137
|
+
return typeof recorded === "number" && Number.isFinite(recorded) ? recorded : 0;
|
|
1138
|
+
}
|
|
1139
|
+
function rebaseAttemptsFor(lastSeenEntry, rebaseKey) {
|
|
1140
|
+
return recordedCount(lastSeenEntry.conflict_resolve_attempts, rebaseKey);
|
|
1141
|
+
}
|
|
1142
|
+
function ciFixAttemptsFor(lastSeenEntry, headSha) {
|
|
1143
|
+
return recordedCount(lastSeenEntry.ci_fix_attempts, headSha);
|
|
1144
|
+
}
|
|
1145
|
+
function isRebaseKeyAttempted(lastSeenEntry, rebaseKey) {
|
|
1146
|
+
return rebaseAttemptsFor(lastSeenEntry, rebaseKey) >= 1;
|
|
1147
|
+
}
|
|
1148
|
+
function isCiHeadAttempted(lastSeenEntry, headSha) {
|
|
1149
|
+
return ciFixAttemptsFor(lastSeenEntry, headSha) >= 1;
|
|
1150
|
+
}
|
|
1151
|
+
function isRebaseBudgetExhausted(lastSeenEntry, maxCatchUpRebases) {
|
|
1152
|
+
const catchUpRebases = lastSeenEntry.catch_up_rebases;
|
|
1153
|
+
return maxCatchUpRebases !== null && typeof catchUpRebases === "number" && catchUpRebases >= maxCatchUpRebases;
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
// src/transcript/constants.ts
|
|
1157
|
+
var USER_ENTRY_TYPE = "user";
|
|
1158
|
+
var HUMAN_ORIGIN_KIND = "human";
|
|
1159
|
+
var TEXT_CONTENT_PART_TYPE = "text";
|
|
1160
|
+
var TOOL_RESULT_CONTENT_PART_TYPE = "tool_result";
|
|
1161
|
+
|
|
1162
|
+
// src/transcript/userTurns.ts
|
|
1163
|
+
function userAuthoredText(entry) {
|
|
1164
|
+
if (entry.type !== USER_ENTRY_TYPE) return null;
|
|
1165
|
+
if (entry.isMeta || entry.isCompactSummary || entry.isSidechain || entry.toolUseResult !== void 0) return null;
|
|
1166
|
+
if (entry.origin != null && entry.origin.kind !== HUMAN_ORIGIN_KIND) return null;
|
|
1167
|
+
const content = entry.message?.content;
|
|
1168
|
+
if (typeof content === "string") return content;
|
|
1169
|
+
if (!Array.isArray(content)) return null;
|
|
1170
|
+
const parts = content;
|
|
1171
|
+
if (parts.some((part) => part?.type === TOOL_RESULT_CONTENT_PART_TYPE)) return null;
|
|
1172
|
+
return parts.filter((part) => part?.type === TEXT_CONTENT_PART_TYPE && typeof part.text === "string").map((part) => part.text).join("\n");
|
|
1173
|
+
}
|
|
1174
|
+
function userAuthoredTextsContaining(transcriptJsonl, literal) {
|
|
1175
|
+
const texts = [];
|
|
1176
|
+
for (const line of transcriptJsonl.split("\n")) {
|
|
1177
|
+
if (!line.includes(literal)) continue;
|
|
1178
|
+
let entry;
|
|
1179
|
+
try {
|
|
1180
|
+
entry = JSON.parse(line);
|
|
1181
|
+
} catch {
|
|
1182
|
+
continue;
|
|
1183
|
+
}
|
|
1184
|
+
const text = userAuthoredText(entry);
|
|
1185
|
+
if (text !== null && text.includes(literal)) texts.push(text);
|
|
1186
|
+
}
|
|
1187
|
+
return texts;
|
|
1188
|
+
}
|
|
1189
|
+
function readFileTail(filePath, maxBytes) {
|
|
1190
|
+
let descriptor;
|
|
1191
|
+
try {
|
|
1192
|
+
descriptor = openSync(filePath, "r");
|
|
1193
|
+
const fileSize = fstatSync(descriptor).size;
|
|
1194
|
+
const length = Math.min(fileSize, maxBytes);
|
|
1195
|
+
const tail = Buffer.alloc(length);
|
|
1196
|
+
readSync(descriptor, tail, 0, length, fileSize - length);
|
|
1197
|
+
return tail.toString("utf-8");
|
|
1198
|
+
} catch {
|
|
1199
|
+
return null;
|
|
1200
|
+
} finally {
|
|
1201
|
+
if (descriptor !== void 0) closeSync(descriptor);
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
// src/guardrails/watchFollowThrough.ts
|
|
1206
|
+
function mtimeMsOf(filePath) {
|
|
1207
|
+
try {
|
|
1208
|
+
return statSync(filePath).mtimeMs;
|
|
1209
|
+
} catch {
|
|
1210
|
+
return void 0;
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
function isDueRecordSuperseded(slotPath, slotPr, dueRecord) {
|
|
1214
|
+
if (!slotPr.head_sha || slotPr.head_sha === dueRecord.headSha) return false;
|
|
1215
|
+
const prsWrittenAtMs = mtimeMsOf(join(slotPath, PRS_FILE_NAME));
|
|
1216
|
+
const dueWrittenAtMs = mtimeMsOf(join(slotPath, WATCH_DUE_FILE_NAME));
|
|
1217
|
+
return prsWrittenAtMs !== void 0 && dueWrittenAtMs !== void 0 && prsWrittenAtMs > dueWrittenAtMs;
|
|
1218
|
+
}
|
|
1219
|
+
function owedWorkInSlot(slotPath, slug, sessionId2, preferences) {
|
|
1220
|
+
if (slug.endsWith(STOPPED_SLOT_SUFFIX)) return [];
|
|
1221
|
+
const dueRecord = parseWatchDueRecord(readSlotText(join(slotPath, WATCH_DUE_FILE_NAME)));
|
|
1222
|
+
if (!dueRecord) return [];
|
|
1223
|
+
if (readJsonRecord(join(slotPath, OWNER_FILE_NAME)).session_id !== sessionId2) return [];
|
|
1224
|
+
if (existsSync(join(slotPath, RESULT_FILE_NAME))) return [];
|
|
1225
|
+
const slotPr = readSlotPr(slotPath);
|
|
1226
|
+
const prUrl = slotPr?.url;
|
|
1227
|
+
const prNumber = slotPr?.number;
|
|
1228
|
+
if (!slotPr?.repo || typeof prUrl !== "string" || typeof prNumber !== "number") return [];
|
|
1229
|
+
if (TERMINAL_SLOT_PR_STATES.includes((slotPr.state ?? "").toLowerCase())) return [];
|
|
1230
|
+
if (isDueRecordSuperseded(slotPath, slotPr, dueRecord)) return [];
|
|
1231
|
+
const lastSeenEntry = lastSeenEntryFor(readSlotText(join(slotPath, LAST_SEEN_FILE_NAME)), `${slotPr.repo}#${prNumber}`);
|
|
1232
|
+
const workOn = (kind, dueOn) => ({
|
|
1233
|
+
kind,
|
|
1234
|
+
slug,
|
|
1235
|
+
prUrl,
|
|
1236
|
+
prNumber,
|
|
1237
|
+
dueOn
|
|
1238
|
+
});
|
|
1239
|
+
const owed = [];
|
|
1240
|
+
const isRebaseOwed = dueRecord.rebaseDueKey !== "" && preferences.autoRebase === ALWAYS_PREFERENCE_VALUE && !isRebaseBudgetExhausted(lastSeenEntry, preferences.maxCatchUpRebases) && !isRebaseKeyAttempted(lastSeenEntry, dueRecord.rebaseDueKey);
|
|
1241
|
+
if (isRebaseOwed) owed.push(workOn("rebase" /* Rebase */, dueRecord.rebaseDueKey));
|
|
1242
|
+
if (dueRecord.ciRedHeadSha !== "" && !isCiHeadAttempted(lastSeenEntry, dueRecord.ciRedHeadSha)) {
|
|
1243
|
+
owed.push(workOn("fix-ci" /* FixCi */, dueRecord.ciRedHeadSha));
|
|
1244
|
+
}
|
|
1245
|
+
return owed;
|
|
1246
|
+
}
|
|
1247
|
+
function findOwedWatchWork(sessionId2, preferences, sessionsDirOverride) {
|
|
1248
|
+
const sessionsDir = join(homedir(), ...MUGGLE_DO_SESSIONS_PATH_SEGMENTS);
|
|
1249
|
+
let slugs;
|
|
1250
|
+
try {
|
|
1251
|
+
slugs = readdirSync(sessionsDir);
|
|
1252
|
+
} catch {
|
|
1253
|
+
return [];
|
|
1254
|
+
}
|
|
1255
|
+
return slugs.flatMap((slug) => owedWorkInSlot(join(sessionsDir, slug), slug, sessionId2, preferences));
|
|
1256
|
+
}
|
|
1257
|
+
function heldPrNumbersIn(transcriptJsonl) {
|
|
1258
|
+
const heldPrNumbers = /* @__PURE__ */ new Set();
|
|
1259
|
+
for (const userText of userAuthoredTextsContaining(transcriptJsonl, WATCH_HOLD_PHRASE_PREFIX)) {
|
|
1260
|
+
for (const hold of userText.matchAll(WATCH_HOLD_INSTRUCTION)) heldPrNumbers.add(Number(hold[1]));
|
|
1261
|
+
}
|
|
1262
|
+
return [...heldPrNumbers];
|
|
1263
|
+
}
|
|
1264
|
+
function applyWatchHolds(state, heldPrNumbers) {
|
|
1265
|
+
const recorded = state.watchHeldPrNumbers ?? [];
|
|
1266
|
+
const newlyHeld = heldPrNumbers.filter((prNumber) => !recorded.includes(prNumber));
|
|
1267
|
+
if (newlyHeld.length === 0) return state;
|
|
1268
|
+
return { ...state, watchHeldPrNumbers: [...recorded, ...newlyHeld] };
|
|
1269
|
+
}
|
|
1270
|
+
function watchFollowThroughDecision(state, owedWork) {
|
|
1271
|
+
const heldPrNumbers = state.watchHeldPrNumbers ?? [];
|
|
1272
|
+
const owed = owedWork.filter((work) => !heldPrNumbers.includes(work.prNumber));
|
|
1273
|
+
const blockCount = state.watchFollowThroughBlockCount ?? 0;
|
|
1274
|
+
if (owed.length === 0) return { action: "none" /* None */, blockCount, owed };
|
|
1275
|
+
return { action: "block" /* Block */, blockCount: blockCount + 1, owed };
|
|
1276
|
+
}
|
|
1277
|
+
function parseMaxCatchUpRebases(configuredValue) {
|
|
1278
|
+
if (configuredValue === UNBOUNDED_PREFERENCE_VALUE) return null;
|
|
1279
|
+
const spelled = typeof configuredValue === "number" ? String(configuredValue) : configuredValue;
|
|
1280
|
+
return typeof spelled === "string" && POSITIVE_INTEGER.test(spelled) ? Number(spelled) : void 0;
|
|
1281
|
+
}
|
|
1282
|
+
function resolveWatchPreferences(homeDir = homedir(), pluginRoot = resolvePluginRoot()) {
|
|
1283
|
+
const shippedDefaults = readJsonRecord(join(pluginRoot, ...PREFERENCE_DEFAULTS_PATH_SEGMENTS));
|
|
1284
|
+
const userPreferences = asRecord(readJsonRecord(join(homeDir, ...USER_PREFERENCES_PATH_SEGMENTS)).preferences);
|
|
1285
|
+
const autoRebase = userPreferences[AUTO_REBASE_PREFERENCE_KEY] ?? shippedDefaults[AUTO_REBASE_PREFERENCE_KEY];
|
|
1286
|
+
const userCap = parseMaxCatchUpRebases(userPreferences[MAX_CATCH_UP_REBASES_PREFERENCE_KEY]);
|
|
1287
|
+
const shippedCap = parseMaxCatchUpRebases(shippedDefaults[MAX_CATCH_UP_REBASES_PREFERENCE_KEY]);
|
|
1288
|
+
return {
|
|
1289
|
+
autoRebase: typeof autoRebase === "string" ? autoRebase : void 0,
|
|
1290
|
+
maxCatchUpRebases: userCap !== void 0 ? userCap : shippedCap ?? null
|
|
1291
|
+
};
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1026
1294
|
// src/guardrails/buildFollowthrough.ts
|
|
1027
1295
|
var BUILD_SKIP_MARKER = /^\s*echo\s+["']?MUGGLE_BUILD_SKIP\b/;
|
|
1028
1296
|
function isBuildSkipMarker(cmd) {
|
|
@@ -1095,14 +1363,53 @@ function detectWalkthroughPost(input2, read = defaultFileReader) {
|
|
|
1095
1363
|
if (callFailed(input2)) return false;
|
|
1096
1364
|
return collectPrPostText(cmd, input2.cwd, read).includes(REPORT_SENTINEL);
|
|
1097
1365
|
}
|
|
1098
|
-
function
|
|
1099
|
-
|
|
1100
|
-
|
|
1366
|
+
function detectWalkthroughPostTargets(input2) {
|
|
1367
|
+
return extractPrUrls(`${input2.tool_response?.stdout ?? ""}
|
|
1368
|
+
${input2.tool_response?.output ?? ""}`);
|
|
1369
|
+
}
|
|
1370
|
+
function applyWalkthroughPosted(state, posted, postedAt, targetPrUrls) {
|
|
1371
|
+
if (!posted) return state;
|
|
1372
|
+
if (targetPrUrls.length === 0) return { ...state, walkthroughPostedAt: postedAt };
|
|
1373
|
+
const postedPrUrls = /* @__PURE__ */ new Set([...state.walkthroughPostedPrUrls ?? [], ...targetPrUrls]);
|
|
1374
|
+
return { ...state, walkthroughPostedPrUrls: [...postedPrUrls] };
|
|
1101
1375
|
}
|
|
1102
1376
|
function applyWalkthroughSkip(state, skipped) {
|
|
1103
1377
|
if (!skipped || state.walkthroughSkipped === true) return state;
|
|
1104
1378
|
return { ...state, walkthroughSkipped: true };
|
|
1105
1379
|
}
|
|
1380
|
+
function normalizeWorkingTree(cwd) {
|
|
1381
|
+
if (!cwd) return void 0;
|
|
1382
|
+
const forwardSlashed = resolve(cwd).replace(/\\/g, "/").replace(/\/+$/, "");
|
|
1383
|
+
return process.platform === "win32" ? forwardSlashed.toLowerCase() : forwardSlashed;
|
|
1384
|
+
}
|
|
1385
|
+
function isOpenedFromSkipTree(state, prUrl) {
|
|
1386
|
+
const skipTree = state.e2eSkipVerifiedInTree;
|
|
1387
|
+
return skipTree !== void 0 && state.prWorkingTrees?.[prUrl] === skipTree;
|
|
1388
|
+
}
|
|
1389
|
+
function withCoveredPrs(state, prUrls) {
|
|
1390
|
+
const covered = new Set(state.e2eSkipCoveredPrs ?? []);
|
|
1391
|
+
const uncovered = prUrls.filter((prUrl) => !covered.has(prUrl));
|
|
1392
|
+
if (uncovered.length === 0) return state;
|
|
1393
|
+
return { ...state, e2eSkipCoveredPrs: [...covered, ...uncovered] };
|
|
1394
|
+
}
|
|
1395
|
+
function isPrCoveredBySkip(state, prUrl) {
|
|
1396
|
+
return (state.e2eSkipCoveredPrs ?? []).includes(prUrl);
|
|
1397
|
+
}
|
|
1398
|
+
function applyPrOpenedToSkipScope(state, prUrl, openedFromTree) {
|
|
1399
|
+
if (!openedFromTree) return state;
|
|
1400
|
+
const recorded = { ...state, prWorkingTrees: { ...state.prWorkingTrees, [prUrl]: openedFromTree } };
|
|
1401
|
+
return isOpenedFromSkipTree(recorded, prUrl) && recorded.e2eSkipDeclaration ? withCoveredPrs(recorded, [prUrl]) : recorded;
|
|
1402
|
+
}
|
|
1403
|
+
function applyE2eSkipScope(state, verifiedInTree) {
|
|
1404
|
+
if (!verifiedInTree || !state.e2eSkipDeclaration) return state;
|
|
1405
|
+
const scoped = { ...state, e2eSkipVerifiedInTree: verifiedInTree };
|
|
1406
|
+
return withCoveredPrs(
|
|
1407
|
+
scoped,
|
|
1408
|
+
scoped.prsHandled.filter((prUrl) => isOpenedFromSkipTree(scoped, prUrl))
|
|
1409
|
+
);
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
// src/guardrails/walkthroughOwed.ts
|
|
1106
1413
|
function runGh(args) {
|
|
1107
1414
|
const timeoutMs = boundedChildTimeoutMs(GH_LOOKUP_TIMEOUT_MS);
|
|
1108
1415
|
if (timeoutMs === null) return null;
|
|
@@ -1135,10 +1442,10 @@ function scanForOwedWalkthroughs(state, lookup = defaultPrWalkthroughLookup) {
|
|
|
1135
1442
|
const candidates = new Set(state.prsHandled);
|
|
1136
1443
|
const branchPrUrl = lookup.branchPrUrl();
|
|
1137
1444
|
if (branchPrUrl) candidates.add(branchPrUrl);
|
|
1138
|
-
const acceptsSkip = state.e2eRun !== true;
|
|
1139
1445
|
const owed = [];
|
|
1140
1446
|
const verified2 = [];
|
|
1141
1447
|
for (const prUrl of candidates) {
|
|
1448
|
+
const acceptsSkip = state.e2eRun !== true || isPrCoveredBySkip(state, prUrl);
|
|
1142
1449
|
if (lookup.prCarriesWalkthrough(prUrl, acceptsSkip)) verified2.push(prUrl);
|
|
1143
1450
|
else owed.push(prUrl);
|
|
1144
1451
|
}
|
|
@@ -1147,11 +1454,22 @@ function scanForOwedWalkthroughs(state, lookup = defaultPrWalkthroughLookup) {
|
|
|
1147
1454
|
function isWalkthroughGateArmed(state) {
|
|
1148
1455
|
const isSkipUnsettled = state.e2eSkipDeclaration !== void 0 && state.e2eSkipSettledOnPrs !== true;
|
|
1149
1456
|
const isOwed = state.e2eRun === true || isSkipUnsettled;
|
|
1150
|
-
return isOwed && state.
|
|
1457
|
+
return isOwed && state.walkthroughsVerified !== true && state.walkthroughSkipped !== true;
|
|
1151
1458
|
}
|
|
1152
1459
|
function isWalkthroughScanCurrent(scan, state) {
|
|
1153
1460
|
const scanned = new Set(scan.prsHandled);
|
|
1154
|
-
|
|
1461
|
+
const coversHandledPrs = scanned.size === new Set(state.prsHandled).size && state.prsHandled.every((prUrl) => scanned.has(prUrl));
|
|
1462
|
+
const postedAt = state.walkthroughPostedAt;
|
|
1463
|
+
const followsLastPost = postedAt === void 0 || (scan.startedAt ?? 0) >= postedAt;
|
|
1464
|
+
return coversHandledPrs && followsLastPost;
|
|
1465
|
+
}
|
|
1466
|
+
function withoutPostedPrs(prUrls, state) {
|
|
1467
|
+
const postedPrUrls = new Set(state.walkthroughPostedPrUrls ?? []);
|
|
1468
|
+
return prUrls.filter((prUrl) => !postedPrUrls.has(prUrl));
|
|
1469
|
+
}
|
|
1470
|
+
function applyPrOpenedToWalkthroughs(state) {
|
|
1471
|
+
if (state.walkthroughsVerified !== true && state.e2eSkipSettledOnPrs !== true) return state;
|
|
1472
|
+
return { ...state, walkthroughsVerified: false, e2eSkipSettledOnPrs: false };
|
|
1155
1473
|
}
|
|
1156
1474
|
function walkthroughGateDecision(state, owedPrUrls, maxBlocks = MAX_WALKTHROUGH_BLOCKS) {
|
|
1157
1475
|
const blockCount = state.walkthroughBlockCount ?? 0;
|
|
@@ -1397,17 +1715,7 @@ var verifyUserWaived = (context) => {
|
|
|
1397
1715
|
const transcript = context.probe.readTextFile(context.transcriptPath);
|
|
1398
1716
|
if (!transcript) return refuted("the transcript could not be read");
|
|
1399
1717
|
const tail = transcript.slice(-64e3);
|
|
1400
|
-
|
|
1401
|
-
if (!line.includes(USER_WAIVE_PHRASE)) return false;
|
|
1402
|
-
try {
|
|
1403
|
-
const entry = JSON.parse(line);
|
|
1404
|
-
const isUserTurn = entry.type === "user" || entry.message?.role === "user";
|
|
1405
|
-
return isUserTurn && JSON.stringify(entry.message?.content ?? "").includes(USER_WAIVE_PHRASE);
|
|
1406
|
-
} catch {
|
|
1407
|
-
return false;
|
|
1408
|
-
}
|
|
1409
|
-
});
|
|
1410
|
-
if (waived) return verified;
|
|
1718
|
+
if (userAuthoredTextsContaining(tail, USER_WAIVE_PHRASE).length > 0) return verified;
|
|
1411
1719
|
return refuted(`no user turn in the transcript contains "${USER_WAIVE_PHRASE}"`);
|
|
1412
1720
|
};
|
|
1413
1721
|
var namePaths = (paths) => {
|
|
@@ -1757,17 +2065,11 @@ function threadForReplyTarget(ledger, targetId) {
|
|
|
1757
2065
|
return void 0;
|
|
1758
2066
|
}
|
|
1759
2067
|
function resolveSlotForPr(prUrl, sessionsDirOverride) {
|
|
1760
|
-
const sessionsDir = join(homedir(),
|
|
2068
|
+
const sessionsDir = join(homedir(), ...MUGGLE_DO_SESSIONS_PATH_SEGMENTS);
|
|
1761
2069
|
if (!existsSync(sessionsDir)) return void 0;
|
|
1762
2070
|
for (const slug of readdirSync(sessionsDir)) {
|
|
1763
2071
|
const slotPath = join(sessionsDir, slug);
|
|
1764
|
-
|
|
1765
|
-
const parsed = JSON.parse(readFileSync(join(slotPath, "prs.json"), "utf-8"));
|
|
1766
|
-
const slotPr = Array.isArray(parsed) ? parsed[0] : parsed;
|
|
1767
|
-
if (slotPr?.url === prUrl) return slotPath;
|
|
1768
|
-
} catch {
|
|
1769
|
-
continue;
|
|
1770
|
-
}
|
|
2072
|
+
if (readSlotPr(slotPath)?.url === prUrl) return slotPath;
|
|
1771
2073
|
}
|
|
1772
2074
|
return void 0;
|
|
1773
2075
|
}
|
|
@@ -1951,8 +2253,12 @@ function prOpened() {
|
|
|
1951
2253
|
if (!url) return "{}";
|
|
1952
2254
|
if (readState(sessionId).prsHandled.includes(url)) return "{}";
|
|
1953
2255
|
markPrHandled(sessionId, url);
|
|
1954
|
-
const
|
|
1955
|
-
const
|
|
2256
|
+
const openedFromTree = normalizeWorkingTree(input.cwd);
|
|
2257
|
+
const stateAfterOpen = commitState(
|
|
2258
|
+
sessionId,
|
|
2259
|
+
(state) => applyPrOpenedToSkipScope(applyPrOpenedToWalkthroughs(state), url, openedFromTree)
|
|
2260
|
+
) ?? readState(sessionId);
|
|
2261
|
+
const declaredSkip = isPrCoveredBySkip(stateAfterOpen, url) ? stateAfterOpen.e2eSkipDeclaration : void 0;
|
|
1956
2262
|
if (declaredSkip) {
|
|
1957
2263
|
startBackgroundJob("settle-walkthrough-skipped" /* SettleWalkthroughSkipped */, [url, declaredSkip.code, declaredSkip.detail]);
|
|
1958
2264
|
} else {
|
|
@@ -1962,7 +2268,7 @@ function prOpened() {
|
|
|
1962
2268
|
startBackgroundJob("scan-walkthroughs" /* ScanWalkthroughs */, [sessionId], input.cwd);
|
|
1963
2269
|
}
|
|
1964
2270
|
const slotNote = declaredSkip ? `Its Muggle AI visual-walkthrough comment is being settled with the E2E skip already recorded this session (${declaredSkip.code}); the turn cannot end until the PR shows it.
|
|
1965
|
-
` : `Its Muggle AI visual-walkthrough comment is reserved and empty \u2014 settle it
|
|
2271
|
+
` : `Its Muggle AI visual-walkthrough comment is reserved and empty \u2014 settle it with the E2E run of this PR's own change (a wave's PRs share one run; any other PR gets its own), or by recording why E2E does not apply from this PR's working tree.
|
|
1966
2272
|
`;
|
|
1967
2273
|
const ctx = `A pull request was just opened: ${url}
|
|
1968
2274
|
` + slotNote + `Per the autoWatchPR preference, a muggle-pr-followup watcher should handle its incoming reviews. If autoWatchPR=always, start it now by invoking ${muggleSkill("/muggle:muggle-pr-followup")} with the PR URL; if =ask, offer it to the user; if =never, do nothing.`;
|
|
@@ -2005,8 +2311,8 @@ function terminalGate() {
|
|
|
2005
2311
|
const reason = decision.blockCount === 1 ? `Do not end the turn yet. PR ${pendingPrList} went terminal (merged/closed) but the post-merge handoff has not run. Finalize the watcher slot, tear down per autoCleanup, then offer next options to the user ${nextOptionsOfferMethod()} \u2014 release, queued work, deferred items. Only that offer clears this gate.` : `Post-merge handoff still owed for PR ${pendingPrList} (reminder ${decision.blockCount}/${MAX_PR_TERMINAL_BLOCKS}): finalize + tear down, then offer the next options ${nextOptionsOfferMethod()}.`;
|
|
2006
2312
|
return blockStop(reason, host);
|
|
2007
2313
|
}
|
|
2008
|
-
function startWalkthroughScanOnGateArming(stateBefore, committed) {
|
|
2009
|
-
if (isWalkthroughGateArmed(committed) && !isWalkthroughGateArmed(stateBefore)) {
|
|
2314
|
+
function startWalkthroughScanOnGateArming(stateBefore, committed, hasPosted = false) {
|
|
2315
|
+
if (isWalkthroughGateArmed(committed) && (hasPosted || !isWalkthroughGateArmed(stateBefore))) {
|
|
2010
2316
|
startBackgroundJob("scan-walkthroughs" /* ScanWalkthroughs */, [sessionId], input.cwd);
|
|
2011
2317
|
}
|
|
2012
2318
|
}
|
|
@@ -2022,17 +2328,25 @@ function recordTests() {
|
|
|
2022
2328
|
e2eSkipCycleScoped: acceptedSkip !== null && CYCLE_SCOPED_SKIP_CODES.includes(acceptedSkip.code)
|
|
2023
2329
|
};
|
|
2024
2330
|
const walkthroughPosted = detectWalkthroughPost(input);
|
|
2331
|
+
const walkthroughPostTargets = walkthroughPosted ? detectWalkthroughPostTargets(input) : [];
|
|
2025
2332
|
const failedRunId = detectFailedRunId(input);
|
|
2333
|
+
const isDeclaredHere = acceptedSkip !== null && !CYCLE_SCOPED_SKIP_CODES.includes(acceptedSkip.code);
|
|
2026
2334
|
const record = (state) => {
|
|
2027
|
-
const
|
|
2335
|
+
const declared = applyE2eSkipDeclaration(applyRecordedRun(state, run), acceptedSkip);
|
|
2336
|
+
const recorded = isDeclaredHere ? applyE2eSkipScope(declared, normalizeWorkingTree(input.cwd)) : declared;
|
|
2028
2337
|
const withWatchSkip = applyWatchSkip(recorded, isWatchSkipMarker(cmd));
|
|
2029
2338
|
const withBuildSkip = applyBuildSkip(withWatchSkip, isBuildSkipMarker(cmd));
|
|
2030
|
-
const withWalkthroughPost = applyWalkthroughPosted(
|
|
2339
|
+
const withWalkthroughPost = applyWalkthroughPosted(
|
|
2340
|
+
withBuildSkip,
|
|
2341
|
+
walkthroughPosted,
|
|
2342
|
+
Date.now(),
|
|
2343
|
+
walkthroughPostTargets
|
|
2344
|
+
);
|
|
2031
2345
|
const withWalkthroughSkip = applyWalkthroughSkip(withWalkthroughPost, isWalkthroughSkipMarker(cmd));
|
|
2032
2346
|
return failedRunId ? applyFailedRun(withWalkthroughSkip, failedRunId) : withWalkthroughSkip;
|
|
2033
2347
|
};
|
|
2034
2348
|
const next = commitState(sessionId, record) ?? record(readState(sessionId));
|
|
2035
|
-
startWalkthroughScanOnGateArming(stateBefore, next);
|
|
2349
|
+
startWalkthroughScanOnGateArming(stateBefore, next, walkthroughPosted);
|
|
2036
2350
|
if (acceptedSkip) recordSkipReasonOnPrs(next, acceptedSkip);
|
|
2037
2351
|
if (judgedSkip && !judgedSkip.accepted) {
|
|
2038
2352
|
return envelope("PostToolUse", explainRejection(judgedSkip), host);
|
|
@@ -2044,9 +2358,17 @@ function recordSkipReasonOnPrs(state, skip) {
|
|
|
2044
2358
|
startBackgroundJob("settle-walkthrough-no-app-logic-change" /* SettleWalkthroughNoAppLogicChange */, [skip.detail], input.cwd);
|
|
2045
2359
|
return;
|
|
2046
2360
|
}
|
|
2047
|
-
for (const prUrl of state.prsHandled) {
|
|
2361
|
+
for (const prUrl of state.prsHandled.filter((handledPrUrl) => isPrCoveredBySkip(state, handledPrUrl))) {
|
|
2048
2362
|
startBackgroundJob("settle-walkthrough-skipped" /* SettleWalkthroughSkipped */, [prUrl, skip.code, skip.detail]);
|
|
2049
2363
|
}
|
|
2364
|
+
startBackgroundJob("settle-branch-walkthrough-skipped" /* SettleBranchWalkthroughSkipped */, [skip.code, skip.detail], input.cwd);
|
|
2365
|
+
}
|
|
2366
|
+
function recordDelegation() {
|
|
2367
|
+
const prUrls = detectBackgroundAcceptanceDispatch(input);
|
|
2368
|
+
if (prUrls === null) return "{}";
|
|
2369
|
+
const delegate = (state) => applyE2eDelegation(state, { dispatchedAt: Date.now(), prUrls });
|
|
2370
|
+
updateState(sessionId, delegate);
|
|
2371
|
+
return "{}";
|
|
2050
2372
|
}
|
|
2051
2373
|
function skillStages() {
|
|
2052
2374
|
const skillName = resolveSkillNameFromToolInput(input.tool_input);
|
|
@@ -2156,6 +2478,42 @@ function watchGate() {
|
|
|
2156
2478
|
const reason = decision.blockCount === 1 ? `Do not end the turn yet. A PR opened this session is open with no live muggle-pr-followup watch: ${prList}. Arm its watch per the muggle-pr-followup arming procedure (arm-watcher.md) \u2014 invoking ${armCommand} bootstraps it and arms it that way (add --resume when its slot already exists). A seeded slot does not count: only a running watch loop does, shown by a watch-heartbeat it touches every poll and that goes stale after ${staleMinutes} minutes (a watch armed moments ago writes it on its first poll). If the PR already merged or closed, end the turn again \u2014 a provider check started now clears it. If it genuinely should not be watched (autoWatchPR=never, handed off elsewhere), tell the user why and run \`echo "MUGGLE_WATCH_SKIP: <reason>"\` \u2014 that records the skip and keeps this gate quiet for the rest of the session.` : `PR watch still owed for ${prList} (reminder ${decision.blockCount}/${MAX_WATCH_BLOCKS}): arm it per arm-watcher.md via ${armCommand} (--resume when its slot exists), or record a legitimate skip via \`echo "MUGGLE_WATCH_SKIP: <reason>"\`.`;
|
|
2157
2479
|
return blockStop(reason, host);
|
|
2158
2480
|
}
|
|
2481
|
+
function owedWatchWorkLine(work) {
|
|
2482
|
+
const muggleDo = muggleSkill("/muggle-do");
|
|
2483
|
+
if (work.kind === "rebase" /* Rebase */) {
|
|
2484
|
+
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}\`.`;
|
|
2485
|
+
}
|
|
2486
|
+
return `- PR #${work.prNumber} (${work.prUrl}) has red CI on head ${work.dueOn.slice(0, 8)} and no fix was attempted: dispatch \`${muggleDo} fix ci <red checks> on ${work.prUrl} slug=${work.slug}\` \u2014 the tick \`${muggleSkill("/muggle:muggle-pr-followup")} ${work.slug} ${work.prNumber} --wake=follow-through\` names the checks.`;
|
|
2487
|
+
}
|
|
2488
|
+
function watchFollowThroughGate() {
|
|
2489
|
+
const owedWork = findOwedWatchWork(sessionId, resolveWatchPreferences());
|
|
2490
|
+
const stateBefore = readState(sessionId);
|
|
2491
|
+
const transcriptTail = watchFollowThroughDecision(stateBefore, owedWork).action === "block" /* Block */ && input.transcript_path ? readFileTail(input.transcript_path, WATCH_HOLD_TRANSCRIPT_TAIL_BYTES) : null;
|
|
2492
|
+
const heldPrNumbers = transcriptTail ? heldPrNumbersIn(transcriptTail) : [];
|
|
2493
|
+
const state = applyWatchHolds(stateBefore, heldPrNumbers);
|
|
2494
|
+
const decision = watchFollowThroughDecision(state, owedWork);
|
|
2495
|
+
if (decision.action === "none" /* None */) {
|
|
2496
|
+
if (state !== stateBefore || (state.watchFollowThroughBlockCount ?? 0) > 0) {
|
|
2497
|
+
updateState(sessionId, (current) => ({
|
|
2498
|
+
...applyWatchHolds(current, heldPrNumbers),
|
|
2499
|
+
watchFollowThroughBlockCount: 0
|
|
2500
|
+
}));
|
|
2501
|
+
}
|
|
2502
|
+
return "{}";
|
|
2503
|
+
}
|
|
2504
|
+
updateState(sessionId, (current) => ({
|
|
2505
|
+
...applyWatchHolds(current, heldPrNumbers),
|
|
2506
|
+
watchFollowThroughBlockCount: decision.blockCount
|
|
2507
|
+
}));
|
|
2508
|
+
const owedList = decision.owed.map(owedWatchWorkLine).join("\n");
|
|
2509
|
+
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.`;
|
|
2510
|
+
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:
|
|
2511
|
+
${owedList}
|
|
2512
|
+
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 \u2014 if the tick finds actionable review feedback it dispatches that first. A recorded attempt (conflict_resolve_attempts / ci_fix_attempts) or a new head clears this; an escalation entry with no attempt behind it does not, and neither does re-arming the watch. ${holdInstruction}` : `Watcher work still owed (reminder ${decision.blockCount}):
|
|
2513
|
+
${owedList}
|
|
2514
|
+
${holdInstruction}`;
|
|
2515
|
+
return blockStop(reason, host);
|
|
2516
|
+
}
|
|
2159
2517
|
function buildFollowthroughGate() {
|
|
2160
2518
|
const state = readState(sessionId);
|
|
2161
2519
|
const decision = buildFollowthroughDecision(state);
|
|
@@ -2172,21 +2530,25 @@ function walkthroughGate() {
|
|
|
2172
2530
|
const scan = readWalkthroughScan(sessionId);
|
|
2173
2531
|
startBackgroundJob("scan-walkthroughs" /* ScanWalkthroughs */, [sessionId], input.cwd);
|
|
2174
2532
|
if (!scan || !isWalkthroughScanCurrent(scan, state)) return "{}";
|
|
2175
|
-
const
|
|
2176
|
-
if (
|
|
2177
|
-
if (scan.verified.length > 0) {
|
|
2178
|
-
writeState(
|
|
2533
|
+
const unposted = withoutPostedPrs(scan.owed, state);
|
|
2534
|
+
if (unposted.length === 0) {
|
|
2535
|
+
if (scan.verified.length + scan.owed.length > 0) {
|
|
2536
|
+
writeState(state.e2eRun === true ? { ...state, walkthroughsVerified: true } : { ...state, e2eSkipSettledOnPrs: true });
|
|
2179
2537
|
}
|
|
2180
2538
|
return "{}";
|
|
2181
2539
|
}
|
|
2182
|
-
const decision = walkthroughGateDecision(state,
|
|
2540
|
+
const decision = walkthroughGateDecision(state, withoutDelegatedPrs(unposted, state, Date.now()));
|
|
2183
2541
|
if (decision.action === "release" /* Release */) return releaseGate("walkthroughReleased");
|
|
2184
2542
|
if (decision.action !== "block" /* Block */) return "{}";
|
|
2185
2543
|
state.walkthroughBlockCount = decision.blockCount;
|
|
2186
2544
|
writeState(state);
|
|
2545
|
+
const declaredSkip = state.e2eSkipDeclaration;
|
|
2546
|
+
const skipOwedPrUrls = declaredSkip ? decision.owed.filter((prUrl) => isPrCoveredBySkip(state, prUrl)) : [];
|
|
2547
|
+
if (declaredSkip && skipOwedPrUrls.length > 0) {
|
|
2548
|
+
return blockOnUnsettledSkip(declaredSkip, skipOwedPrUrls, decision.blockCount);
|
|
2549
|
+
}
|
|
2187
2550
|
const prList = decision.owed.join(", ");
|
|
2188
|
-
|
|
2189
|
-
const reason = decision.blockCount === 1 ? `Do not end the turn yet. An E2E acceptance run happened this session but no visual walkthrough has reached ${prList}. Per the postPRVisualWalkthrough preference (default: always), post it now via ${muggleSkill("/muggle:muggle-pr-visual-walkthrough")} \u2014 include the failed runs, which are the ones reviewers most need to see. If this result genuinely should not be posted (postPRVisualWalkthrough=never, someone else's PR, nothing renderable), tell the user why and run \`echo "MUGGLE_WALKTHROUGH_SKIP: <reason>"\` \u2014 that records the skip and keeps this gate quiet for the rest of the session.` : `Walkthrough still owed for ${prList} (reminder ${decision.blockCount}/${MAX_WALKTHROUGH_BLOCKS}): post via ${muggleSkill("/muggle:muggle-pr-visual-walkthrough")}, or record a legitimate skip via \`echo "MUGGLE_WALKTHROUGH_SKIP: <reason>"\`.`;
|
|
2551
|
+
const reason = decision.blockCount === 1 ? `Do not end the turn yet. No visual walkthrough or skip record has reached ${prList}. Each PR carries the run of its own change \u2014 a wave's PRs share one run, every other PR gets its own \u2014 so never post one change's run to another change's PR. If this PR's change was tested, post that run now per the postPRVisualWalkthrough preference (default: always) via ${muggleSkill("/muggle:muggle-pr-visual-walkthrough")} \u2014 include the failed runs, which are the ones reviewers most need to see. If it was not, run E2E for it first: inline via ${muggleSkill("/muggle:muggle-test")}, or in a background muggle:acceptance-tester per do/background-e2e.md while other work continues \u2014 or, where E2E cannot apply to it, declare the skip from that PR's own working tree, since a skip settles only the PRs of the tree it was verified in. If this result genuinely should not be posted (postPRVisualWalkthrough=never, someone else's PR, nothing renderable), tell the user why and run \`echo "MUGGLE_WALKTHROUGH_SKIP: <reason>"\` \u2014 that records the skip and keeps this gate quiet for the rest of the session.` : `Walkthrough still owed for ${prList} (reminder ${decision.blockCount}/${MAX_WALKTHROUGH_BLOCKS}): post that PR's own run via ${muggleSkill("/muggle:muggle-pr-visual-walkthrough")}, run E2E for it first if its change was never tested, or record a legitimate skip via \`echo "MUGGLE_WALKTHROUGH_SKIP: <reason>"\`.`;
|
|
2190
2552
|
return blockStop(reason, host);
|
|
2191
2553
|
}
|
|
2192
2554
|
function blockOnUnsettledSkip(owedSkip, owedPrUrls, blockCount) {
|
|
@@ -2316,9 +2678,11 @@ var handlers = {
|
|
|
2316
2678
|
"pr-terminal": prTerminal,
|
|
2317
2679
|
"offer-ran": offerRan,
|
|
2318
2680
|
"record-tests": recordTests,
|
|
2681
|
+
"record-delegation": recordDelegation,
|
|
2319
2682
|
"e2e-gate": e2eGate,
|
|
2320
2683
|
"terminal-gate": terminalGate,
|
|
2321
2684
|
"watch-gate": watchGate,
|
|
2685
|
+
"watch-follow-through-gate": watchFollowThroughGate,
|
|
2322
2686
|
"build-followthrough-gate": buildFollowthroughGate,
|
|
2323
2687
|
"walkthrough-gate": walkthroughGate,
|
|
2324
2688
|
"record-comment-replies": recordCommentReplies,
|
|
@@ -2337,9 +2701,15 @@ var handlers = {
|
|
|
2337
2701
|
var jobArgs = process.argv.slice(3);
|
|
2338
2702
|
function scanWalkthroughsJob() {
|
|
2339
2703
|
const scannedSessionId = jobArgs[0] ?? "unknown";
|
|
2704
|
+
const startedAt = Date.now();
|
|
2340
2705
|
const state = readState(scannedSessionId);
|
|
2341
2706
|
const scan = scanForOwedWalkthroughs(state);
|
|
2342
|
-
writeWalkthroughScan(scannedSessionId, {
|
|
2707
|
+
writeWalkthroughScan(scannedSessionId, {
|
|
2708
|
+
prsHandled: state.prsHandled,
|
|
2709
|
+
owed: scan.owed,
|
|
2710
|
+
verified: scan.verified,
|
|
2711
|
+
startedAt
|
|
2712
|
+
});
|
|
2343
2713
|
return "{}";
|
|
2344
2714
|
}
|
|
2345
2715
|
function reserveWalkthroughCommentJob() {
|
|
@@ -2355,6 +2725,14 @@ function settleWalkthroughSkippedJob() {
|
|
|
2355
2725
|
settleWalkthroughCommentAsSkipped(prUrl, skip.code, skip.detail);
|
|
2356
2726
|
return JSON.stringify({ settled: isWalkthroughSettledOnPr(prUrl) });
|
|
2357
2727
|
}
|
|
2728
|
+
function settleBranchWalkthroughSkippedJob() {
|
|
2729
|
+
const [codeArg, detail] = jobArgs;
|
|
2730
|
+
const code = E2E_SKIP_CODES.find((skipCode) => skipCode === codeArg);
|
|
2731
|
+
if (!code) return "{}";
|
|
2732
|
+
const prUrl = defaultPrWalkthroughLookup.branchPrUrl();
|
|
2733
|
+
if (prUrl) settleWalkthroughCommentAsSkipped(prUrl, code, detail ?? "");
|
|
2734
|
+
return "{}";
|
|
2735
|
+
}
|
|
2358
2736
|
function settleWalkthroughUnreasonedJob() {
|
|
2359
2737
|
const [prUrl] = jobArgs;
|
|
2360
2738
|
if (prUrl) settleWalkthroughCommentAsUnreasoned(prUrl);
|
|
@@ -2380,6 +2758,7 @@ var backgroundJobs = {
|
|
|
2380
2758
|
["scan-walkthroughs" /* ScanWalkthroughs */]: scanWalkthroughsJob,
|
|
2381
2759
|
["reserve-walkthrough-comment" /* ReserveWalkthroughComment */]: reserveWalkthroughCommentJob,
|
|
2382
2760
|
["settle-walkthrough-skipped" /* SettleWalkthroughSkipped */]: settleWalkthroughSkippedJob,
|
|
2761
|
+
["settle-branch-walkthrough-skipped" /* SettleBranchWalkthroughSkipped */]: settleBranchWalkthroughSkippedJob,
|
|
2383
2762
|
["settle-walkthrough-unreasoned" /* SettleWalkthroughUnreasoned */]: settleWalkthroughUnreasonedJob,
|
|
2384
2763
|
["settle-walkthrough-no-app-logic-change" /* SettleWalkthroughNoAppLogicChange */]: settleWalkthroughNoAppLogicChangeJob,
|
|
2385
2764
|
["scan-watch-pr-states" /* ScanWatchPrStates */]: scanWatchPrStatesJob
|