@muggleai/works 5.32.0-staging.289 → 5.32.0-staging.291

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.32.0-staging.289"
12
+ "version": "5.32.0-staging.291"
13
13
  }
14
14
  ]
15
15
  }
@@ -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.32.0-staging.289",
4
+ "version": "5.32.0-staging.291",
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.32.0-staging.289",
7
+ "@muggleai/works@5.32.0-staging.291",
8
8
  "serve"
9
9
  ],
10
10
  "env": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muggle",
3
- "version": "5.32.0-staging.289",
3
+ "version": "5.32.0-staging.291",
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.32.0-staging.289",
5
+ "version": "5.32.0-staging.291",
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.32.0-staging.289",
7
+ "@muggleai/works@5.32.0-staging.291",
8
8
  "serve"
9
9
  ]
10
10
  }
@@ -28,10 +28,10 @@
28
28
  "hooks": [
29
29
  {
30
30
  "type": "command",
31
- "command": "env MUGGLE_HOOK_HOST=codex bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-walkthrough-heading.sh",
31
+ "command": "env MUGGLE_HOOK_HOST=codex bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-draft-pr-gate.sh guardrail-walkthrough-heading.sh",
32
32
  "async": false,
33
33
  "timeout": 10,
34
- "commandWindows": "node \"${CLAUDE_PLUGIN_ROOT}\\scripts\\codex-hook-windows.mjs\" \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-walkthrough-heading.sh"
34
+ "commandWindows": "node \"${CLAUDE_PLUGIN_ROOT}\\scripts\\codex-hook-windows.mjs\" \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-draft-pr-gate.sh guardrail-walkthrough-heading.sh"
35
35
  }
36
36
  ]
37
37
  },
@@ -26,28 +26,28 @@
26
26
  {
27
27
  "type": "command",
28
28
  "if": "Bash(*gh *)",
29
- "command": "set -- guardrail-dispatch.sh guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-walkthrough-heading.sh; . \"${CLAUDE_PLUGIN_ROOT}/scripts/hook-entry.sh\"",
29
+ "command": "set -- guardrail-dispatch.sh guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-draft-pr-gate.sh guardrail-walkthrough-heading.sh; . \"${CLAUDE_PLUGIN_ROOT}/scripts/hook-entry.sh\"",
30
30
  "async": false,
31
31
  "timeout": 1
32
32
  },
33
33
  {
34
34
  "type": "command",
35
35
  "if": "Bash(*glab *)",
36
- "command": "set -- guardrail-dispatch.sh guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-walkthrough-heading.sh; . \"${CLAUDE_PLUGIN_ROOT}/scripts/hook-entry.sh\"",
36
+ "command": "set -- guardrail-dispatch.sh guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-draft-pr-gate.sh guardrail-walkthrough-heading.sh; . \"${CLAUDE_PLUGIN_ROOT}/scripts/hook-entry.sh\"",
37
37
  "async": false,
38
38
  "timeout": 1
39
39
  },
40
40
  {
41
41
  "type": "command",
42
42
  "if": "PowerShell(*gh *)",
43
- "command": "set -- guardrail-dispatch.sh guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-walkthrough-heading.sh; . \"${CLAUDE_PLUGIN_ROOT}/scripts/hook-entry.sh\"",
43
+ "command": "set -- guardrail-dispatch.sh guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-draft-pr-gate.sh guardrail-walkthrough-heading.sh; . \"${CLAUDE_PLUGIN_ROOT}/scripts/hook-entry.sh\"",
44
44
  "async": false,
45
45
  "timeout": 1
46
46
  },
