@muggleai/works 5.26.0-staging.214 → 5.26.0-staging.215

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.
@@ -9,7 +9,7 @@
9
9
  "name": "muggleai",
10
10
  "source": "./plugin",
11
11
  "description": "Real-browser E2E acceptance for your coding agent: test the flows you changed and open the PR with screenshots. Built for flows other tools can't reach: managed test identities with live inboxes (magic links, email OTP and 2FA, verification mail, password resets), an encrypted secret store for login and test credentials, and a test graph that runs prerequisite flows first. Plain-English tests become replayable scripts on localhost or preview URLs.",
12
- "version": "5.26.0-staging.214"
12
+ "version": "5.26.0-staging.215"
13
13
  }
14
14
  ]
15
15
  }
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { runCli } from './chunk-3RNJ666J.js';
2
+ import { runCli } from './chunk-FP5PRYGP.js';
3
3
  import './chunk-MJ34HBWC.js';
4
4
 
5
5
  // src/cli/main.ts
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { src_exports as commands, createUnifiedMcpServer, server_exports as server } from './chunk-3RNJ666J.js';
1
+ export { src_exports as commands, createUnifiedMcpServer, server_exports as server } from './chunk-FP5PRYGP.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-MJ34HBWC.js';
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "muggle",
3
3
  "description": "Real-browser E2E acceptance for your coding agent: test the flows you changed and open the PR with screenshots. Built for flows other tools can't reach: managed test identities with live inboxes (magic links, email OTP and 2FA, verification mail, password resets), an encrypted secret store for login and test credentials, and a test graph that runs prerequisite flows first. Plain-English tests become replayable scripts on localhost or preview URLs.",
