@muggleai/works 5.26.0-staging.208 → 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.
Files changed (46) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/cli.js +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/plugin/.claude-plugin/plugin.json +1 -1
  5. package/dist/plugin/.codex-mcp.json +1 -1
  6. package/dist/plugin/.codex-plugin/plugin.json +1 -1
  7. package/dist/plugin/.cursor-plugin/plugin.json +1 -1
  8. package/dist/plugin/.mcp.json +1 -1
  9. package/dist/plugin/agents/acceptance-tester.md +18 -2
  10. package/dist/plugin/hooks/README.md +5 -4
  11. package/dist/plugin/hooks/codex-hooks.json +2 -2
  12. package/dist/plugin/hooks/hooks.json +2 -2
  13. package/dist/plugin/scripts/guardrail-record-delegation.sh +25 -0
  14. package/dist/plugin/scripts/guardrail-walkthrough-gate.sh +6 -6
  15. package/dist/plugin/scripts/guardrails.mjs +161 -32
  16. package/dist/plugin/skills/do/background-e2e.md +89 -0
  17. package/dist/plugin/skills/do/e2e-acceptance.md +4 -0
  18. package/dist/plugin/skills/do/e2e-repair.md +1 -1
  19. package/dist/plugin/skills/do/open-prs/forward.md +3 -3
  20. package/dist/plugin/skills/do/pre-flight.md +4 -3
  21. package/dist/plugin/skills/do/wave-e2e.md +3 -3
  22. package/dist/plugin/skills/do/wave-or-stream.md +51 -0
  23. package/dist/plugin/skills/muggle-do/SKILL.md +6 -2
  24. package/dist/release-manifest.json +3 -3
  25. package/package.json +1 -1
  26. package/plugin/.claude-plugin/plugin.json +1 -1
  27. package/plugin/.codex-mcp.json +1 -1
  28. package/plugin/.codex-plugin/plugin.json +1 -1
  29. package/plugin/.cursor-plugin/plugin.json +1 -1
  30. package/plugin/.mcp.json +1 -1
  31. package/plugin/agents/acceptance-tester.md +18 -2
  32. package/plugin/hooks/README.md +5 -4
  33. package/plugin/hooks/codex-hooks.json +2 -2
  34. package/plugin/hooks/hooks.json +2 -2
  35. package/plugin/scripts/guardrail-record-delegation.sh +25 -0
  36. package/plugin/scripts/guardrail-walkthrough-gate.sh +6 -6
  37. package/plugin/scripts/guardrails.mjs +161 -32
  38. package/plugin/skills/do/background-e2e.md +89 -0
  39. package/plugin/skills/do/e2e-acceptance.md +4 -0
  40. package/plugin/skills/do/e2e-repair.md +1 -1
  41. package/plugin/skills/do/open-prs/forward.md +3 -3
  42. package/plugin/skills/do/pre-flight.md +4 -3
  43. package/plugin/skills/do/wave-e2e.md +3 -3
  44. package/plugin/skills/do/wave-or-stream.md +51 -0
  45. package/plugin/skills/muggle-do/SKILL.md +6 -2
  46. /package/dist/{chunk-HOKMW4AL.js → chunk-PQVRAFNE.js} +0 -0
@@ -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.208"
12
+ "version": "5.26.0-staging.209"
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-HOKMW4AL.js';
2
+ import { runCli } from './chunk-PQVRAFNE.js';
3
3
  import './chunk-ZR7KLGHQ.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-HOKMW4AL.js';
1
+ export { src_exports as commands, createUnifiedMcpServer, server_exports as server } from './chunk-PQVRAFNE.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-ZR7KLGHQ.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.208",
4
+ "version": "5.26.0-staging.209",
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.208",
7
+ "@muggleai/works@5.26.0-staging.209",
8
8
  "serve"
9
9
  ],
10
10
  "env": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muggle",
3
- "version": "5.26.0-staging.208",
3
+ "version": "5.26.0-staging.209",
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.208",
5
+ "version": "5.26.0-staging.209",
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.208",
7
+ "@muggleai/works@5.26.0-staging.209",
8
8
  "serve"
9
9
  ]
10
10
  }
@@ -30,6 +30,8 @@ The orchestrator provides a dispatch prompt with:
30
30
 
31
31
  - **What to do:** Run tests, import tests, manage preferences, check status, or repair.
32
32
  - **For testing:** Target URL and what to test — a feature description, acceptance criteria, or "run regression on recent changes."