47
47
  {
48
48
  "type": "command",
49
49
  "if": "PowerShell(*glab *)",
50
- "command": "set -- guardrail-dispatch.sh guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-walkthrough-heading.sh; . \"${CLAUDE_PLUGIN_ROOT}/scripts/hook-entry.sh\"",
50
+ "command": "set -- guardrail-dispatch.sh guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-draft-pr-gate.sh guardrail-walkthrough-heading.sh; . \"${CLAUDE_PLUGIN_ROOT}/scripts/hook-entry.sh\"",
51
51
  "async": false,
52
52
  "timeout": 1
53
53
  }
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env bash
2
+ set -uo pipefail
3
+
4
+ # Draft-PR gate (PreToolUse, Bash). Denies opening a PR/MR as a draft — `gh pr create
5
+ # --draft`, `glab mr create --draft|--wip`, a GitLab `Draft:` title — and turning an open
6
+ # one back into a draft (`gh pr ready --undo`, `convertPullRequestToDraft`). Muggle opens
7
+ # every PR ready for review.
8
+ #
9
+ # Must stay synchronous — only a sync PreToolUse hook can deny — and it fires before every
10
+ # Bash call, so a keyword pre-filter on the command keeps Node off the hot path. The filter
11
+ # is deliberately looser than the gate (any `draft`/`wip`/`--undo`/` -d` next to gh or glab);
12
+ # guardrails.mjs makes the exact call. Degrades to {} so it never blocks an unrelated command.
13
+
14
+ guardrail_script_dir="${BASH_SOURCE[0]%/*}"
15
+ [[ $guardrail_script_dir == "${BASH_SOURCE[0]}" ]] && guardrail_script_dir=.
16
+ . "$guardrail_script_dir/guardrail-lib.sh"
17
+
18
+ GUARDRAIL_SUBCOMMAND="draft-pr-gate"
19
+
20
+ guardrail_wants() {
21
+ guardrail_fields_match command '(gh|glab)[[:space:]].*(draft|wip|--undo|[[:space:]]-d([[:space:]]|$))'
22
+ }
23
+
24
+ if guardrail_is_hook_script; then
25
+ guardrail_run_standalone "$GUARDRAIL_SUBCOMMAND"
26
+ fi
@@ -138,6 +138,15 @@ var GUARDRAIL_SUBCOMMAND_ASSIGNMENT = /^GUARDRAIL_SUBCOMMAND="([\w-]+)"/m;
138
138
  var HOOK_COMMAND_SCRIPTS = /^set -- ([^;]+);/;
139
139
  var GUARDRAIL_DISPATCH_SCRIPT = "guardrail-dispatch.sh";
140
140
  var MUGGLE_DO_STAGES_AFTER_BUILD = "impact \u2192 unit tests \u2192 PR \u2192 E2E \u2192 watcher";
141
+ var GITHUB_PR_CREATE_CMD = /\bgh\s+pr\s+create\b/;
142
+ var GITHUB_PR_READY_CMD = /\bgh\s+pr\s+ready\b/;
143
+ var GITLAB_MR_CREATE_OR_UPDATE_CMD = /\bglab\s+mr\s+(?:create|update)\b/;
144
+ var DRAFT_FLAG = /(?:^|\s)(?:--draft(?:=true)?|-d)(?=\s|$)/i;
145
+ var GITLAB_WIP_FLAG = /(?:^|\s)--wip(?=\s|$)/i;
146
+ var UNDO_FLAG = /(?:^|\s)--undo(?=\s|$)/;
147
+ var GITLAB_DRAFT_TITLE = /\bglab\s+mr\s+(?:create|update)\b[^;&|\n]*?(?:--title|-t)(?:=|\s+)["']?\s*(?:draft\s*:|\[draft\]|\(draft\)|wip\s*:)/i;
148
+ var GITHUB_CONVERT_TO_DRAFT_MUTATION = /\bconvertPullRequestToDraft\b/;
149
+ var GITHUB_REST_DRAFT_FIELD = /\bgh\s+api\b[^;&|\n]*\bpulls\b[^;&|\n]*\bdraft=true\b/i;
141
150
 
142
151
  // src/guardrails/store/fileLock.ts
143
152
  function isProcessAlive(pid) {
@@ -2908,6 +2917,31 @@ function evaluateReviewThreadResolve(input2) {
2908
2917
  return { deny: true, reason: RESOLVE_DENIAL };
2909
2918
  }
2910
2919
 
2920
+ // src/guardrails/draftPr.ts
2921
+ var QUOTED_STRING = /"(?:[^"\\]|\\.)*"|'[^']*'/g;
2922
+ var COMMAND_SEPARATOR = /&&|\|\||[;|\n]/;
2923
+ function unquotedSegments(command) {
2924
+ return command.replace(QUOTED_STRING, '""').split(COMMAND_SEPARATOR);
2925
+ }
2926
+ function detectDraftPrCommand(command) {
2927
+ for (const segment of unquotedSegments(command)) {
2928
+ if (GITHUB_PR_CREATE_CMD.test(segment) && DRAFT_FLAG.test(segment)) return true;
2929
+ if (GITHUB_PR_READY_CMD.test(segment) && UNDO_FLAG.test(segment)) return true;
2930
+ if (GITLAB_MR_CREATE_OR_UPDATE_CMD.test(segment) && (DRAFT_FLAG.test(segment) || GITLAB_WIP_FLAG.test(segment))) {
2931
+ return true;
2932
+ }
2933
+ }
2934
+ if (GITLAB_DRAFT_TITLE.test(command)) return true;
2935
+ if (PROVIDER_API_INVOCATION.test(command) && GITHUB_CONVERT_TO_DRAFT_MUTATION.test(command)) return true;
2936
+ return GITHUB_REST_DRAFT_FIELD.test(command);
2937
+ }
2938
+ var DRAFT_DENIAL = "Blocked: Muggle never opens draft PRs/MRs. Every PR goes up ready for review, so reviewers and CI start on it as soon as it opens. Re-run the command without `--draft`/`-d`/`--wip` (and without a `Draft:`/`WIP:` title prefix on GitLab). If the change is not ready for review, don't open the PR yet; if a draft already exists, mark it ready with `gh pr ready <n>` (GitLab: `glab mr update <n> --ready`).";
2939
+ function evaluateDraftPr(input2) {
2940
+ if (!isShellToolCall(input2)) return { deny: false };
2941
+ if (!detectDraftPrCommand(input2.tool_input?.command ?? "")) return { deny: false };
2942
+ return { deny: true, reason: DRAFT_DENIAL };
2943
+ }
2944
+
2911
2945
  // src/guardrails/emit.ts