4
- "version": "5.26.0-staging.214",
4
+ "version": "5.26.0-staging.215",
5
5
  "author": {
6
6
  "name": "Muggle AI",
7
7
  "email": "support@muggle-ai.com"
@@ -4,7 +4,7 @@
4
4
  "command": "npx",
5
5
  "args": [
6
6
  "-y",
7
- "@muggleai/works@5.26.0-staging.214",
7
+ "@muggleai/works@5.26.0-staging.215",
8
8
  "serve"
9
9
  ],
10
10
  "env": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muggle",
3
- "version": "5.26.0-staging.214",
3
+ "version": "5.26.0-staging.215",
4
4
  "description": "Real-browser E2E acceptance for your coding agent: test the flows you changed and open the PR with screenshots. Built for flows other tools can't reach: managed test identities with live inboxes (magic links, email OTP and 2FA, verification mail, password resets), an encrypted secret store for login and test credentials, and a test graph that runs prerequisite flows first. Plain-English tests become replayable scripts on localhost or preview URLs.",
5
5
  "author": {
6
6
  "name": "Muggle AI",
@@ -2,7 +2,7 @@
2
2
  "name": "muggle",
3
3
  "displayName": "Muggle AI",
4
4
  "description": "Real-browser E2E acceptance for your coding agent: test the flows you changed and open the PR with screenshots. Built for flows other tools can't reach: managed test identities with live inboxes (magic links, email OTP and 2FA, verification mail, password resets), an encrypted secret store for login and test credentials, and a test graph that runs prerequisite flows first. Plain-English tests become replayable scripts on localhost or preview URLs.",
5
- "version": "5.26.0-staging.214",
5
+ "version": "5.26.0-staging.215",
6
6
  "author": {
7
7
  "name": "Muggle AI",
8
8
  "email": "support@muggle-ai.com"
@@ -4,7 +4,7 @@
4
4
  "command": "npx",
5
5
  "args": [
6
6
  "-y",
7
- "@muggleai/works@5.26.0-staging.214",
7
+ "@muggleai/works@5.26.0-staging.215",
8
8
  "serve"
9
9
  ]
10
10
  }
@@ -35,7 +35,7 @@ Pre-filters are bash builtins only (`guardrail-lib.sh`), so an irrelevant event
35
35
  | Hook event | Wrapper | Strength | Condition | Preference | Effect |
36
36
  | :--------- | :------ | :------- | :-------- | :--------- | :----- |
37
37
  | `PostToolUse` (Bash) | `guardrail-pr-opened.sh` | advise | a `gh pr create`/`gh pr ready` just succeeded | `autoWatchPR` | start a `muggle-pr-followup` watcher on the new PR |
38
- | `PostToolUse` (Bash + muggle execute/replay MCP tools) | `guardrail-record-tests.sh` | record | a unit-test command passed, an E2E run happened (execute/replay call), or an `echo "MUGGLE_E2E_SKIP: <reason>"` marker declared E2E un-runnable, or a walkthrough carrying the `build-pr-section` sentinel was posted / declared un-postable via `echo "MUGGLE_WALKTHROUGH_SKIP: <reason>"` | — | set `unitTestsGreen` / `e2eRun` / `e2eSkipped` / `walkthroughPostedPrUrls` / `walkthroughSkipped` session state. A post settles only the PR its output names (`gh pr comment`/`create` print it; a `gh api` comment edit returns `html_url`); a post whose output names none is timestamped (`walkthroughPostedAt`), and a scan begun after it decides. An accepted skip records the working tree it was verified in and settles only that tree's change: the PRs opened from it (`prWorkingTrees`, tracked in `e2eSkipCoveredPrs`) and its checked-out branch's PR |
38
+ | `PostToolUse` (Bash + muggle execute/replay MCP tools) | `guardrail-record-tests.sh` | record | a unit-test command passed, an E2E run happened (execute/replay call), or an `echo "MUGGLE_E2E_SKIP: <reason>"` marker declared E2E un-runnable, or a walkthrough carrying the `build-pr-section` sentinel was posted / declared un-postable via `echo "MUGGLE_WALKTHROUGH_SKIP: <reason>"` | — | set `unitTestsGreen` / `e2eRun` / `e2eSkipped` / `walkthroughPostedPrUrls` / `walkthroughSkipped` session state. A post settles only the PR its output names (`gh pr comment`/`create` print it; a `gh api` comment edit returns `html_url`); a post whose output names none is timestamped (`walkthroughPostedAt`), and a scan begun after it decides. An accepted skip records the change it was verified for — the working tree's origin repo and checked-out branch (`e2eSkipVerifiedChange`) — and settles only that change: the PRs opened for it (`prChanges`, tracked in `e2eSkipCoveredPrs`) and its checked-out branch's PR. A PR's change is its URL's repo plus the command's `--head`/`--source-branch`, or else the hook tree's branch when the command never changed directory and that tree is in the PR's repo; a PR whose change is unknown is never covered, so `Push-Location`/`cd`/`--repo` cannot hand it another change's skip |
39
39
  | `PostToolUse` (Bash) | `guardrail-pr-terminal.sh` | advise | a PR just went terminal — a `gh pr merge`/`gh pr close` success line or the `TERMINAL pr=N` line the watch scripts print in a shell result (never bare `"state":"MERGED"` metadata). Not registered on `Monitor`: a Monitor call returns before its script prints anything, so its result never carries that line | — | record `terminalPending`, direct the post-merge handoff: finalize the watcher slot, tear down per `autoCleanup`, offer next options via AskUserQuestion |
40
40
  | `PostToolUse` (AskUserQuestion) | `guardrail-offer-ran.sh` | record | a next-options offer ran while a terminal PR was pending | — | clear `terminalPending` — the only exit for the post-merge Stop gate |
41
41
  | `PostToolUse` (Agent, Task) | `guardrail-record-delegation.sh` | record | a `muggle:acceptance-tester` was launched into the background — its response carries no finished report yet | — | append to `e2eDelegations` with the PR URLs its brief names; for a bounded window the E2E and debug-path gates hold off, and the walkthrough gate sets those PRs aside, so the session is never steered into a second browser run alongside the agent's. Shares the AskUserQuestion group's dispatch |
@@ -49,7 +49,7 @@ Pre-filters are bash builtins only (`guardrail-lib.sh`), so an irrelevant event
49
49
  | `Stop` | `guardrail-terminal-gate.sh` | **enforce** | a PR went terminal this session and the AskUserQuestion next-options offer hasn't run since | — | **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) |
50
50
  | `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 |
51
51
  | `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 |
52
- | `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 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 from the same tree. 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 |
52
+ | `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 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 |
53
53
  | `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) |
54
54
  | `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). Quiet while a background acceptance-tester is in flight — its failed runs land in this session's state and it debugs them itself |
55
55
  | `Stop` | `guardrail-comment-reply-gate.sh` | **enforce** | this session claimed a review thread and left one of its comments uncovered | — | **block** the turn until each comment gets its threaded reply per `do/per-comment-replies.md` or a `MUGGLE_REPLY_SKIP: <comment-id> <reason>` marker defers it (releases after 3 blocks). The claim is the signal, not a push, so a round that answers a question with no code change is caught too; a thread another session claimed never blocks this one |
@@ -80,6 +80,10 @@ var WATCH_TERMINAL_CMD = /pr-watch-(?:loop|arm)\.sh/;
80
80
  var MERGED_GATE_OUTPUT_SEPARATOR = "\n\n";
81
81
  var GITHUB_PR_URL = /https:\/\/github\.com\/[^/\s]+\/[^/\s]+\/pull\/\d+/;
82
82
  var GITLAB_MR_URL = /https?:\/\/[^/\s]+\/[^\s]+\/-\/merge_requests\/\d+/;
83
+ var PR_OPEN_COMMAND = /\b(?:gh\s+pr\s+(?:create|ready)|glab\s+mr\s+(?:create|update))\b/;
84
+ var PR_HEAD_BRANCH_FLAG = /\s(?:--head(?:=|\s+)|-H\s+|--source-branch(?:=|\s+)|-s\s+)["']?([^\s"';|&)]+)/;
85
+ var DIRECTORY_CHANGE_COMMAND = /(?:^|[\s;&|(])(?:cd|pushd|chdir|Push-Location|Set-Location)(?=\s|$)/i;
86
+ var CHANGE_REPO_REMOTE = "origin";
83
87
  var SUBAGENT_DISPATCH_TOOL_NAMES = ["Agent", "Task"];
84
88
  var ACCEPTANCE_TESTER_SUBAGENT_TYPE = /(?:^|:)acceptance-tester$/;
85
89
  var ACCEPTANCE_REPORT_MARKERS = ["## Test Summary", "**Overall:**"];
@@ -1377,14 +1381,120 @@ function applyWalkthroughSkip(state, skipped) {
1377
1381
  if (!skipped || state.walkthroughSkipped === true) return state;
1378
1382
  return { ...state, walkthroughSkipped: true };
1379
1383
  }
1380
- function normalizeWorkingTree(cwd) {
1384
+ var readTextFile = (path) => {
1385
+ try {
1386
+ return readFileSync(path, "utf8");
1387
+ } catch {
1388
+ return null;
1389
+ }
1390
+ };
1391
+ var listFiles = (dir) => {
1392
+ try {
1393
+ return readdirSync(dir);
1394
+ } catch {
1395
+ return [];
1396
+ }
1397
+ };
1398
+ var runGit = (args, cwd) => {
1399
+ const timeoutMs = boundedChildTimeoutMs(GIT_PROBE_TIMEOUT_MS);
1400
+ if (timeoutMs === null) return null;
1401
+ try {
1402
+ return execFileSync("git", args, {
1403
+ cwd,
1404
+ encoding: "utf8",
1405
+ timeout: timeoutMs,
1406
+ stdio: ["ignore", "pipe", "ignore"],
1407
+ windowsHide: true
1408
+ });
1409
+ } catch {
1410
+ return null;
1411
+ }
1412
+ };
1413
+ var hostAndPort = (url) => {
1414
+ const withScheme = /^https?:\/\//i.test(url) ? url : `http://${url}`;
1415
+ try {
1416
+ const parsed = new URL(withScheme);
1417
+ const port = parsed.port ? Number(parsed.port) : parsed.protocol === "https:" ? 443 : 80;
1418
+ return { host: parsed.hostname, port };
1419
+ } catch {
1420
+ return null;
1421
+ }
1422
+ };
1423
+ var isReachable = (url) => {
1424
+ const target = hostAndPort(url);
1425
+ if (!target) return false;
1426
+ const spawnTimeoutMs = boundedChildTimeoutMs(DEV_SERVER_PROBE_TIMEOUT_MS * 2);
1427
+ if (spawnTimeoutMs === null) return false;
1428
+ const socketTimeoutMs = Math.min(DEV_SERVER_PROBE_TIMEOUT_MS, Math.floor(spawnTimeoutMs / 2));
1429
+ const script = `const net=require('net');const s=net.connect(${target.port},${JSON.stringify(target.host)});s.setTimeout(${socketTimeoutMs});s.on('connect',()=>{s.destroy();process.exit(0)});s.on('timeout',()=>{s.destroy();process.exit(1)});s.on('error',()=>process.exit(1));`;
1430
+ try {
1431
+ execFileSync(process.execPath, ["-e", script], {
1432
+ timeout: spawnTimeoutMs,
1433
+ stdio: "ignore",
1434
+ windowsHide: true
1435
+ });
1436
+ return true;
1437
+ } catch {
1438
+ return false;
1439
+ }
1440
+ };
1441
+ var defaultSkipProbes = {
1442
+ readTextFile,
1443
+ listFiles,
1444
+ runGit,
1445
+ isReachable
1446
+ };
1447
+
1448
+ // src/guardrails/changeIdentity.ts
1449
+ function toRepoKey(host2, path) {
1450
+ const repoPath = path.replace(/^\/+|\/+$/g, "").replace(/\.git$/i, "");
1451
+ return host2 && repoPath ? `${host2}/${repoPath}`.toLowerCase() : void 0;
1452
+ }
1453
+ function repoKeyOfPrUrl(prUrl) {
1454
+ const pullsAt = prUrl.match(GITHUB_PR_URL) ? prUrl.indexOf("/pull/") : prUrl.match(GITLAB_MR_URL) ? prUrl.indexOf("/-/merge_requests/") : -1;
1455
+ if (pullsAt < 0) return void 0;
1456
+ try {
1457
+ const repoUrl = new URL(prUrl.slice(0, pullsAt));
1458
+ return toRepoKey(repoUrl.hostname, repoUrl.pathname);
1459
+ } catch {
1460
+ return void 0;
1461
+ }
1462
+ }
1463
+ function repoKeyOfRemoteUrl(remoteUrl) {
1464
+ const trimmedUrl = remoteUrl.trim();
1465
+ const scpStyle = trimmedUrl.match(/^[^@\s/]+@([^:\s/]+):(?!\/)(.+)$/);
1466
+ if (scpStyle) return toRepoKey(scpStyle[1], scpStyle[2]);
1467
+ try {
1468
+ const parsedUrl = new URL(trimmedUrl);
1469
+ return toRepoKey(parsedUrl.hostname, parsedUrl.pathname);
1470
+ } catch {
1471
+ return void 0;
1472
+ }
1473
+ }
1474
+ function resolveTreeChange(cwd, runGit2 = defaultSkipProbes.runGit) {
1381
1475
  if (!cwd) return void 0;
1382
- const forwardSlashed = resolve(cwd).replace(/\\/g, "/").replace(/\/+$/, "");
1383
- return process.platform === "win32" ? forwardSlashed.toLowerCase() : forwardSlashed;
1476
+ const remoteUrl = runGit2(["remote", "get-url", CHANGE_REPO_REMOTE], cwd);
1477
+ const repo = remoteUrl ? repoKeyOfRemoteUrl(remoteUrl) : void 0;
1478
+ const branch = runGit2(["branch", "--show-current"], cwd)?.trim();
1479
+ return repo && branch ? { repo, branch } : void 0;
1480
+ }
1481
+ function resolveOpenedPrChange(command, prUrl, cwd, runGit2 = defaultSkipProbes.runGit) {
1482
+ const repo = repoKeyOfPrUrl(prUrl);
1483
+ if (!repo) return void 0;
1484
+ const openAt = command.search(PR_OPEN_COMMAND);
1485
+ const headFlag = openAt < 0 ? null : command.slice(openAt).match(PR_HEAD_BRANCH_FLAG);
1486
+ if (headFlag) return { repo, branch: headFlag[1].slice(headFlag[1].lastIndexOf(":") + 1) };
1487
+ if (DIRECTORY_CHANGE_COMMAND.test(command)) return void 0;
1488
+ const treeChange = resolveTreeChange(cwd, runGit2);
1489
+ return treeChange?.repo === repo ? treeChange : void 0;
1490
+ }
1491
+ function isSameChange(left, right) {
1492
+ return left !== void 0 && right !== void 0 && left.repo === right.repo && left.branch === right.branch;
1384
1493
  }
1385
- function isOpenedFromSkipTree(state, prUrl) {
1386
- const skipTree = state.e2eSkipVerifiedInTree;
1387
- return skipTree !== void 0 && state.prWorkingTrees?.[prUrl] === skipTree;
1494
+
1495
+ // src/guardrails/skipScope.ts
1496
+ function isPrOfSkipChange(state, prUrl) {
1497
+ return isSameChange(state.prChanges?.[prUrl], state.e2eSkipVerifiedChange);
1388
1498
  }
1389
1499
  function withCoveredPrs(state, prUrls) {
1390
1500
  const covered = new Set(state.e2eSkipCoveredPrs ?? []);
@@ -1395,17 +1505,17 @@ function withCoveredPrs(state, prUrls) {
1395
1505
  function isPrCoveredBySkip(state, prUrl) {
1396
1506
  return (state.e2eSkipCoveredPrs ?? []).includes(prUrl);
1397
1507
  }
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;
1508
+ function applyPrOpenedToSkipScope(state, prUrl, prChange) {
1509
+ if (!prChange) return state;
1510
+ const recorded = { ...state, prChanges: { ...state.prChanges, [prUrl]: prChange } };
1511
+ return isPrOfSkipChange(recorded, prUrl) && recorded.e2eSkipDeclaration ? withCoveredPrs(recorded, [prUrl]) : recorded;
1402
1512
  }
1403
- function applyE2eSkipScope(state, verifiedInTree) {
1404
- if (!verifiedInTree || !state.e2eSkipDeclaration) return state;
1405
- const scoped = { ...state, e2eSkipVerifiedInTree: verifiedInTree };
1513
+ function applyE2eSkipScope(state, verifiedChange) {
1514
+ if (!verifiedChange || !state.e2eSkipDeclaration) return state;
1515
+ const scoped = { ...state, e2eSkipVerifiedChange: verifiedChange };
1406
1516
  return withCoveredPrs(
1407
1517
  scoped,
1408
- scoped.prsHandled.filter((prUrl) => isOpenedFromSkipTree(scoped, prUrl))
1518
+ scoped.prsHandled.filter((prUrl) => isPrOfSkipChange(scoped, prUrl))
1409
1519
  );
1410
1520
  }
1411
1521
 
@@ -1787,71 +1897,6 @@ function explainRejection(judged) {
1787
1897
  }
1788
1898
  return `The skip cited ${judged.claimedCode}, but that could not be verified: ${judged.failure}. E2E is still owed \u2014 cite a code that holds, or run it.`;
1789
1899
  }
1790
- var readTextFile = (path) => {
1791
- try {
1792
- return readFileSync(path, "utf8");
1793
- } catch {
1794
- return null;
1795
- }
1796
- };
1797
- var listFiles = (dir) => {
1798
- try {
1799
- return readdirSync(dir);
1800
- } catch {
1801
- return [];
1802
- }
1803
- };
1804
- var runGit = (args, cwd) => {
1805
- const timeoutMs = boundedChildTimeoutMs(GIT_PROBE_TIMEOUT_MS);
1806
- if (timeoutMs === null) return null;
1807
- try {
1808
- return execFileSync("git", args, {
1809
- cwd,
1810
- encoding: "utf8",
1811
- timeout: timeoutMs,
1812
- stdio: ["ignore", "pipe", "ignore"],
1813
- windowsHide: true
1814
- });
1815
- } catch {
1816
- return null;
1817
- }
1818
- };
1819
- var hostAndPort = (url) => {
1820
- const withScheme = /^https?:\/\//i.test(url) ? url : `http://${url}`;
1821
- try {
1822
- const parsed = new URL(withScheme);
1823
- const port = parsed.port ? Number(parsed.port) : parsed.protocol === "https:" ? 443 : 80;
1824
- return { host: parsed.hostname, port };
1825
- } catch {
1826
- return null;
1827
- }
1828
- };
1829
- var isReachable = (url) => {
1830
- const target = hostAndPort(url);
1831
- if (!target) return false;
1832
- const spawnTimeoutMs = boundedChildTimeoutMs(DEV_SERVER_PROBE_TIMEOUT_MS * 2);
1833
- if (spawnTimeoutMs === null) return false;
1834
- const socketTimeoutMs = Math.min(DEV_SERVER_PROBE_TIMEOUT_MS, Math.floor(spawnTimeoutMs / 2));
1835
- const script = `const net=require('net');const s=net.connect(${target.port},${JSON.stringify(target.host)});s.setTimeout(${socketTimeoutMs});s.on('connect',()=>{s.destroy();process.exit(0)});s.on('timeout',()=>{s.destroy();process.exit(1)});s.on('error',()=>process.exit(1));`;
1836
- try {
1837
- execFileSync(process.execPath, ["-e", script], {
1838
- timeout: spawnTimeoutMs,
1839
- stdio: "ignore",
1840
- windowsHide: true
1841
- });
1842
- return true;
1843
- } catch {
1844
- return false;
1845
- }
1846
- };
1847
- var defaultSkipProbes = {
1848
- readTextFile,
1849
- listFiles,
1850
- runGit,
1851
- isReachable
1852
- };
1853
-
1854
- // src/guardrails/skipReason.ts
1855
1900
  function judgeE2eSkip(input2, state, probes = defaultSkipProbes) {
1856
1901
  return resolveSkipDeclaration(input2.tool_input?.command ?? "", {
1857
1902
  cwd: input2.cwd,
@@ -2253,10 +2298,10 @@ function prOpened() {
2253
2298
  if (!url) return "{}";
2254
2299
  if (readState(sessionId).prsHandled.includes(url)) return "{}";
2255
2300
  markPrHandled(sessionId, url);
2256
- const openedFromTree = normalizeWorkingTree(input.cwd);
2301
+ const prChange = resolveOpenedPrChange(input.tool_input?.command ?? "", url, input.cwd);
2257
2302
  const stateAfterOpen = commitState(
2258
2303
  sessionId,
2259
- (state) => applyPrOpenedToSkipScope(applyPrOpenedToWalkthroughs(state), url, openedFromTree)
2304
+ (state) => applyPrOpenedToSkipScope(applyPrOpenedToWalkthroughs(state), url, prChange)
2260
2305
  ) ?? readState(sessionId);
2261
2306
  const declaredSkip = isPrCoveredBySkip(stateAfterOpen, url) ? stateAfterOpen.e2eSkipDeclaration : void 0;
2262
2307
  if (declaredSkip) {
@@ -2331,9 +2376,10 @@ function recordTests() {
2331
2376
  const walkthroughPostTargets = walkthroughPosted ? detectWalkthroughPostTargets(input) : [];
2332
2377
  const failedRunId = detectFailedRunId(input);
2333
2378
  const isDeclaredHere = acceptedSkip !== null && !CYCLE_SCOPED_SKIP_CODES.includes(acceptedSkip.code);
2379
+ const verifiedChange = isDeclaredHere ? resolveTreeChange(input.cwd) : void 0;
2334
2380
  const record = (state) => {
2335
2381
  const declared = applyE2eSkipDeclaration(applyRecordedRun(state, run), acceptedSkip);
2336
- const recorded = isDeclaredHere ? applyE2eSkipScope(declared, normalizeWorkingTree(input.cwd)) : declared;
2382
+ const recorded = isDeclaredHere ? applyE2eSkipScope(declared, verifiedChange) : declared;
2337
2383
  const withWatchSkip = applyWatchSkip(recorded, isWatchSkipMarker(cmd));
2338
2384
  const withBuildSkip = applyBuildSkip(withWatchSkip, isBuildSkipMarker(cmd));
2339
2385
  const withWalkthroughPost = applyWalkthroughPosted(
@@ -2548,7 +2594,7 @@ function walkthroughGate() {
2548
2594
  return blockOnUnsettledSkip(declaredSkip, skipOwedPrUrls, decision.blockCount);
2549
2595
  }
2550
2596
  const prList = decision.owed.join(", ");
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>"\`.`;
2597
+ 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 repo and branch it was verified on. 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>"\`.`;
2552
2598
  return blockStop(reason, host);
2553
2599
  }
2554
2600
  function blockOnUnsettledSkip(owedSkip, owedPrUrls, blockCount) {
@@ -78,7 +78,7 @@ A session that fixed bugs by hand and opened each PR itself follows the same lan
78
78
 
79
79
  - Dispatching a background acceptance-tester holds the E2E and debug-path Stop gates off for a bounded window, and for that window the walkthrough gate sets aside the PRs its brief names — the session is never steered into a second browser run alongside the agent's.
80
80
  - A walkthrough posted to one PR settles that PR only; every other PR the session opened is still checked for its own.
81
- - A skip declaration settles only the PRs of the working tree it is declared in — the PRs opened from it and its branch's PR, never another change's.
81
+ - A skip declaration settles only the PRs of the change it is declared in — the working tree's repo and branch: the PRs opened for that branch and its branch's PR, never another change's, wherever the session's directory sat when a PR was opened.
82
82
  - Every PR's walkthrough check stays red until its slot is settled, so a change whose run never came back cannot pass as tested.
83
83
 
84
84
  ## Invariants
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "release": "5.18.0",
3
- "buildId": "run-214-1",
4
- "commitSha": "647eac21c7d04165bee843fc43ac5d85f63ffa9c",
5
- "buildTime": "2026-10-26T19:41:32Z",
3
+ "buildId": "run-215-1",
4
+ "commitSha": "8ba7463f7cdb1186e82e5466b1631540c2141dc7",
5
+ "buildTime": "2026-10-26T20:22:23Z",
6
6
  "serviceName": "muggle-ai-works-mcp"
7
7
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@muggleai/works",
3
3
  "mcpName": "io.github.multiplex-ai/muggle",
4
- "version": "5.26.0-staging.214",
4
+ "version": "5.26.0-staging.215",
5
5
  "description": "13 years of Microsoft hyperscale engineering, packaged as a harness for your AI coding agent.",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "muggle",
3
3
  "description": "Real-browser E2E acceptance for your coding agent: test the flows you changed and open the PR with screenshots. Built for flows other tools can't reach: managed test identities with live inboxes (magic links, email OTP and 2FA, verification mail, password resets), an encrypted secret store for login and test credentials, and a test graph that runs prerequisite flows first. Plain-English tests become replayable scripts on localhost or preview URLs.",
4
- "version": "5.26.0-staging.214",
4
+ "version": "5.26.0-staging.215",
5
5
  "author": {
6
6
  "name": "Muggle AI",
7
7
  "email": "support@muggle-ai.com"
@@ -4,7 +4,7 @@
4
4
  "command": "npx",
5
5
  "args": [
6
6
  "-y",
7
- "@muggleai/works@5.26.0-staging.214",
7
+ "@muggleai/works@5.26.0-staging.215",
8
8
  "serve"
9
9
  ],
10
10
  "env": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muggle",
3
- "version": "5.26.0-staging.214",
3
+ "version": "5.26.0-staging.215",
4
4
  "description": "Real-browser E2E acceptance for your coding agent: test the flows you changed and open the PR with screenshots. Built for flows other tools can't reach: managed test identities with live inboxes (magic links, email OTP and 2FA, verification mail, password resets), an encrypted secret store for login and test credentials, and a test graph that runs prerequisite flows first. Plain-English tests become replayable scripts on localhost or preview URLs.",
5
5
  "author": {
6
6
  "name": "Muggle AI",
@@ -2,7 +2,7 @@
2
2
  "name": "muggle",
3
3
  "displayName": "Muggle AI",
4
4
  "description": "Real-browser E2E acceptance for your coding agent: test the flows you changed and open the PR with screenshots. Built for flows other tools can't reach: managed test identities with live inboxes (magic links, email OTP and 2FA, verification mail, password resets), an encrypted secret store for login and test credentials, and a test graph that runs prerequisite flows first. Plain-English tests become replayable scripts on localhost or preview URLs.",
5
- "version": "5.26.0-staging.214",
5
+ "version": "5.26.0-staging.215",
6
6
  "author": {
7
7
  "name": "Muggle AI",
8
8
  "email": "support@muggle-ai.com"
package/plugin/.mcp.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "command": "npx",
5
5
  "args": [
6
6
  "-y",
7
- "@muggleai/works@5.26.0-staging.214",
7
+ "@muggleai/works@5.26.0-staging.215",
8
8
  "serve"
9
9
  ]
10
10
  }
@@ -35,7 +35,7 @@ Pre-filters are bash builtins only (`guardrail-lib.sh`), so an irrelevant event
35
35
  | Hook event | Wrapper | Strength | Condition | Preference | Effect |
36
36
  | :--------- | :------ | :------- | :-------- | :--------- | :----- |
37
37
  | `PostToolUse` (Bash) | `guardrail-pr-opened.sh` | advise | a `gh pr create`/`gh pr ready` just succeeded | `autoWatchPR` | start a `muggle-pr-followup` watcher on the new PR |
38
- | `PostToolUse` (Bash + muggle execute/replay MCP tools) | `guardrail-record-tests.sh` | record | a unit-test command passed, an E2E run happened (execute/replay call), or an `echo "MUGGLE_E2E_SKIP: <reason>"` marker declared E2E un-runnable, or a walkthrough carrying the `build-pr-section` sentinel was posted / declared un-postable via `echo "MUGGLE_WALKTHROUGH_SKIP: <reason>"` | — | set `unitTestsGreen` / `e2eRun` / `e2eSkipped` / `walkthroughPostedPrUrls` / `walkthroughSkipped` session state. A post settles only the PR its output names (`gh pr comment`/`create` print it; a `gh api` comment edit returns `html_url`); a post whose output names none is timestamped (`walkthroughPostedAt`), and a scan begun after it decides. An accepted skip records the working tree it was verified in and settles only that tree's change: the PRs opened from it (`prWorkingTrees`, tracked in `e2eSkipCoveredPrs`) and its checked-out branch's PR |
38
+ | `PostToolUse` (Bash + muggle execute/replay MCP tools) | `guardrail-record-tests.sh` | record | a unit-test command passed, an E2E run happened (execute/replay call), or an `echo "MUGGLE_E2E_SKIP: <reason>"` marker declared E2E un-runnable, or a walkthrough carrying the `build-pr-section` sentinel was posted / declared un-postable via `echo "MUGGLE_WALKTHROUGH_SKIP: <reason>"` | — | set `unitTestsGreen` / `e2eRun` / `e2eSkipped` / `walkthroughPostedPrUrls` / `walkthroughSkipped` session state. A post settles only the PR its output names (`gh pr comment`/`create` print it; a `gh api` comment edit returns `html_url`); a post whose output names none is timestamped (`walkthroughPostedAt`), and a scan begun after it decides. An accepted skip records the change it was verified for — the working tree's origin repo and checked-out branch (`e2eSkipVerifiedChange`) — and settles only that change: the PRs opened for it (`prChanges`, tracked in `e2eSkipCoveredPrs`) and its checked-out branch's PR. A PR's change is its URL's repo plus the command's `--head`/`--source-branch`, or else the hook tree's branch when the command never changed directory and that tree is in the PR's repo; a PR whose change is unknown is never covered, so `Push-Location`/`cd`/`--repo` cannot hand it another change's skip |
39
39
  | `PostToolUse` (Bash) | `guardrail-pr-terminal.sh` | advise | a PR just went terminal — a `gh pr merge`/`gh pr close` success line or the `TERMINAL pr=N` line the watch scripts print in a shell result (never bare `"state":"MERGED"` metadata). Not registered on `Monitor`: a Monitor call returns before its script prints anything, so its result never carries that line | — | record `terminalPending`, direct the post-merge handoff: finalize the watcher slot, tear down per `autoCleanup`, offer next options via AskUserQuestion |
40
40
  | `PostToolUse` (AskUserQuestion) | `guardrail-offer-ran.sh` | record | a next-options offer ran while a terminal PR was pending | — | clear `terminalPending` — the only exit for the post-merge Stop gate |
41
41
  | `PostToolUse` (Agent, Task) | `guardrail-record-delegation.sh` | record | a `muggle:acceptance-tester` was launched into the background — its response carries no finished report yet | — | append to `e2eDelegations` with the PR URLs its brief names; for a bounded window the E2E and debug-path gates hold off, and the walkthrough gate sets those PRs aside, so the session is never steered into a second browser run alongside the agent's. Shares the AskUserQuestion group's dispatch |
@@ -49,7 +49,7 @@ Pre-filters are bash builtins only (`guardrail-lib.sh`), so an irrelevant event
49
49
  | `Stop` | `guardrail-terminal-gate.sh` | **enforce** | a PR went terminal this session and the AskUserQuestion next-options offer hasn't run since | — | **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) |
50
50
  | `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 |
51
51
  | `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 |
52
- | `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 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 from the same tree. 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 |
52
+ | `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 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 |
53
53
  | `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) |
54
54
  | `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). Quiet while a background acceptance-tester is in flight — its failed runs land in this session's state and it debugs them itself |
55
55
  | `Stop` | `guardrail-comment-reply-gate.sh` | **enforce** | this session claimed a review thread and left one of its comments uncovered | — | **block** the turn until each comment gets its threaded reply per `do/per-comment-replies.md` or a `MUGGLE_REPLY_SKIP: <comment-id> <reason>` marker defers it (releases after 3 blocks). The claim is the signal, not a push, so a round that answers a question with no code change is caught too; a thread another session claimed never blocks this one |
@@ -80,6 +80,10 @@ var WATCH_TERMINAL_CMD = /pr-watch-(?:loop|arm)\.sh/;
80
80
  var MERGED_GATE_OUTPUT_SEPARATOR = "\n\n";
81
81
  var GITHUB_PR_URL = /https:\/\/github\.com\/[^/\s]+\/[^/\s]+\/pull\/\d+/;
82
82
  var GITLAB_MR_URL = /https?:\/\/[^/\s]+\/[^\s]+\/-\/merge_requests\/\d+/;
83
+ var PR_OPEN_COMMAND = /\b(?:gh\s+pr\s+(?:create|ready)|glab\s+mr\s+(?:create|update))\b/;
84
+ var PR_HEAD_BRANCH_FLAG = /\s(?:--head(?:=|\s+)|-H\s+|--source-branch(?:=|\s+)|-s\s+)["']?([^\s"';|&)]+)/;
85
+ var DIRECTORY_CHANGE_COMMAND = /(?:^|[\s;&|(])(?:cd|pushd|chdir|Push-Location|Set-Location)(?=\s|$)/i;
86
+ var CHANGE_REPO_REMOTE = "origin";
83
87
  var SUBAGENT_DISPATCH_TOOL_NAMES = ["Agent", "Task"];
84
88
  var ACCEPTANCE_TESTER_SUBAGENT_TYPE = /(?:^|:)acceptance-tester$/;
85
89
  var ACCEPTANCE_REPORT_MARKERS = ["## Test Summary", "**Overall:**"];
@@ -1377,14 +1381,120 @@ function applyWalkthroughSkip(state, skipped) {
1377
1381
  if (!skipped || state.walkthroughSkipped === true) return state;
1378
1382
  return { ...state, walkthroughSkipped: true };
1379
1383
  }
1380
- function normalizeWorkingTree(cwd) {
1384
+ var readTextFile = (path) => {
1385
+ try {
1386
+ return readFileSync(path, "utf8");
1387
+ } catch {
1388
+ return null;
1389
+ }
1390
+ };
1391
+ var listFiles = (dir) => {
1392
+ try {
1393
+ return readdirSync(dir);
1394
+ } catch {
1395
+ return [];
1396
+ }
1397
+ };
1398
+ var runGit = (args, cwd) => {
1399
+ const timeoutMs = boundedChildTimeoutMs(GIT_PROBE_TIMEOUT_MS);
1400
+ if (timeoutMs === null) return null;
1401
+ try {
1402
+ return execFileSync("git", args, {
1403
+ cwd,
1404
+ encoding: "utf8",
1405
+ timeout: timeoutMs,
1406
+ stdio: ["ignore", "pipe", "ignore"],
1407
+ windowsHide: true
1408
+ });
1409
+ } catch {
1410
+ return null;
1411
+ }
1412
+ };
1413
+ var hostAndPort = (url) => {
1414
+ const withScheme = /^https?:\/\//i.test(url) ? url : `http://${url}`;
1415
+ try {
1416
+ const parsed = new URL(withScheme);
1417
+ const port = parsed.port ? Number(parsed.port) : parsed.protocol === "https:" ? 443 : 80;
1418
+ return { host: parsed.hostname, port };
1419
+ } catch {
1420
+ return null;
1421
+ }
1422
+ };
1423
+ var isReachable = (url) => {
1424
+ const target = hostAndPort(url);
1425
+ if (!target) return false;
1426
+ const spawnTimeoutMs = boundedChildTimeoutMs(DEV_SERVER_PROBE_TIMEOUT_MS * 2);
1427
+ if (spawnTimeoutMs === null) return false;
1428
+ const socketTimeoutMs = Math.min(DEV_SERVER_PROBE_TIMEOUT_MS, Math.floor(spawnTimeoutMs / 2));
1429
+ const script = `const net=require('net');const s=net.connect(${target.port},${JSON.stringify(target.host)});s.setTimeout(${socketTimeoutMs});s.on('connect',()=>{s.destroy();process.exit(0)});s.on('timeout',()=>{s.destroy();process.exit(1)});s.on('error',()=>process.exit(1));`;
1430
+ try {
1431
+ execFileSync(process.execPath, ["-e", script], {
1432
+ timeout: spawnTimeoutMs,
1433
+ stdio: "ignore",
1434
+ windowsHide: true
1435
+ });
1436
+ return true;
1437
+ } catch {
1438
+ return false;
1439
+ }
1440
+ };
1441
+ var defaultSkipProbes = {
1442
+ readTextFile,
1443
+ listFiles,
1444
+ runGit,
1445
+ isReachable
1446
+ };
1447
+
1448
+ // src/guardrails/changeIdentity.ts
1449
+ function toRepoKey(host2, path) {
1450
+ const repoPath = path.replace(/^\/+|\/+$/g, "").replace(/\.git$/i, "");
1451
+ return host2 && repoPath ? `${host2}/${repoPath}`.toLowerCase() : void 0;
1452
+ }
1453
+ function repoKeyOfPrUrl(prUrl) {
1454
+ const pullsAt = prUrl.match(GITHUB_PR_URL) ? prUrl.indexOf("/pull/") : prUrl.match(GITLAB_MR_URL) ? prUrl.indexOf("/-/merge_requests/") : -1;
1455
+ if (pullsAt < 0) return void 0;
1456
+ try {
1457
+ const repoUrl = new URL(prUrl.slice(0, pullsAt));
1458
+ return toRepoKey(repoUrl.hostname, repoUrl.pathname);
1459
+ } catch {
1460
+ return void 0;
1461
+ }
1462
+ }
1463
+ function repoKeyOfRemoteUrl(remoteUrl) {
1464
+ const trimmedUrl = remoteUrl.trim();
1465
+ const scpStyle = trimmedUrl.match(/^[^@\s/]+@([^:\s/]+):(?!\/)(.+)$/);
1466
+ if (scpStyle) return toRepoKey(scpStyle[1], scpStyle[2]);
1467
+ try {
1468
+ const parsedUrl = new URL(trimmedUrl);
1469
+ return toRepoKey(parsedUrl.hostname, parsedUrl.pathname);
1470
+ } catch {
1471
+ return void 0;
1472
+ }
1473
+ }
1474
+ function resolveTreeChange(cwd, runGit2 = defaultSkipProbes.runGit) {
1381
1475
  if (!cwd) return void 0;
1382
- const forwardSlashed = resolve(cwd).replace(/\\/g, "/").replace(/\/+$/, "");
1383
- return process.platform === "win32" ? forwardSlashed.toLowerCase() : forwardSlashed;
1476
+ const remoteUrl = runGit2(["remote", "get-url", CHANGE_REPO_REMOTE], cwd);
1477
+ const repo = remoteUrl ? repoKeyOfRemoteUrl(remoteUrl) : void 0;
1478
+ const branch = runGit2(["branch", "--show-current"], cwd)?.trim();
1479
+ return repo && branch ? { repo, branch } : void 0;
1480
+ }
1481
+ function resolveOpenedPrChange(command, prUrl, cwd, runGit2 = defaultSkipProbes.runGit) {
1482
+ const repo = repoKeyOfPrUrl(prUrl);
1483
+ if (!repo) return void 0;
1484
+ const openAt = command.search(PR_OPEN_COMMAND);
1485
+ const headFlag = openAt < 0 ? null : command.slice(openAt).match(PR_HEAD_BRANCH_FLAG);
1486
+ if (headFlag) return { repo, branch: headFlag[1].slice(headFlag[1].lastIndexOf(":") + 1) };
1487
+ if (DIRECTORY_CHANGE_COMMAND.test(command)) return void 0;
1488
+ const treeChange = resolveTreeChange(cwd, runGit2);
1489
+ return treeChange?.repo === repo ? treeChange : void 0;
1490
+ }
1491
+ function isSameChange(left, right) {
1492
+ return left !== void 0 && right !== void 0 && left.repo === right.repo && left.branch === right.branch;
1384
1493
  }
1385
- function isOpenedFromSkipTree(state, prUrl) {
1386
- const skipTree = state.e2eSkipVerifiedInTree;
1387
- return skipTree !== void 0 && state.prWorkingTrees?.[prUrl] === skipTree;
1494
+
1495
+ // src/guardrails/skipScope.ts
1496
+ function isPrOfSkipChange(state, prUrl) {
1497
+ return isSameChange(state.prChanges?.[prUrl], state.e2eSkipVerifiedChange);
1388
1498
  }
1389
1499
  function withCoveredPrs(state, prUrls) {
1390
1500
  const covered = new Set(state.e2eSkipCoveredPrs ?? []);
@@ -1395,17 +1505,17 @@ function withCoveredPrs(state, prUrls) {
1395
1505
  function isPrCoveredBySkip(state, prUrl) {
1396
1506
  return (state.e2eSkipCoveredPrs ?? []).includes(prUrl);
1397
1507
  }
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;
1508
+ function applyPrOpenedToSkipScope(state, prUrl, prChange) {
1509
+ if (!prChange) return state;
1510
+ const recorded = { ...state, prChanges: { ...state.prChanges, [prUrl]: prChange } };
1511
+ return isPrOfSkipChange(recorded, prUrl) && recorded.e2eSkipDeclaration ? withCoveredPrs(recorded, [prUrl]) : recorded;
1402
1512
  }
1403
- function applyE2eSkipScope(state, verifiedInTree) {
1404
- if (!verifiedInTree || !state.e2eSkipDeclaration) return state;
1405
- const scoped = { ...state, e2eSkipVerifiedInTree: verifiedInTree };
1513
+ function applyE2eSkipScope(state, verifiedChange) {
1514
+ if (!verifiedChange || !state.e2eSkipDeclaration) return state;
1515
+ const scoped = { ...state, e2eSkipVerifiedChange: verifiedChange };
1406
1516
  return withCoveredPrs(
1407
1517
  scoped,
1408
- scoped.prsHandled.filter((prUrl) => isOpenedFromSkipTree(scoped, prUrl))
1518
+ scoped.prsHandled.filter((prUrl) => isPrOfSkipChange(scoped, prUrl))
1409
1519
  );
1410
1520
  }
1411
1521
 
@@ -1787,71 +1897,6 @@ function explainRejection(judged) {
1787
1897
  }
1788
1898
  return `The skip cited ${judged.claimedCode}, but that could not be verified: ${judged.failure}. E2E is still owed \u2014 cite a code that holds, or run it.`;
1789
1899
  }
1790
- var readTextFile = (path) => {
1791
- try {
1792
- return readFileSync(path, "utf8");
1793
- } catch {
1794
- return null;
1795
- }
1796
- };
1797
- var listFiles = (dir) => {
1798
- try {
1799
- return readdirSync(dir);
1800
- } catch {
1801
- return [];
1802
- }
1803
- };
1804
- var runGit = (args, cwd) => {
1805
- const timeoutMs = boundedChildTimeoutMs(GIT_PROBE_TIMEOUT_MS);
1806
- if (timeoutMs === null) return null;
1807
- try {
1808
- return execFileSync("git", args, {
1809
- cwd,
1810
- encoding: "utf8",
1811
- timeout: timeoutMs,
1812
- stdio: ["ignore", "pipe", "ignore"],
1813
- windowsHide: true
1814
- });
1815
- } catch {
1816
- return null;
1817
- }
1818
- };
1819
- var hostAndPort = (url) => {
1820
- const withScheme = /^https?:\/\//i.test(url) ? url : `http://${url}`;
1821
- try {
1822
- const parsed = new URL(withScheme);
1823
- const port = parsed.port ? Number(parsed.port) : parsed.protocol === "https:" ? 443 : 80;
1824
- return { host: parsed.hostname, port };
1825
- } catch {
1826
- return null;
1827
- }
1828
- };
1829
- var isReachable = (url) => {
1830
- const target = hostAndPort(url);
1831
- if (!target) return false;
1832
- const spawnTimeoutMs = boundedChildTimeoutMs(DEV_SERVER_PROBE_TIMEOUT_MS * 2);
1833
- if (spawnTimeoutMs === null) return false;
1834
- const socketTimeoutMs = Math.min(DEV_SERVER_PROBE_TIMEOUT_MS, Math.floor(spawnTimeoutMs / 2));
1835
- const script = `const net=require('net');const s=net.connect(${target.port},${JSON.stringify(target.host)});s.setTimeout(${socketTimeoutMs});s.on('connect',()=>{s.destroy();process.exit(0)});s.on('timeout',()=>{s.destroy();process.exit(1)});s.on('error',()=>process.exit(1));`;
1836
- try {
1837
- execFileSync(process.execPath, ["-e", script], {
1838
- timeout: spawnTimeoutMs,
1839
- stdio: "ignore",
1840
- windowsHide: true
1841
- });
1842
- return true;
1843
- } catch {
1844
- return false;
1845
- }
1846
- };
1847
- var defaultSkipProbes = {
1848
- readTextFile,
1849
- listFiles,
1850
- runGit,
1851
- isReachable
1852
- };
1853
-
1854
- // src/guardrails/skipReason.ts
1855
1900
  function judgeE2eSkip(input2, state, probes = defaultSkipProbes) {
1856
1901
  return resolveSkipDeclaration(input2.tool_input?.command ?? "", {
1857
1902
  cwd: input2.cwd,
@@ -2253,10 +2298,10 @@ function prOpened() {
2253
2298
  if (!url) return "{}";
2254
2299
  if (readState(sessionId).prsHandled.includes(url)) return "{}";
2255
2300
  markPrHandled(sessionId, url);
2256
- const openedFromTree = normalizeWorkingTree(input.cwd);
2301
+ const prChange = resolveOpenedPrChange(input.tool_input?.command ?? "", url, input.cwd);
2257
2302
  const stateAfterOpen = commitState(
2258
2303
  sessionId,
2259
- (state) => applyPrOpenedToSkipScope(applyPrOpenedToWalkthroughs(state), url, openedFromTree)
2304
+ (state) => applyPrOpenedToSkipScope(applyPrOpenedToWalkthroughs(state), url, prChange)
2260
2305
  ) ?? readState(sessionId);
2261
2306
  const declaredSkip = isPrCoveredBySkip(stateAfterOpen, url) ? stateAfterOpen.e2eSkipDeclaration : void 0;
2262
2307
  if (declaredSkip) {
@@ -2331,9 +2376,10 @@ function recordTests() {
2331
2376
  const walkthroughPostTargets = walkthroughPosted ? detectWalkthroughPostTargets(input) : [];
2332
2377
  const failedRunId = detectFailedRunId(input);
2333
2378
  const isDeclaredHere = acceptedSkip !== null && !CYCLE_SCOPED_SKIP_CODES.includes(acceptedSkip.code);
2379
+ const verifiedChange = isDeclaredHere ? resolveTreeChange(input.cwd) : void 0;
2334
2380
  const record = (state) => {
2335
2381
  const declared = applyE2eSkipDeclaration(applyRecordedRun(state, run), acceptedSkip);
2336
- const recorded = isDeclaredHere ? applyE2eSkipScope(declared, normalizeWorkingTree(input.cwd)) : declared;
2382
+ const recorded = isDeclaredHere ? applyE2eSkipScope(declared, verifiedChange) : declared;
2337
2383
  const withWatchSkip = applyWatchSkip(recorded, isWatchSkipMarker(cmd));
2338
2384
  const withBuildSkip = applyBuildSkip(withWatchSkip, isBuildSkipMarker(cmd));
2339
2385
  const withWalkthroughPost = applyWalkthroughPosted(
@@ -2548,7 +2594,7 @@ function walkthroughGate() {
2548
2594
  return blockOnUnsettledSkip(declaredSkip, skipOwedPrUrls, decision.blockCount);
2549
2595
  }
2550
2596
  const prList = decision.owed.join(", ");
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>"\`.`;
2597
+ 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 repo and branch it was verified on. 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>"\`.`;
2552
2598
  return blockStop(reason, host);
2553
2599
  }
2554
2600
  function blockOnUnsettledSkip(owedSkip, owedPrUrls, blockCount) {
@@ -78,7 +78,7 @@ A session that fixed bugs by hand and opened each PR itself follows the same lan
78
78
 
79
79
  - Dispatching a background acceptance-tester holds the E2E and debug-path Stop gates off for a bounded window, and for that window the walkthrough gate sets aside the PRs its brief names — the session is never steered into a second browser run alongside the agent's.
80
80
  - A walkthrough posted to one PR settles that PR only; every other PR the session opened is still checked for its own.
81
- - A skip declaration settles only the PRs of the working tree it is declared in — the PRs opened from it and its branch's PR, never another change's.
81
+ - A skip declaration settles only the PRs of the change it is declared in — the working tree's repo and branch: the PRs opened for that branch and its branch's PR, never another change's, wherever the session's directory sat when a PR was opened.
82
82
  - Every PR's walkthrough check stays red until its slot is settled, so a change whose run never came back cannot pass as tested.
83
83
 
84
84
  ## Invariants
File without changes