33
+ - **For a background change run:** one change's brief — its session directory, repo, worktree, branch, head SHA, validation target, project, scope, and the absolute path of the stage file to execute. Read that file and execute its steps yourself, starting the app from the brief's worktree; its tool calls are the run. Every value you need is in the brief — the conversation that wrote it is not available to you.
34
+ - **For a background wave run:** the same brief, carrying every member of the wave — a change split across repos whose PRs only work together — each with its own repo, worktree, branch, head SHA and PR, plus the wave stage file. Start every member's services from that member's worktree, run each test case once against the combined stack, and name the member each failure implicates. A brief whose PRs are unrelated changes is a stream, not a wave: test only the one change it names, and leave its siblings to their own runs.
33
35
  - **For import:** Path to test files or documents to import.
34
36
  - **For preferences:** Which preference to view or change, or "show all."
35
37
  - **For status/repair:** No additional input needed.
@@ -81,6 +83,16 @@ For each **passed** test, list the name only:
81
83
  ### {Test Name} — PASS
82
84
  ```
83
85
 
86
+ ### When Running a Background Change Run
87
+
88
+ Return the report in the Output format of the stage file the brief named, followed by one line naming what the run tested — one line per member for a wave run, and each failed test naming its `implicatedRepo` (the member whose change the failing step points at, or `unknown`):
89
+
90
+ ```
91
+ Tested: {owner/repo}@{head sha}
92
+ ```
93
+
94
+ The orchestrator posts the report only while every listed SHA is still its branch head, and only to that change's PRs — for a wave, the same report to every member's PR. A run that could not start reports its verdict and reason in the same format — never return without a report.
95
+
84
96
  ### When Importing Tests
85
97
 
86
98
  Report:
@@ -108,5 +120,9 @@ Report:
108
120
  3. **Describe problems from the user's perspective.** "The checkout button is not clickable after adding an item to the cart" — not "onClick handler missing on Button component in CartPage.tsx."
109
121
  4. **Do not modify application code.** Report findings; coding agents act on them.
110
122
  5. **Do not decide when to run.** The orchestrator dispatches; you execute and report.
111
- 6. **Do not choose local vs remote.** The `muggle-test` skill handles routing based on the target URL and user preferences.
112
- 7. **Use skills, not raw MCP tools.** The orchestrator pastes the full skill text into your dispatch prompt. Follow the skill's instructions exactly.
123
+ 6. **Do not choose local vs remote.** The `muggle-test` skill handles routing based on the target URL and user preferences; in a background change run, the brief's validation target decides.
124
+ 7. **Use skills, not raw MCP tools.** The orchestrator pastes the full skill text into your dispatch prompt. Follow the skill's instructions exactly. A background change run is the one exception: the stage file its brief names is the procedure, and its MCP calls are its steps.
125
+ 8. **Never dispatch another agent or fork.** Run every step in your own context. A run handed further down escapes the orchestrator's one-local-run-at-a-time queue and lands on the browser alongside the next run; two studio runs at once corrupt each other.
126
+ 9. **Never run alongside another local run.** Before your first local execution, list the local run results; if a run is still executing, return `BLOCKED — another local run in flight` instead of starting one.
127
+ 10. **Never write to a PR or the repo.** No commits, pushes, PR edits, comments, walkthrough posts, or watcher arms — the orchestrator owns every PR write, because only it knows which change a PR belongs to.
128
+ 11. **Never declare a skip marker in a background change run.** Return the skip code in the report; the orchestrator declares it from the PR's own worktree, where it settles that PR alone.
@@ -35,22 +35,23 @@ 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` / `walkthroughPosted` / `walkthroughSkipped` session state |
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 |
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
+ | `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 |
41
42
  | `PostToolUse` (Skill + muggle telemetry-skill-emit) | `guardrail-skill-stages.sh` | advise | a skill this plugin ships was invoked; its `SKILL.md` frontmatter may declare `mandatoryStages`. Registered on the skill's own MCP announcement too, so the declaration still lands if the Skill payload ever stops carrying a name. A muggle-test announcement is also an E2E run (the clean SKIP verdict), recorded here alone: the state store drops a write that cannot take the session's lock in time, so a second writer for one emit could lose either record | — | record `lastInvokedSkillName` + `mandatoryStages` (and `e2eRun` for a muggle-test announcement), and name the declared files as required reading at the moment of use |
42
43
  | `PostToolUse` (Read) | `guardrail-record-stage-read.sh` | record | a markdown file under a `skills/` directory was opened | — | append to `stagesRead` — how the stage gate tells a stage that was read from one that was skipped |
43
44
  | `PostToolUse` (Bash + muggle telemetry-event-emit / user-feedback-create) | `guardrail-record-stage-signals.sh` | record | a Step 6f `pre-execution-classification` emit, debug-path evidence for a failed run (a `*-failure-classified\|resolved` emit or feedback naming it), or a `MUGGLE_STAGE_SKIP` / `MUGGLE_CLASSIFY_SKIP` / `MUGGLE_DEBUG_SKIP` marker | — | set `classifiedTestCaseIds` / `debuggedRuns` / the matching skip flag |
44
45
  | `PostToolUse` (Bash) | `guardrail-record-comment-replies.sh` | record | an unresolved-thread fetch named review threads still awaiting an answer (classified by the `<!-- muggle-do:bot -->` marker, never the author login), a threaded reply the provider **confirmed** answered comments in one, or a `MUGGLE_REPLY_SKIP` marker deferred them | — | claim each thread and cover the comments answered, in the per-PR ledger beside the muggle-do slot |
45
46
  | `PreToolUse` (Bash, `if` a command names `gh`/`glab`) | `guardrail-report-format.sh` | **enforce** | a `gh pr comment\|create\|edit` body — or a `gh api … issues/comments/<id>` PATCH editing one — reads like an E2E report but lacks the `build-pr-section` sentinel | — | **deny** — render via `muggle build-pr-section` instead |
46
47
  | `PreToolUse` (muggle local execute/replay) | `guardrail-classify-gate.sh` | **enforce** | `muggle-test` is the skill in play and the target test case has no `pre-execution-classification` this session | — | **deny** — run Step 6f first (it calls `muggle-remote-test-script-list`, which is where the run learns the case has never passed) or record a legitimate skip via `MUGGLE_CLASSIFY_SKIP`. Scoped to `muggle-test`, so the single-target skills that legitimately skip classification are untouched; fails open when the test case can't be resolved |
47
- | `Stop` | `guardrail-e2e-gate.sh` | **enforce** | unit tests passed this session, no E2E ran yet, and no skip was recorded | `autoE2ETest` | **block** the turn until E2E runs via `muggle-test` or a `MUGGLE_E2E_SKIP` marker records a legitimate skip (full message once, one-line reminders after; releases after 3 blocks) |
48
+ | `Stop` | `guardrail-e2e-gate.sh` | **enforce** | unit tests passed this session, no E2E ran yet, and no skip was recorded | `autoE2ETest` | **block** the turn until E2E runs via `muggle-test` or a `MUGGLE_E2E_SKIP` marker records a legitimate skip (full message once, one-line reminders after; releases after 3 blocks). Quiet while a background acceptance-tester is in flight |
48
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) |
49
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 |
50
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 |
51
- | `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 in play 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 an accepted E2E skip, 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 (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. 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 and stays open until one lands |
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
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) |
53
- | `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) |
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 |
54
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 |
55
56
  | `Stop` | `guardrail-capability-claim.sh` | **enforce** | the closing turn tells the user a login- or code-gated flow can't be tested, reached, or verified | — | **block** once, citing `_shared/identity-and-inbox.md`: the managed profile's live inbox, provisioned number, stored TOTP secret, credentials, and CAPTCHA solver clear exactly that blocker. Reads the claim out of the transcript, since a Stop payload carries no message text. Per-sentence matching, and a sentence naming a voice call, an OAuth-only provider, or a deployment with no number provisioned never fires — those limits are real. Nudges once per session, then stays quiet, so a misread costs one turn |
56
57
  | `UserPromptSubmit` | `guardrail-build-router.sh` | advise | a build/implement/fix request (first one this session) | `autoRouteBuildToMuggleDo` | route the work through `muggle-do` (build delegated to superpowers) |
@@ -102,10 +102,10 @@
102
102
  "hooks": [
103
103
  {
104
104
  "type": "command",
105
- "command": "env MUGGLE_HOOK_HOST=codex bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-offer-ran.sh\"",
105
+ "command": "env MUGGLE_HOOK_HOST=codex bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-offer-ran.sh guardrail-record-delegation.sh",
106
106
  "async": false,
107
107
  "timeout": 10,
108
- "commandWindows": "node \"${CLAUDE_PLUGIN_ROOT}\\scripts\\codex-hook-windows.mjs\" \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-offer-ran.sh\""
108
+ "commandWindows": "node \"${CLAUDE_PLUGIN_ROOT}\\scripts\\codex-hook-windows.mjs\" \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-offer-ran.sh guardrail-record-delegation.sh"
109
109
  }
110
110
  ]
111
111
  }
@@ -133,11 +133,11 @@
133
133
  ]
134
134
  },
135
135
  {
136
- "matcher": "AskUserQuestion",
136
+ "matcher": "AskUserQuestion|Agent|Task",
137
137
  "hooks": [
138
138
  {
139
139
  "type": "command",
140
- "command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-offer-ran.sh\"",
140
+ "command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-offer-ran.sh guardrail-record-delegation.sh",
141
141
  "async": false,
142
142
  "timeout": 1
143
143
  }
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env bash
2
+ set -uo pipefail
3
+
4
+ # Background acceptance-tester observer (PostToolUse/Agent|Task). Records that
5
+ # a change's E2E was handed to a muggle:acceptance-tester running in the
6
+ # background, so the E2E, walkthrough and debug-path Stop gates hold off rather
7
+ # than steer the main session into a second browser run alongside the agent's.
8
+ # Emits no directive.
9
+ #
10
+ # Pre-filter: most dispatches are other agents, so only a payload naming the
11
+ # acceptance-tester spawns Node. Degrades to {}.
12
+
13
+ guardrail_script_dir="${BASH_SOURCE[0]%/*}"
14
+ [[ $guardrail_script_dir == "${BASH_SOURCE[0]}" ]] && guardrail_script_dir=.
15
+ . "$guardrail_script_dir/guardrail-lib.sh"
16
+
17
+ GUARDRAIL_SUBCOMMAND="record-delegation"
18
+
19
+ guardrail_wants() {
20
+ guardrail_payload_matches 'acceptance-tester'
21
+ }
22
+
23
+ if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
24
+ guardrail_run_standalone "$GUARDRAIL_SUBCOMMAND"
25
+ fi
@@ -11,11 +11,11 @@ set -uo pipefail
11
11
  # it fires on EVERY turn end. There is no command payload to key off, so the
12
12
  # pre-filter reads the same per-session state file guardrails.mjs uses and only
13
13
  # spawns Node when the gate could actually fire — i.e. an acceptance run or an
14
- # unsettled skip is recorded and the walkthrough is neither posted nor skipped.
15
- # On the overwhelming majority of turns (no E2E this session) the state file is
16
- # absent or carries neither, so we return {} in-shell and never pay Node
17
- # cold-start — which also means the gate's `gh` lookups only ever run on turns
18
- # that could genuinely owe a walkthrough. Degrades to {}.
14
+ # unsettled skip is recorded and the walkthrough is neither verified on every
15
+ # PR nor skipped. On the overwhelming majority of turns (no E2E this session)
16
+ # the state file is absent or carries neither, so we return {} in-shell and
17
+ # never pay Node cold-start — which also means the gate's `gh` lookups only
18
+ # ever run on turns that could genuinely owe a walkthrough. Degrades to {}.
19
19
 
20
20
  guardrail_script_dir="${BASH_SOURCE[0]%/*}"
21
21
  [[ $guardrail_script_dir == "${BASH_SOURCE[0]}" ]] && guardrail_script_dir=.
@@ -25,7 +25,7 @@ GUARDRAIL_SUBCOMMAND="walkthrough-gate"
25
25
 
26
26
  guardrail_wants() {
27
27
  guardrail_load_state || return 1
28
- guardrail_state_has '"walkthroughPosted": true' && return 1
28
+ guardrail_state_has '"walkthroughsVerified": true' && return 1
29
29
  guardrail_state_has '"walkthroughReleased": true' && return 1
30
30
  guardrail_state_has '"walkthroughSkipped": true' && return 1
31
31
  guardrail_state_has '"e2eRun": true' && return 0
@@ -78,6 +78,12 @@ var CALL_FAILURE_SIGNALS = [
78
78
  var FORGE_TERMINAL_CMD = /\b(?:gh\s+pr\s+(?:merge|close|reopen)|glab\s+mr\s+(?:merge|close|reopen))\b/;
79
79
  var WATCH_TERMINAL_CMD = /pr-watch-(?:loop|arm)\.sh/;
80
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;
81
87
 
82
88
  // src/guardrails/store/fileLock.ts
83
89
  function isProcessAlive(pid) {
@@ -210,6 +216,7 @@ var GuardrailBackgroundJob = /* @__PURE__ */ ((GuardrailBackgroundJob2) => {
210
216
  GuardrailBackgroundJob2["ScanWalkthroughs"] = "scan-walkthroughs";
211
217
  GuardrailBackgroundJob2["ReserveWalkthroughComment"] = "reserve-walkthrough-comment";
212
218
  GuardrailBackgroundJob2["SettleWalkthroughSkipped"] = "settle-walkthrough-skipped";
219
+ GuardrailBackgroundJob2["SettleBranchWalkthroughSkipped"] = "settle-branch-walkthrough-skipped";
213
220
  GuardrailBackgroundJob2["SettleWalkthroughUnreasoned"] = "settle-walkthrough-unreasoned";
214
221
  GuardrailBackgroundJob2["SettleWalkthroughNoAppLogicChange"] = "settle-walkthrough-no-app-logic-change";
215
222
  GuardrailBackgroundJob2["ScanWatchPrStates"] = "scan-watch-pr-states";
@@ -248,8 +255,6 @@ function isShellToolCall(input2) {
248
255
  }
249
256
 
250
257
  // src/guardrails/prOpened.ts
251
- var PR_URL = /https:\/\/github\.com\/[^/\s]+\/[^/\s]+\/pull\/\d+/;
252
- var MR_URL = /https?:\/\/[^/\s]+\/[^\s]+\/-\/merge_requests\/\d+/;
253
258
  var CREATE_CMD = /\bgh\s+pr\s+(create|ready)\b/;
254
259
  var MR_CREATE_CMD = /\bglab\s+mr\s+create\b|\bglab\s+mr\s+update\b.*--ready\b/;
255
260
  function detectPrOpened(input2) {
@@ -258,7 +263,7 @@ function detectPrOpened(input2) {
258
263
  if (!CREATE_CMD.test(cmd) && !MR_CREATE_CMD.test(cmd)) return null;
259
264
  const out = `${input2.tool_response?.stdout ?? ""}