2912
2946
  function envelope(eventName, context, host2) {
2913
2947
  if (!context) return "{}";
@@ -3542,6 +3576,11 @@ function resolveGate() {
3542
3576
  if (!resolveVerdict.deny || !resolveVerdict.reason) return "{}";
3543
3577
  return denyTool(resolveVerdict.reason, host);
3544
3578
  }
3579
+ function draftPrGate() {
3580
+ const draftVerdict = evaluateDraftPr(input);
3581
+ if (!draftVerdict.deny || !draftVerdict.reason) return "{}";
3582
+ return denyTool(draftVerdict.reason, host);
3583
+ }
3545
3584
  function buildRouter() {
3546
3585
  const prompt = input.prompt ?? "";
3547
3586
  const isMuggleDoInvoked = isMuggleDoForwardInvocation(prompt);
@@ -3600,6 +3639,7 @@ var handlers = {
3600
3639
  "report-gate": reportGate,
3601
3640
  "walkthrough-heading-gate": walkthroughHeadingGate,
3602
3641
  "resolve-gate": resolveGate,
3642
+ "draft-pr-gate": draftPrGate,
3603
3643
  "build-router": buildRouter,
3604
3644
  "skill-stages": skillStages,
3605
3645
  "record-stage-read": recordStageRead,
@@ -9,6 +9,8 @@ glab mr create -R <group>/<project> \
9
9
  --title "<title>" --description "$(cat <signed-file>)"
10
10
  ```
11
11
 
12
+ Never open it as a draft — no `--draft`/`--wip` and no `Draft:`/`WIP:`/`[Draft]`/`(Draft)` title prefix. Muggle opens every MR ready for review, and a PreToolUse gate denies the draft forms.
13
+
12
14
  Sign with `--mode editable` per [`../post-signature.md`](../post-signature.md) — the description this opens the MR with is the same body `mr-edit.md` refreshes later, so it carries the dedup marker from the start.
13
15
 
14
16
  `glab` prints the created MR's URL on success — capture stdout and store the URL for handoff (the watcher seeds from it, the user gets the link).
@@ -58,6 +58,8 @@ Per repo:
58
58
  - `github` → `gh pr create --title "<Step 3 title>" --body-file <signed-file> --head <branch>`, passing Step 3's title, prefix included, and the file signed in Step 4. Capture the PR URL and number.
59
59
  - `gitlab` → open the change via [`../../_shared/vcs/gitlab/mr-create.md`](../../_shared/vcs/gitlab/mr-create.md): `glab mr create --source-branch <branch> --target-branch <base> --title "<Step 3 title>" --description "..."`. Capture the MR URL and iid.
60
60
 
61
+ Never open it as a draft: no `--draft`/`-d` on `gh`, no `--draft`/`--wip` or `Draft:`/`WIP:` title prefix on `glab`, and never convert it to one afterwards. The PR goes up ready for review — that is what lets reviewers and CI start while E2E runs. A PreToolUse gate denies every draft route.
62
+
61
63
  A create that fails ends the cycle for that repo: report it under **Errors** and run no E2E for it, since the run would have no PR to settle.
62
64
 
63
65
  ## Stage 7 — report on the PR
@@ -100,7 +102,7 @@ If `prs.json` is empty, **do not arm** — record the reason in `result.md` and
100
102
 
101
103
  ## Invariants
102
104
 
103
- - Branch synced with its base before the push, never after; PR opened per non-skipped repo before Stage 6 starts; the tested head is the PR's head before its walkthrough settles; designated walkthrough comment settled via Mode A, or its skip reason stated; `prs.json`+`last_seen.json` seeded (no `cycle.json`, no `requirements.md`); Stage 7.5 cleared before arming; arming per `arm-watcher.md` is the last action.
105
+ - Branch synced with its base before the push, never after; PR opened per non-skipped repo before Stage 6 starts, ready for review — never a draft; the tested head is the PR's head before its walkthrough settles; designated walkthrough comment settled via Mode A, or its skip reason stated; `prs.json`+`last_seen.json` seeded (no `cycle.json`, no `requirements.md`); Stage 7.5 cleared before arming; arming per `arm-watcher.md` is the last action.
104
106
 
105
107
  ## Output
106
108
 
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "release": "5.26.0",
3
- "buildId": "run-289-1",
4
- "commitSha": "5d44bf0bdd34dec23b1a1626bcf9640d434dc7e9",
5
- "buildTime": "2026-11-04T07:03:17Z",
3
+ "buildId": "run-291-1",
4
+ "commitSha": "ecb60c98aeaac6e8e757ab3eb61fc7d80b17a43a",
5
+ "buildTime": "2026-11-04T07:41:43Z",
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.32.0-staging.289",
4
+ "version": "5.32.0-staging.291",
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.32.0-staging.289",
4
+ "version": "5.32.0-staging.291",
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.32.0-staging.289",
7
+ "@muggleai/works@5.32.0-staging.291",
8
8
  "serve"
9
9
  ],
10
10
  "env": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muggle",
3
- "version": "5.32.0-staging.289",
3
+ "version": "5.32.0-staging.291",
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.32.0-staging.289",
5
+ "version": "5.32.0-staging.291",
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.32.0-staging.289",
7
+ "@muggleai/works@5.32.0-staging.291",
8
8
  "serve"
9
9
  ]
10
10
  }
@@ -28,10 +28,10 @@
28
28
  "hooks": [
29
29
  {
30
30
  "type": "command",
31
- "command": "env MUGGLE_HOOK_HOST=codex bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-walkthrough-heading.sh",
31
+ "command": "env MUGGLE_HOOK_HOST=codex bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-draft-pr-gate.sh guardrail-walkthrough-heading.sh",
32
32
  "async": false,
33
33
  "timeout": 10,
34
- "commandWindows": "node \"${CLAUDE_PLUGIN_ROOT}\\scripts\\codex-hook-windows.mjs\" \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-walkthrough-heading.sh"
34
+ "commandWindows": "node \"${CLAUDE_PLUGIN_ROOT}\\scripts\\codex-hook-windows.mjs\" \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-draft-pr-gate.sh guardrail-walkthrough-heading.sh"
35
35
  }
36
36
  ]
37
37
  },
@@ -26,28 +26,28 @@
26
26
  {
27
27
  "type": "command",
28
28
  "if": "Bash(*gh *)",
29
- "command": "set -- guardrail-dispatch.sh guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-walkthrough-heading.sh; . \"${CLAUDE_PLUGIN_ROOT}/scripts/hook-entry.sh\"",
29
+ "command": "set -- guardrail-dispatch.sh guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-draft-pr-gate.sh guardrail-walkthrough-heading.sh; . \"${CLAUDE_PLUGIN_ROOT}/scripts/hook-entry.sh\"",
30
30
  "async": false,
31
31
  "timeout": 1
32
32
  },
33
33
  {
34
34
  "type": "command",
35
35
  "if": "Bash(*glab *)",
36
- "command": "set -- guardrail-dispatch.sh guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-walkthrough-heading.sh; . \"${CLAUDE_PLUGIN_ROOT}/scripts/hook-entry.sh\"",
36
+ "command": "set -- guardrail-dispatch.sh guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-draft-pr-gate.sh guardrail-walkthrough-heading.sh; . \"${CLAUDE_PLUGIN_ROOT}/scripts/hook-entry.sh\"",
37
37
  "async": false,
38
38
  "timeout": 1
39
39
  },
40
40
  {
41
41
  "type": "command",
42
42
  "if": "PowerShell(*gh *)",
43
- "command": "set -- guardrail-dispatch.sh guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-walkthrough-heading.sh; . \"${CLAUDE_PLUGIN_ROOT}/scripts/hook-entry.sh\"",
43
+ "command": "set -- guardrail-dispatch.sh guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-draft-pr-gate.sh guardrail-walkthrough-heading.sh; . \"${CLAUDE_PLUGIN_ROOT}/scripts/hook-entry.sh\"",
44
44
  "async": false,
45
45
  "timeout": 1
46
46
  },
47
47
  {
48
48
  "type": "command",
49
49
  "if": "PowerShell(*glab *)",
50
- "command": "set -- guardrail-dispatch.sh guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-walkthrough-heading.sh; . \"${CLAUDE_PLUGIN_ROOT}/scripts/hook-entry.sh\"",
50
+ "command": "set -- guardrail-dispatch.sh guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-draft-pr-gate.sh guardrail-walkthrough-heading.sh; . \"${CLAUDE_PLUGIN_ROOT}/scripts/hook-entry.sh\"",
51
51
  "async": false,
52
52
  "timeout": 1
53
53
  }
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env bash
2
+ set -uo pipefail
3
+
4
+ # Draft-PR gate (PreToolUse, Bash). Denies opening a PR/MR as a draft — `gh pr create
5
+ # --draft`, `glab mr create --draft|--wip`, a GitLab `Draft:` title — and turning an open
6
+ # one back into a draft (`gh pr ready --undo`, `convertPullRequestToDraft`). Muggle opens
7
+ # every PR ready for review.
8
+ #
9
+ # Must stay synchronous — only a sync PreToolUse hook can deny — and it fires before every
10
+ # Bash call, so a keyword pre-filter on the command keeps Node off the hot path. The filter
11
+ # is deliberately looser than the gate (any `draft`/`wip`/`--undo`/` -d` next to gh or glab);
12
+ # guardrails.mjs makes the exact call. Degrades to {} so it never blocks an unrelated command.
13
+
14
+ guardrail_script_dir="${BASH_SOURCE[0]%/*}"
15
+ [[ $guardrail_script_dir == "${BASH_SOURCE[0]}" ]] && guardrail_script_dir=.
16
+ . "$guardrail_script_dir/guardrail-lib.sh"
17
+
18
+ GUARDRAIL_SUBCOMMAND="draft-pr-gate"
19
+
20
+ guardrail_wants() {
21
+ guardrail_fields_match command '(gh|glab)[[:space:]].*(draft|wip|--undo|[[:space:]]-d([[:space:]]|$))'
22
+ }
23
+
24
+ if guardrail_is_hook_script; then
25
+ guardrail_run_standalone "$GUARDRAIL_SUBCOMMAND"
26
+ fi
@@ -138,6 +138,15 @@ var GUARDRAIL_SUBCOMMAND_ASSIGNMENT = /^GUARDRAIL_SUBCOMMAND="([\w-]+)"/m;
138
138
  var HOOK_COMMAND_SCRIPTS = /^set -- ([^;]+);/;
139
139
  var GUARDRAIL_DISPATCH_SCRIPT = "guardrail-dispatch.sh";
140
140
  var MUGGLE_DO_STAGES_AFTER_BUILD = "impact \u2192 unit tests \u2192 PR \u2192 E2E \u2192 watcher";
141
+ var GITHUB_PR_CREATE_CMD = /\bgh\s+pr\s+create\b/;
142
+ var GITHUB_PR_READY_CMD = /\bgh\s+pr\s+ready\b/;
143
+ var GITLAB_MR_CREATE_OR_UPDATE_CMD = /\bglab\s+mr\s+(?:create|update)\b/;
144
+ var DRAFT_FLAG = /(?:^|\s)(?:--draft(?:=true)?|-d)(?=\s|$)/i;
145
+ var GITLAB_WIP_FLAG = /(?:^|\s)--wip(?=\s|$)/i;
146
+ var UNDO_FLAG = /(?:^|\s)--undo(?=\s|$)/;
147
+ var GITLAB_DRAFT_TITLE = /\bglab\s+mr\s+(?:create|update)\b[^;&|\n]*?(?:--title|-t)(?:=|\s+)["']?\s*(?:draft\s*:|\[draft\]|\(draft\)|wip\s*:)/i;
148
+ var GITHUB_CONVERT_TO_DRAFT_MUTATION = /\bconvertPullRequestToDraft\b/;
149
+ var GITHUB_REST_DRAFT_FIELD = /\bgh\s+api\b[^;&|\n]*\bpulls\b[^;&|\n]*\bdraft=true\b/i;
141
150
 
142
151
  // src/guardrails/store/fileLock.ts
143
152
  function isProcessAlive(pid) {
@@ -2908,6 +2917,31 @@ function evaluateReviewThreadResolve(input2) {
2908
2917
  return { deny: true, reason: RESOLVE_DENIAL };
2909
2918
  }
2910
2919
 
2920
+ // src/guardrails/draftPr.ts
2921
+ var QUOTED_STRING = /"(?:[^"\\]|\\.)*"|'[^']*'/g;
2922
+ var COMMAND_SEPARATOR = /&&|\|\||[;|\n]/;
2923
+ function unquotedSegments(command) {
2924
+ return command.replace(QUOTED_STRING, '""').split(COMMAND_SEPARATOR);
2925
+ }
2926
+ function detectDraftPrCommand(command) {
2927
+ for (const segment of unquotedSegments(command)) {
2928
+ if (GITHUB_PR_CREATE_CMD.test(segment) && DRAFT_FLAG.test(segment)) return true;
2929
+ if (GITHUB_PR_READY_CMD.test(segment) && UNDO_FLAG.test(segment)) return true;
2930
+ if (GITLAB_MR_CREATE_OR_UPDATE_CMD.test(segment) && (DRAFT_FLAG.test(segment) || GITLAB_WIP_FLAG.test(segment))) {
2931
+ return true;
2932
+ }
2933
+ }
2934
+ if (GITLAB_DRAFT_TITLE.test(command)) return true;
2935
+ if (PROVIDER_API_INVOCATION.test(command) && GITHUB_CONVERT_TO_DRAFT_MUTATION.test(command)) return true;
2936
+ return GITHUB_REST_DRAFT_FIELD.test(command);
2937
+ }
2938
+ var DRAFT_DENIAL = "Blocked: Muggle never opens draft PRs/MRs. Every PR goes up ready for review, so reviewers and CI start on it as soon as it opens. Re-run the command without `--draft`/`-d`/`--wip` (and without a `Draft:`/`WIP:` title prefix on GitLab). If the change is not ready for review, don't open the PR yet; if a draft already exists, mark it ready with `gh pr ready <n>` (GitLab: `glab mr update <n> --ready`).";
2939
+ function evaluateDraftPr(input2) {
2940
+ if (!isShellToolCall(input2)) return { deny: false };
2941
+ if (!detectDraftPrCommand(input2.tool_input?.command ?? "")) return { deny: false };
2942
+ return { deny: true, reason: DRAFT_DENIAL };
2943
+ }
2944
+
2911
2945
  // src/guardrails/emit.ts
2912
2946
  function envelope(eventName, context, host2) {
2913
2947
  if (!context) return "{}";
@@ -3542,6 +3576,11 @@ function resolveGate() {
3542
3576
  if (!resolveVerdict.deny || !resolveVerdict.reason) return "{}";
3543
3577
  return denyTool(resolveVerdict.reason, host);
3544
3578
  }
3579
+ function draftPrGate() {
3580
+ const draftVerdict = evaluateDraftPr(input);
3581
+ if (!draftVerdict.deny || !draftVerdict.reason) return "{}";
3582
+ return denyTool(draftVerdict.reason, host);
3583
+ }
3545
3584
  function buildRouter() {
3546
3585
  const prompt = input.prompt ?? "";
3547
3586
  const isMuggleDoInvoked = isMuggleDoForwardInvocation(prompt);
@@ -3600,6 +3639,7 @@ var handlers = {
3600
3639
  "report-gate": reportGate,
3601
3640
  "walkthrough-heading-gate": walkthroughHeadingGate,
3602
3641
  "resolve-gate": resolveGate,
3642
+ "draft-pr-gate": draftPrGate,
3603
3643
  "build-router": buildRouter,
3604
3644
  "skill-stages": skillStages,
3605
3645
  "record-stage-read": recordStageRead,
@@ -9,6 +9,8 @@ glab mr create -R <group>/<project> \
9
9
  --title "<title>" --description "$(cat <signed-file>)"
10
10
  ```
11
11
 
12
+ Never open it as a draft — no `--draft`/`--wip` and no `Draft:`/`WIP:`/`[Draft]`/`(Draft)` title prefix. Muggle opens every MR ready for review, and a PreToolUse gate denies the draft forms.
13
+
12
14
  Sign with `--mode editable` per [`../post-signature.md`](../post-signature.md) — the description this opens the MR with is the same body `mr-edit.md` refreshes later, so it carries the dedup marker from the start.
13
15
 
14
16
  `glab` prints the created MR's URL on success — capture stdout and store the URL for handoff (the watcher seeds from it, the user gets the link).
@@ -58,6 +58,8 @@ Per repo:
58
58
  - `github` → `gh pr create --title "<Step 3 title>" --body-file <signed-file> --head <branch>`, passing Step 3's title, prefix included, and the file signed in Step 4. Capture the PR URL and number.
59
59
  - `gitlab` → open the change via [`../../_shared/vcs/gitlab/mr-create.md`](../../_shared/vcs/gitlab/mr-create.md): `glab mr create --source-branch <branch> --target-branch <base> --title "<Step 3 title>" --description "..."`. Capture the MR URL and iid.
60
60
 
61
+ Never open it as a draft: no `--draft`/`-d` on `gh`, no `--draft`/`--wip` or `Draft:`/`WIP:` title prefix on `glab`, and never convert it to one afterwards. The PR goes up ready for review — that is what lets reviewers and CI start while E2E runs. A PreToolUse gate denies every draft route.
62
+
61
63
  A create that fails ends the cycle for that repo: report it under **Errors** and run no E2E for it, since the run would have no PR to settle.
62
64
 
63
65
  ## Stage 7 — report on the PR
@@ -100,7 +102,7 @@ If `prs.json` is empty, **do not arm** — record the reason in `result.md` and
100
102
 
101
103
  ## Invariants
102
104
 
103
- - Branch synced with its base before the push, never after; PR opened per non-skipped repo before Stage 6 starts; the tested head is the PR's head before its walkthrough settles; designated walkthrough comment settled via Mode A, or its skip reason stated; `prs.json`+`last_seen.json` seeded (no `cycle.json`, no `requirements.md`); Stage 7.5 cleared before arming; arming per `arm-watcher.md` is the last action.
105
+ - Branch synced with its base before the push, never after; PR opened per non-skipped repo before Stage 6 starts, ready for review — never a draft; the tested head is the PR's head before its walkthrough settles; designated walkthrough comment settled via Mode A, or its skip reason stated; `prs.json`+`last_seen.json` seeded (no `cycle.json`, no `requirements.md`); Stage 7.5 cleared before arming; arming per `arm-watcher.md` is the last action.
104
106
 
105
107
  ## Output
106
108