260
265
  ${input2.tool_response?.output ?? ""}`;
261
- const m = out.match(PR_URL) ?? out.match(MR_URL);
266
+ const m = out.match(GITHUB_PR_URL) ?? out.match(GITLAB_MR_URL);
262
267
  return m ? m[0] : null;
263
268
  }
264
269
 
@@ -638,6 +643,38 @@ function classificationGateDecision(state, input2) {
638
643
  return { deny: true, testCaseId };
639
644
  }
640
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
+
641
678
  // src/guardrails/debugPath.ts
642
679
  var DEBUG_SKIP_MARKER = /^\s*echo\s+["']?MUGGLE_DEBUG_SKIP\b/;
643
680
  var serialize = (input2) => `${JSON.stringify(input2.tool_input ?? {})}
@@ -691,10 +728,10 @@ function undebuggedFailedRuns(state) {
691
728
  const debugged = new Set(state.debuggedRuns ?? []);
692
729
  return (state.failedRuns ?? []).filter((runId) => !debugged.has(runId));
693
730
  }
694
- function debugGateDecision(state, maxBlocks = MAX_DEBUG_BLOCKS) {
731
+ function debugGateDecision(state, maxBlocks = MAX_DEBUG_BLOCKS, now = Date.now()) {
695
732
  const blockCount = state.debugBlockCount ?? 0;
696
733
  const undebugged = undebuggedFailedRuns(state);
697
- if (state.debugSkipped === true || undebugged.length === 0) {
734
+ if (state.debugSkipped === true || undebugged.length === 0 || isE2eDelegationInFlight(state, now)) {
698
735
  return { action: "none" /* None */, blockCount, undebugged };
699
736
  }
700
737
  if (blockCount >= maxBlocks) {
@@ -823,9 +860,11 @@ function applyRecordedRun(state, run) {
823
860
  }
824
861
  return next;
825
862
  }
826
- function e2eGateDecision(state, maxBlocks = MAX_E2E_BLOCKS) {
863
+ function e2eGateDecision(state, maxBlocks = MAX_E2E_BLOCKS, now = Date.now()) {
827
864
  const blockCount = state.e2eBlockCount ?? 0;
828
- if (!shouldRunE2E(state)) return { action: "none" /* None */, blockCount };
865
+ if (!shouldRunE2E(state) || isE2eDelegationInFlight(state, now)) {
866
+ return { action: "none" /* None */, blockCount };
867
+ }
829
868
  if (blockCount >= maxBlocks) return { action: "release" /* Release */, blockCount };
830
869
  return { action: "block" /* Block */, blockCount: blockCount + 1 };
831
870
  }
@@ -855,7 +894,7 @@ var SHORT_SHA_LENGTH = 7;
855
894
  var GH_COMMENT_TIMEOUT_MS = 1e4;
856
895
 
857
896
  // src/pr-walkthrough/gh.ts
858
- var GITHUB_PR_URL = /^https:\/\/github\.com\/([^/\s]+)\/([^/\s]+)\/pull\/(\d+)/;
897
+ var GITHUB_PR_URL2 = /^https:\/\/github\.com\/([^/\s]+)\/([^/\s]+)\/pull\/(\d+)/;
859
898
  var GH_CALLS_ENV = "MUGGLE_GUARDRAIL_GH_CALLS";
860
899
  var defaultGhRunner = (args, input2) => {
861
900
  if (process.env[GH_CALLS_ENV] === "off") return null;
@@ -874,7 +913,7 @@ var defaultGhRunner = (args, input2) => {
874
913
  }
875
914
  };
876
915
  function parsePrUrl(prUrl) {
877
- const parts = prUrl.match(GITHUB_PR_URL);
916
+ const parts = prUrl.match(GITHUB_PR_URL2);
878
917
  if (!parts) return null;
879
918
  return { repo: `${parts[1]}/${parts[2]}`, prNumber: Number(parts[3]) };
880
919
  }
@@ -1324,14 +1363,53 @@ function detectWalkthroughPost(input2, read = defaultFileReader) {
1324
1363
  if (callFailed(input2)) return false;
1325
1364
  return collectPrPostText(cmd, input2.cwd, read).includes(REPORT_SENTINEL);
1326
1365
  }
1327
- function applyWalkthroughPosted(state, posted) {
1328
- if (!posted || state.walkthroughPosted === true) return state;
1329
- return { ...state, walkthroughPosted: true };
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] };
1330
1375
  }
1331
1376
  function applyWalkthroughSkip(state, skipped) {
1332
1377
  if (!skipped || state.walkthroughSkipped === true) return state;
1333
1378
  return { ...state, walkthroughSkipped: true };
1334
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
1335
1413
  function runGh(args) {
1336
1414
  const timeoutMs = boundedChildTimeoutMs(GH_LOOKUP_TIMEOUT_MS);
1337
1415
  if (timeoutMs === null) return null;
@@ -1364,10 +1442,10 @@ function scanForOwedWalkthroughs(state, lookup = defaultPrWalkthroughLookup) {
1364
1442
  const candidates = new Set(state.prsHandled);
1365
1443
  const branchPrUrl = lookup.branchPrUrl();
1366
1444
  if (branchPrUrl) candidates.add(branchPrUrl);
1367
- const acceptsSkip = state.e2eRun !== true;
1368
1445
  const owed = [];
1369
1446
  const verified2 = [];
1370
1447
  for (const prUrl of candidates) {
1448
+ const acceptsSkip = state.e2eRun !== true || isPrCoveredBySkip(state, prUrl);
1371
1449
  if (lookup.prCarriesWalkthrough(prUrl, acceptsSkip)) verified2.push(prUrl);
1372
1450
  else owed.push(prUrl);
1373
1451
  }
@@ -1376,11 +1454,22 @@ function scanForOwedWalkthroughs(state, lookup = defaultPrWalkthroughLookup) {
1376
1454
  function isWalkthroughGateArmed(state) {
1377
1455
  const isSkipUnsettled = state.e2eSkipDeclaration !== void 0 && state.e2eSkipSettledOnPrs !== true;
1378
1456
  const isOwed = state.e2eRun === true || isSkipUnsettled;
1379
- return isOwed && state.walkthroughPosted !== true && state.walkthroughSkipped !== true;
1457
+ return isOwed && state.walkthroughsVerified !== true && state.walkthroughSkipped !== true;
1380
1458
  }
1381
1459
  function isWalkthroughScanCurrent(scan, state) {
1382
1460
  const scanned = new Set(scan.prsHandled);
1383
- return scanned.size === new Set(state.prsHandled).size && state.prsHandled.every((prUrl) => scanned.has(prUrl));
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 };
1384
1473
  }
1385
1474
  function walkthroughGateDecision(state, owedPrUrls, maxBlocks = MAX_WALKTHROUGH_BLOCKS) {
1386
1475
  const blockCount = state.walkthroughBlockCount ?? 0;
@@ -2164,8 +2253,12 @@ function prOpened() {
2164
2253
  if (!url) return "{}";
2165
2254
  if (readState(sessionId).prsHandled.includes(url)) return "{}";
2166
2255
  markPrHandled(sessionId, url);
2167
- const stateAfterOpen = commitState(sessionId, (state) => ({ ...state, e2eSkipSettledOnPrs: false })) ?? readState(sessionId);
2168
- const declaredSkip = stateAfterOpen.e2eSkipDeclaration;
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;
2169
2262
  if (declaredSkip) {
2170
2263
  startBackgroundJob("settle-walkthrough-skipped" /* SettleWalkthroughSkipped */, [url, declaredSkip.code, declaredSkip.detail]);
2171
2264
  } else {
@@ -2175,7 +2268,7 @@ function prOpened() {
2175
2268
  startBackgroundJob("scan-walkthroughs" /* ScanWalkthroughs */, [sessionId], input.cwd);
2176
2269
  }
2177
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.
2178
- ` : `Its Muggle AI visual-walkthrough comment is reserved and empty \u2014 settle it by posting the walkthrough there once E2E runs, or by recording why E2E does not apply.
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.
2179
2272
  `;
2180
2273
  const ctx = `A pull request was just opened: ${url}
2181
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.`;
@@ -2218,8 +2311,8 @@ function terminalGate() {
2218
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()}.`;
2219
2312
  return blockStop(reason, host);
2220
2313
  }
2221
- function startWalkthroughScanOnGateArming(stateBefore, committed) {
2222
- if (isWalkthroughGateArmed(committed) && !isWalkthroughGateArmed(stateBefore)) {
2314
+ function startWalkthroughScanOnGateArming(stateBefore, committed, hasPosted = false) {
2315
+ if (isWalkthroughGateArmed(committed) && (hasPosted || !isWalkthroughGateArmed(stateBefore))) {
2223
2316
  startBackgroundJob("scan-walkthroughs" /* ScanWalkthroughs */, [sessionId], input.cwd);
2224
2317
  }
2225
2318
  }
@@ -2235,17 +2328,25 @@ function recordTests() {
2235
2328
  e2eSkipCycleScoped: acceptedSkip !== null && CYCLE_SCOPED_SKIP_CODES.includes(acceptedSkip.code)
2236
2329
  };
2237
2330
  const walkthroughPosted = detectWalkthroughPost(input);
2331
+ const walkthroughPostTargets = walkthroughPosted ? detectWalkthroughPostTargets(input) : [];
2238
2332
  const failedRunId = detectFailedRunId(input);
2333
+ const isDeclaredHere = acceptedSkip !== null && !CYCLE_SCOPED_SKIP_CODES.includes(acceptedSkip.code);
2239
2334
  const record = (state) => {
2240
- const recorded = applyE2eSkipDeclaration(applyRecordedRun(state, run), acceptedSkip);
2335
+ const declared = applyE2eSkipDeclaration(applyRecordedRun(state, run), acceptedSkip);
2336
+ const recorded = isDeclaredHere ? applyE2eSkipScope(declared, normalizeWorkingTree(input.cwd)) : declared;
2241
2337
  const withWatchSkip = applyWatchSkip(recorded, isWatchSkipMarker(cmd));
2242
2338
  const withBuildSkip = applyBuildSkip(withWatchSkip, isBuildSkipMarker(cmd));
2243
- const withWalkthroughPost = applyWalkthroughPosted(withBuildSkip, walkthroughPosted);
2339
+ const withWalkthroughPost = applyWalkthroughPosted(
2340
+ withBuildSkip,
2341
+ walkthroughPosted,
2342
+ Date.now(),
2343
+ walkthroughPostTargets
2344
+ );
2244
2345
  const withWalkthroughSkip = applyWalkthroughSkip(withWalkthroughPost, isWalkthroughSkipMarker(cmd));
2245
2346
  return failedRunId ? applyFailedRun(withWalkthroughSkip, failedRunId) : withWalkthroughSkip;
2246
2347
  };
2247
2348
  const next = commitState(sessionId, record) ?? record(readState(sessionId));
2248
- startWalkthroughScanOnGateArming(stateBefore, next);
2349
+ startWalkthroughScanOnGateArming(stateBefore, next, walkthroughPosted);
2249
2350
  if (acceptedSkip) recordSkipReasonOnPrs(next, acceptedSkip);
2250
2351
  if (judgedSkip && !judgedSkip.accepted) {
2251
2352
  return envelope("PostToolUse", explainRejection(judgedSkip), host);
@@ -2257,9 +2358,17 @@ function recordSkipReasonOnPrs(state, skip) {
2257
2358
  startBackgroundJob("settle-walkthrough-no-app-logic-change" /* SettleWalkthroughNoAppLogicChange */, [skip.detail], input.cwd);
2258
2359
  return;
2259
2360
  }
2260
- for (const prUrl of state.prsHandled) {
2361
+ for (const prUrl of state.prsHandled.filter((handledPrUrl) => isPrCoveredBySkip(state, handledPrUrl))) {
2261
2362
  startBackgroundJob("settle-walkthrough-skipped" /* SettleWalkthroughSkipped */, [prUrl, skip.code, skip.detail]);
2262
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 "{}";
2263
2372
  }
2264
2373
  function skillStages() {
2265
2374
  const skillName = resolveSkillNameFromToolInput(input.tool_input);
@@ -2421,21 +2530,25 @@ function walkthroughGate() {
2421
2530
  const scan = readWalkthroughScan(sessionId);
2422
2531
  startBackgroundJob("scan-walkthroughs" /* ScanWalkthroughs */, [sessionId], input.cwd);
2423
2532
  if (!scan || !isWalkthroughScanCurrent(scan, state)) return "{}";
2424
- const owedSkip = state.e2eRun === true ? void 0 : state.e2eSkipDeclaration;
2425
- if (scan.owed.length === 0) {
2426
- if (scan.verified.length > 0) {
2427
- writeState(owedSkip ? { ...state, e2eSkipSettledOnPrs: true } : { ...state, walkthroughPosted: true });
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 });
2428
2537
  }
2429
2538
  return "{}";
2430
2539
  }
2431
- const decision = walkthroughGateDecision(state, scan.owed);
2540
+ const decision = walkthroughGateDecision(state, withoutDelegatedPrs(unposted, state, Date.now()));
2432
2541
  if (decision.action === "release" /* Release */) return releaseGate("walkthroughReleased");
2433
2542
  if (decision.action !== "block" /* Block */) return "{}";
2434
2543
  state.walkthroughBlockCount = decision.blockCount;
2435
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
+ }
2436
2550
  const prList = decision.owed.join(", ");
2437
- if (owedSkip) return blockOnUnsettledSkip(owedSkip, decision.owed, decision.blockCount);
2438
- 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>"\`.`;
2439
2552
  return blockStop(reason, host);
2440
2553
  }
2441
2554
  function blockOnUnsettledSkip(owedSkip, owedPrUrls, blockCount) {
@@ -2565,6 +2678,7 @@ var handlers = {
2565
2678
  "pr-terminal": prTerminal,
2566
2679
  "offer-ran": offerRan,
2567
2680
  "record-tests": recordTests,
2681
+ "record-delegation": recordDelegation,
2568
2682
  "e2e-gate": e2eGate,
2569
2683
  "terminal-gate": terminalGate,
2570
2684
  "watch-gate": watchGate,
@@ -2587,9 +2701,15 @@ var handlers = {
2587
2701
  var jobArgs = process.argv.slice(3);
2588
2702
  function scanWalkthroughsJob() {
2589
2703
  const scannedSessionId = jobArgs[0] ?? "unknown";
2704
+ const startedAt = Date.now();
2590
2705
  const state = readState(scannedSessionId);
2591
2706
  const scan = scanForOwedWalkthroughs(state);
2592
- writeWalkthroughScan(scannedSessionId, { prsHandled: state.prsHandled, owed: scan.owed, verified: scan.verified });
2707
+ writeWalkthroughScan(scannedSessionId, {
2708
+ prsHandled: state.prsHandled,
2709
+ owed: scan.owed,
2710
+ verified: scan.verified,
2711
+ startedAt
2712
+ });
2593
2713
  return "{}";
2594
2714
  }
2595
2715
  function reserveWalkthroughCommentJob() {
@@ -2605,6 +2725,14 @@ function settleWalkthroughSkippedJob() {
2605
2725
  settleWalkthroughCommentAsSkipped(prUrl, skip.code, skip.detail);
2606
2726
  return JSON.stringify({ settled: isWalkthroughSettledOnPr(prUrl) });
2607
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
+ }
2608
2736
  function settleWalkthroughUnreasonedJob() {
2609
2737
  const [prUrl] = jobArgs;
2610
2738
  if (prUrl) settleWalkthroughCommentAsUnreasoned(prUrl);
@@ -2630,6 +2758,7 @@ var backgroundJobs = {
2630
2758
  ["scan-walkthroughs" /* ScanWalkthroughs */]: scanWalkthroughsJob,
2631
2759
  ["reserve-walkthrough-comment" /* ReserveWalkthroughComment */]: reserveWalkthroughCommentJob,
2632
2760
  ["settle-walkthrough-skipped" /* SettleWalkthroughSkipped */]: settleWalkthroughSkippedJob,
2761
+ ["settle-branch-walkthrough-skipped" /* SettleBranchWalkthroughSkipped */]: settleBranchWalkthroughSkippedJob,
2633
2762
  ["settle-walkthrough-unreasoned" /* SettleWalkthroughUnreasoned */]: settleWalkthroughUnreasonedJob,
2634
2763
  ["settle-walkthrough-no-app-logic-change" /* SettleWalkthroughNoAppLogicChange */]: settleWalkthroughNoAppLogicChangeJob,
2635
2764
  ["scan-watch-pr-states" /* ScanWatchPrStates */]: scanWatchPrStatesJob