@muggleai/works 4.15.1 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-YKR2TQ24.js → chunk-KDRSEHK5.js} +2 -1
- package/dist/{chunk-5G7WI7IY.js → chunk-XO5BQZM3.js} +2 -2
- package/dist/cli.js +2 -2
- package/dist/index.js +2 -2
- package/dist/plugin/.claude-plugin/plugin.json +1 -1
- package/dist/plugin/.cursor-plugin/plugin.json +1 -1
- package/dist/plugin/hooks/README.md +26 -0
- package/dist/plugin/hooks/hooks.json +39 -0
- package/dist/plugin/scripts/ensure-electron-app.sh +1 -1
- package/dist/plugin/scripts/guardrail-build-router.sh +9 -0
- package/dist/plugin/scripts/guardrail-e2e-gate.sh +8 -0
- package/dist/plugin/scripts/guardrail-pr-opened.sh +10 -0
- package/dist/plugin/scripts/guardrail-record-tests.sh +9 -0
- package/dist/plugin/scripts/guardrails.mjs +143 -0
- package/dist/plugin/skills/_shared/github-cli-recipes/pr-metadata.md +2 -1
- package/dist/plugin/skills/_shared/pr-followup-helpers/echo-skip.md +16 -0
- package/dist/plugin/skills/_shared/pr-followup-helpers.md +1 -0
- package/dist/plugin/skills/do/address-reviews.md +1 -1
- package/dist/plugin/skills/do/build.md +4 -0
- package/dist/plugin/skills/do/cleanup.md +6 -5
- package/dist/plugin/skills/do/fix-ci.md +1 -1
- package/dist/plugin/skills/do/input-routing.md +7 -6
- package/dist/plugin/skills/do/next-step.md +18 -0
- package/dist/plugin/skills/do/open-prs/forward.md +2 -0
- package/dist/plugin/skills/do/resolve-conflicts.md +62 -0
- package/dist/plugin/skills/muggle-do/SKILL.md +2 -1
- package/dist/plugin/skills/muggle-pr-followup/SKILL.md +1 -1
- package/dist/plugin/skills/muggle-pr-followup/contract.md +40 -16
- package/dist/plugin/skills/muggle-pr-followup/state-schemas.md +5 -1
- package/dist/plugin/skills/muggle-preferences/preference-gates/autoRouteBuildToMuggleDo.md +13 -0
- package/dist/plugin/skills/muggle-test/SKILL.md +7 -5
- package/dist/plugin/skills/muggle-test-feature-local/SKILL.md +7 -5
- package/dist/release-manifest.json +4 -4
- package/dist/{src-ECRJW2LY.js → src-2O5UH4FA.js} +1 -1
- package/package.json +6 -6
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/.cursor-plugin/plugin.json +1 -1
- package/plugin/hooks/README.md +26 -0
- package/plugin/hooks/hooks.json +39 -0
- package/plugin/scripts/ensure-electron-app.sh +1 -1
- package/plugin/scripts/guardrail-build-router.sh +9 -0
- package/plugin/scripts/guardrail-e2e-gate.sh +8 -0
- package/plugin/scripts/guardrail-pr-opened.sh +10 -0
- package/plugin/scripts/guardrail-record-tests.sh +9 -0
- package/plugin/scripts/guardrails.mjs +143 -0
- package/plugin/skills/_shared/github-cli-recipes/pr-metadata.md +2 -1
- package/plugin/skills/_shared/pr-followup-helpers/echo-skip.md +16 -0
- package/plugin/skills/_shared/pr-followup-helpers.md +1 -0
- package/plugin/skills/do/address-reviews.md +1 -1
- package/plugin/skills/do/build.md +4 -0
- package/plugin/skills/do/cleanup.md +6 -5
- package/plugin/skills/do/fix-ci.md +1 -1
- package/plugin/skills/do/input-routing.md +7 -6
- package/plugin/skills/do/next-step.md +18 -0
- package/plugin/skills/do/open-prs/forward.md +2 -0
- package/plugin/skills/do/resolve-conflicts.md +62 -0
- package/plugin/skills/muggle-do/SKILL.md +2 -1
- package/plugin/skills/muggle-pr-followup/SKILL.md +1 -1
- package/plugin/skills/muggle-pr-followup/contract.md +40 -16
- package/plugin/skills/muggle-pr-followup/state-schemas.md +5 -1
- package/plugin/skills/muggle-preferences/preference-gates/autoRouteBuildToMuggleDo.md +13 -0
- package/plugin/skills/muggle-test/SKILL.md +7 -5
- package/plugin/skills/muggle-test-feature-local/SKILL.md +7 -5
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
# Post-Merge Cleanup Stage
|
|
2
2
|
|
|
3
|
-
Invoked by `/muggle-do` when the watcher forwards a PR's terminal
|
|
3
|
+
Invoked by `/muggle-do` when the watcher forwards a PR's terminal state. On `merged` it resolves the session's workspace and **delegates** teardown to the shared procedure (it does not restate the teardown steps); on `closed` (unmerged) it skips teardown. Either way it ends by suggesting the next step. Never runs while the PR is open.
|
|
4
4
|
|
|
5
5
|
## Input
|
|
6
6
|
|
|
7
|
-
`$ARGUMENTS` carries
|
|
7
|
+
`$ARGUMENTS` carries `slug=<slug>` and `state=<merged|closed>` (default `merged`). No PR URL, no review ids.
|
|
8
8
|
|
|
9
9
|
## Procedure
|
|
10
10
|
|
|
11
11
|
1. Read `~/.muggle-ai/muggle-do/sessions/<slug>/`: `prs.json` (PR `repo`, `number`, observed `state`) and `state.md` (`worktreePath` if a worktree was used, and the target branch `headRefName`).
|
|
12
|
-
2.
|
|
13
|
-
3.
|
|
14
|
-
4. Append a cleanup line to the session's `followup.log
|
|
12
|
+
2. If `prs.json` shows the PR still open, do nothing and exit — this stage is terminal-only.
|
|
13
|
+
3. **Teardown (`merged` only).** When the PR is `merged`, run [`../_shared/post-merge-cleanup.md`](../_shared/post-merge-cleanup.md) with `{worktreePath}` and `{branch}`. That file owns the teardown sequence **and its safety rules** — including skipping worktree-remove and local branch deletion when no worktree was used. This stage adds no teardown logic of its own. On `closed`, skip teardown — the branch and any worktree stay intact.
|
|
14
|
+
4. Append a cleanup line to the session's `followup.log`, recording whether teardown ran.
|
|
15
|
+
5. Suggest the next step per [`next-step.md`](next-step.md), passing whether teardown ran. This is the stage's last action.
|
|
@@ -40,7 +40,7 @@ Commit per the `fix(ci): <check> — <what>` convention ([`../_shared/pr-followu
|
|
|
40
40
|
### Step 5 — Update state + respawn
|
|
41
41
|
|
|
42
42
|
- Increment `last_seen.ci_fix_attempts[red_sha]`.
|
|
43
|
-
- Respawn the watcher: `/loop 1m /muggle:muggle-pr-followup <slug> <n>`. CI on the new SHA is the verify loop — a still-red SHA returns as a fresh dispatch, bounded by the per-SHA fix budget (Step 6).
|
|
43
|
+
- Respawn the watcher: `/loop 1m /muggle:muggle-pr-followup <slug> <n>`. The watcher cancelled its own cron when it dispatched this fix-ci cycle ([`../muggle-pr-followup/contract.md`](../muggle-pr-followup/contract.md) Step 5), so this restart is the single live watcher. CI on the new SHA is the verify loop — a still-red SHA returns as a fresh dispatch, bounded by the per-SHA fix budget (Step 6).
|
|
44
44
|
|
|
45
45
|
### Step 6 — Escalate (budget spent or out of scope)
|
|
46
46
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# Input routing
|
|
2
2
|
|
|
3
|
-
How `/muggle-do` resolves `$ARGUMENTS` to a mode. Modes 1–
|
|
3
|
+
How `/muggle-do` resolves `$ARGUMENTS` to a mode. Modes 1–4 are programmatic — dispatched by the watcher — so never ask on those. Inspect in order:
|
|
4
4
|
|
|
5
5
|
1. **Address-reviews** — a `github.com/.../pull/<n>` URL **and** one or more review ids (integers ≥ 100000000) → [`address-reviews.md`](address-reviews.md).
|
|
6
6
|
2. **Fix-CI** — a `github.com/.../pull/<n>` URL **and** a `fix ci` / `fix-ci` directive with failing check names (no review ids) → [`fix-ci.md`](fix-ci.md).
|
|
7
|
-
3. **
|
|
8
|
-
4. **
|
|
9
|
-
5. **
|
|
10
|
-
6. **
|
|
7
|
+
3. **Resolve-conflicts** — a `github.com/.../pull/<n>` URL **and** a `resolve conflicts` / `resolve-conflicts` directive (no review ids, no check names) → [`resolve-conflicts.md`](resolve-conflicts.md).
|
|
8
|
+
4. **Post-merge cleanup** — a `cleanup` token and `slug=<slug>` (no PR URL, no review ids), optionally `state=<merged|closed>` (default `merged`) → [`cleanup.md`](cleanup.md).
|
|
9
|
+
5. **Empty / `help` / `menu` / `?`** → menu + session selector.
|
|
10
|
+
6. **Task automation** (perform an action on a website) → `muggle:muggle-browser-task`.
|
|
11
|
+
7. **Otherwise** → forward pipeline at Stage 1.
|
|
11
12
|
|
|
12
|
-
When in doubt between #
|
|
13
|
+
When in doubt between #6 and #7, ask one question.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Next-Step Suggestion
|
|
2
|
+
|
|
3
|
+
Closing step of a terminal `/muggle-do` turn (post-merge or post-close). Advances silently when the session still has a plan, stops and asks when it doesn't.
|
|
4
|
+
|
|
5
|
+
## Input
|
|
6
|
+
|
|
7
|
+
- `slug` — the session.
|
|
8
|
+
- `teardownRan` — whether [`cleanup.md`](cleanup.md) already ran teardown (true on `merged` + `autoCleanup: always`; false on `closed` or a skipped gate).
|
|
9
|
+
|
|
10
|
+
## Procedure
|
|
11
|
+
|
|
12
|
+
1. Read the session plan — the current session's TodoWrite list.
|
|
13
|
+
2. **Pending items remain** → do not prompt. Append `next-step: plan has <N> pending — advancing` to `followup.log` and continue to the next pending item. The user set a course; honor it.
|
|
14
|
+
3. **No pending items** → stop and ask for directions with one `AskUserQuestion` selector:
|
|
15
|
+
- **Clean up now** — offer only when `teardownRan` is false (a `closed` PR, or `merged` with `autoCleanup` not `always`). Runs the shared teardown [`../_shared/post-merge-cleanup.md`](../_shared/post-merge-cleanup.md) for this slug, under its own safety rules.
|
|
16
|
+
- **Move on / next task** — start a fresh `/muggle-do` forward run, or pick another open session.
|
|
17
|
+
- **Done — stop here** — exit with no further action.
|
|
18
|
+
4. Append the chosen outcome to `followup.log`.
|
|
@@ -78,3 +78,5 @@ Append one short reminder tied to the gate value:
|
|
|
78
78
|
- `always` → `Once merged, I'll run the cleanup sequence automatically.`
|
|
79
79
|
- `never` → omit.
|
|
80
80
|
- `ask` / absent → `Once merged, I'll check with you about cleanup.`
|
|
81
|
+
|
|
82
|
+
Regardless of the gate, also append: `Once it's merged or closed, I'll move to the next plan item — or ask where to go next if there's no plan.`
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Resolve-Conflicts (watcher-dispatched)
|
|
2
|
+
|
|
3
|
+
Rebase a PR whose branch conflicts with its base, resolve the conflicts behind a verify-or-rollback gate, and force-push — so a mergeable-blocked PR doesn't sit idle forever. A dumb-pipe dispatch like fix-ci: the watcher detects `mergeable == CONFLICTING` and hands off; the executor owns the rebase + resolution, never the decision to dispatch.
|
|
4
|
+
|
|
5
|
+
## Turn preamble
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
**/muggle-do resolve-conflicts** — rebasing <owner>/<repo>#<n> onto <base> to clear merge conflicts.
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Input
|
|
12
|
+
|
|
13
|
+
`$ARGUMENTS` carries a `github.com/.../pull/<n>` URL, `slug=<slug>`, and a `resolve conflicts` directive (no review ids, no failing check names). Parse all three.
|
|
14
|
+
|
|
15
|
+
## Inputs from disk
|
|
16
|
+
|
|
17
|
+
From `~/.muggle-ai/muggle-do/sessions/<slug>/`: `prs.json` (PR + branch + `head_sha`), `last_seen.json` (`conflict_resolve_attempts`, `conflict_escalated_shas`, `pushed_shas`), `state.md` (worktree path, validation strategy, base branch).
|
|
18
|
+
|
|
19
|
+
## Procedure
|
|
20
|
+
|
|
21
|
+
### Step 1 — Re-attach
|
|
22
|
+
|
|
23
|
+
Materialize the PR branch in its worktree per [`../_shared/pr-branch-worktree.md`](../_shared/pr-branch-worktree.md) (or use `state.md`'s `worktreePath`). Capture `conflict_sha = prs.json[0].head_sha` and the base branch (`baseRefName` from [`../_shared/github-cli-recipes/pr-metadata.md`](../_shared/github-cli-recipes/pr-metadata.md)).
|
|
24
|
+
|
|
25
|
+
### Step 2 — Rebase onto base + resolve
|
|
26
|
+
|
|
27
|
+
Run [`../_shared/rebase-before-e2e.md`](../_shared/rebase-before-e2e.md) against the base branch (it fires because a conflicting PR is behind). Conflict handling follows [`autoResolveConflicts`](../muggle-preferences/preference-gates/autoResolveConflicts.md):
|
|
28
|
+
|
|
29
|
+
- default `never` → abort and escalate per Step 5 (`kind: "rebase-conflict"`). The watcher keeps polling; the user resolves on GitHub, or opts into `autoResolveConflicts=always`.
|
|
30
|
+
- `always` → resolve behind the verify-or-rollback gate in [`../_shared/resolve-rebase-conflicts.md`](../_shared/resolve-rebase-conflicts.md).
|
|
31
|
+
|
|
32
|
+
### Step 3 — Verify the resolution
|
|
33
|
+
|
|
34
|
+
Build (typecheck + lint on the changed surface) + unit suite must pass. Run E2E per [`e2e-acceptance.md`](e2e-acceptance.md) when app logic changed and the session carries validation context. A resolution that does not verify is rolled back → escalate per Step 5. **Never push an unverified merge.**
|
|
35
|
+
|
|
36
|
+
### Step 4 — Force-push + respawn
|
|
37
|
+
|
|
38
|
+
Push with `--force-with-lease` (the rebase rewrote history). Append the new SHA to `last_seen.pushed_shas`; increment `last_seen.conflict_resolve_attempts[conflict_sha]`. Respawn the watcher as the last action:
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
/loop 1m /muggle:muggle-pr-followup <slug> <n>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The watcher cancelled its own cron when it dispatched this cycle ([`../muggle-pr-followup/contract.md`](../muggle-pr-followup/contract.md) Step 5b), so this restart is the single live watcher. Its next tick re-checks mergeability on the new head — the rebase is its own verify loop, bounded by the per-SHA attempt budget.
|
|
45
|
+
|
|
46
|
+
### Step 5 — Escalate (can't resolve / budget spent)
|
|
47
|
+
|
|
48
|
+
When `autoResolveConflicts=never`, the resolution failed verification, or `conflict_resolve_attempts[conflict_sha]` has reached 2:
|
|
49
|
+
|
|
50
|
+
1. Add `conflict_sha` to `last_seen.conflict_escalated_shas` so the watcher does not re-dispatch this SHA.
|
|
51
|
+
2. Emit one terminal escalation naming the PR and the conflicting files.
|
|
52
|
+
3. Respawn the watcher (last action) — it keeps polling for the user's manual resolution or any new reviews.
|
|
53
|
+
|
|
54
|
+
### Step 6 — Telemetry
|
|
55
|
+
|
|
56
|
+
Emit one `muggle-do:cycle` event ([`../_shared/telemetry-events/muggle-do-cycle.md`](../_shared/telemetry-events/muggle-do-cycle.md)) with `outcome: "conflicts-resolved"` (a verified rebase pushed) or `"conflicts-escalated"`.
|
|
57
|
+
|
|
58
|
+
## Guardrails
|
|
59
|
+
|
|
60
|
+
- Max 2 resolve attempts per SHA; then escalate rather than churn.
|
|
61
|
+
- Never push an unverified merge — verify-or-rollback always.
|
|
62
|
+
- The default `autoResolveConflicts=never` escalates to the user rather than guessing a merge. Auto-resolution is strictly opt-in.
|
|
@@ -55,7 +55,7 @@ When invoked with the directive (PR URL + slug + review ids), routes to [`../do/
|
|
|
55
55
|
|
|
56
56
|
## Input routing
|
|
57
57
|
|
|
58
|
-
`/muggle-do` serves one interactive mode (the forward pipeline, from a fresh task) and
|
|
58
|
+
`/muggle-do` serves one interactive mode (the forward pipeline, from a fresh task) and four programmatic modes the watcher dispatches (address-reviews, fix-ci, resolve-conflicts, post-merge cleanup). Resolve `$ARGUMENTS` to a mode per [`../do/input-routing.md`](../do/input-routing.md) before doing anything else.
|
|
59
59
|
|
|
60
60
|
## Preferences
|
|
61
61
|
|
|
@@ -63,6 +63,7 @@ When invoked with the directive (PR URL + slug + review ids), routes to [`../do/
|
|
|
63
63
|
| :--------- | :--- |
|
|
64
64
|
| `autoE2ETest` | Stage 6 — run E2E every cycle (default `always`), or fold into pre-flight |
|
|
65
65
|
| `autoResolveConflicts` | On rebase conflict — resolve autonomously behind a verify-or-rollback gate (opt-in), or abort + escalate (default `never`) |
|
|
66
|
+
| `autoRouteBuildToMuggleDo` | Front-door guardrail — route build/implement/fix requests through this pipeline (build delegated to superpowers); fired by the UserPromptSubmit guardrail, default `ask` |
|
|
66
67
|
|
|
67
68
|
`autoUseWorktree`, `autoRebase`, `autoResolveConflicts`, `autoCreatePR`, `autoCleanup` fire from per-stage files.
|
|
68
69
|
|
|
@@ -7,7 +7,7 @@ description: Use this skill when the user wants a pull request's incoming review
|
|
|
7
7
|
|
|
8
8
|
> Telemetry first step: see [`../_shared/telemetry-emit.md`](../_shared/telemetry-emit.md). Use `skillName: "muggle-pr-followup"`.
|
|
9
9
|
|
|
10
|
-
A watcher that babysits one open PR's review thread and
|
|
10
|
+
A watcher that babysits one open PR's review thread, CI, and merge-conflict state. Polls for new submitted reviews, check-run state, and mergeability; when review feedback lands, CI goes red, or the branch conflicts with its base, hands the work to `/muggle-do` and exits. On merge or close, it hands the terminal wrap-up to `/muggle-do` the same way — teardown when merged, then a next-step suggestion. `/muggle-do` is the executor — it classifies the reviews, fixes the failing checks, or rebases-and-resolves the conflict, pushes, replies per comment, and respawns the watcher.
|
|
11
11
|
|
|
12
12
|
**The watcher is a dumb pipe.** It does not classify reviews, iterate cycles, post replies, or escalate. All of that lives in `/muggle-do`. See [stage-8 design](../../../../muggle-ai-brain/architecture/2026-05-08-muggle-do-pr-comment-loop-design.md) for the rationale.
|
|
13
13
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Watcher Per-Tick Contract
|
|
2
2
|
|
|
3
|
-
The procedure for the **tick mode** of `muggle-pr-followup` — one polling iteration scoped to one PR. The watcher is a dumb pipe: it polls for new submitted reviews
|
|
3
|
+
The procedure for the **tick mode** of `muggle-pr-followup` — one polling iteration scoped to one PR. The watcher is a dumb pipe: it polls for new submitted reviews, CI checks, and merge-conflict state, dispatches `/muggle-do` if there's review feedback, fixable red CI, or an unmergeable branch, and exits. It does not classify, fix, resolve, amend requirements, post replies, run cycles, or escalate.
|
|
4
4
|
|
|
5
5
|
Routing into this mode is documented in [`SKILL.md`](SKILL.md#routing). The architectural rationale lives in the brain doc `architecture/2026-05-08-muggle-do-pr-comment-loop-design.md`.
|
|
6
6
|
|
|
@@ -25,35 +25,43 @@ If either file is missing or the PR is not in `prs.json`, the tick is a no-op. L
|
|
|
25
25
|
|
|
26
26
|
## Procedure
|
|
27
27
|
|
|
28
|
+
### Step 0 — Stale-fire guard
|
|
29
|
+
|
|
30
|
+
If `prs.json[0].state` on disk is already `merged` or `closed`, this slot was finalized by a prior tick and this is a stale (queued) fire — per-minute cron fires enqueued while the session was busy still drain after the cron is cancelled. Defensively cancel any lingering cron for this slug (`CronList` → the job whose command ends with `/muggle:muggle-pr-followup <slug> <n>` → `CronDelete`; no-op if none), append a `stale-tick` line to `followup.log`, and exit. Do not re-fetch or re-finalize.
|
|
31
|
+
|
|
28
32
|
### Step 1 — Refresh PR state
|
|
29
33
|
|
|
30
|
-
Per [`../_shared/github-cli-recipes/pr-metadata.md`](../_shared/github-cli-recipes/pr-metadata.md). Update `prs.json[0].head_sha` and `prs.json[0].state` from the response.
|
|
34
|
+
Per [`../_shared/github-cli-recipes/pr-metadata.md`](../_shared/github-cli-recipes/pr-metadata.md). Update `prs.json[0].head_sha` and `prs.json[0].state` from the response; keep `mergeable` / `mergeStateStatus` from the same call for Step 5.
|
|
31
35
|
|
|
32
36
|
### Step 2 — Termination check
|
|
33
37
|
|
|
34
38
|
If `state` is `MERGED` or `CLOSED`:
|
|
35
39
|
|
|
36
40
|
1. Finalize the slot per [`finalize.md`](finalize.md) — mark terminal, write `result.md`, log + telemetry, unschedule this watcher's cron.
|
|
37
|
-
2.
|
|
41
|
+
2. Hand off the terminal wrap-up as the last action of the turn — for both `MERGED` and `CLOSED`:
|
|
38
42
|
|
|
39
43
|
```
|
|
40
|
-
/muggle-do post-merge cleanup slug=<slug>
|
|
44
|
+
/muggle-do post-merge cleanup slug=<slug> state=<merged|closed>
|
|
41
45
|
```
|
|
42
46
|
|
|
43
|
-
`/muggle-do` owns the worktree/branch knowledge
|
|
47
|
+
`/muggle-do` owns the worktree/branch knowledge: it runs teardown only on `merged` (honoring the `autoCleanup` gate — `closed` is unmerged, so the branch and any worktree stay intact), then suggests the next step. This is a runtime dispatch, not a doc dependency on `/muggle-do` — see the one-way rule in [`../CLAUDE.md`](../CLAUDE.md).
|
|
44
48
|
3. Exit. The watcher has unscheduled itself; no future ticks fire for this PR.
|
|
45
49
|
|
|
46
50
|
|
|
47
51
|
### Step 3 — Fetch new submitted reviews
|
|
48
52
|
|
|
49
|
-
Per [`../_shared/github-cli-recipes/submitted-reviews.md`](../_shared/github-cli-recipes/submitted-reviews.md).
|
|
53
|
+
Per [`../_shared/github-cli-recipes/submitted-reviews.md`](../_shared/github-cli-recipes/submitted-reviews.md). Exclude two kinds of review id:
|
|
54
|
+
|
|
55
|
+
- ids in `last_seen.escalated_review_ids` — already escalated; the watcher must not re-dispatch them.
|
|
56
|
+
- **echo reviews** per [`../_shared/pr-followup-helpers/echo-skip.md`](../_shared/pr-followup-helpers/echo-skip.md) — a review whose every comment carries the loop marker is the loop's own reply, surfaced by GitHub as a new review. Advance `last_seen.reviewId` past it and skip; never dispatch, or the watcher replies to itself forever.
|
|
50
57
|
|
|
51
58
|
### Step 4 — If one or more new reviews → dispatch (reviews preempt CI)
|
|
52
59
|
|
|
53
60
|
The watcher does **not** classify. Classification, batching, replying, escalation, and cycle execution all live in `/muggle-do`. The watcher's job is to hand over the list of new review ids and exit.
|
|
54
61
|
|
|
55
62
|
1. Reset `last_seen.idle_tick_count` to 0.
|
|
56
|
-
2.
|
|
63
|
+
2. **Stop this watcher (single-thread).** Cancel its cron so no tick fires while the dev cycle runs: `CronList`, find the job whose command ends with `/muggle:muggle-pr-followup <slug> <n>` (exact two-arg match), `CronDelete` it. `/muggle-do` respawns the watcher when the cycle finishes — exactly one cron ever, and no tick overlaps a running cycle.
|
|
64
|
+
3. Dispatch `/muggle-do` with an *address-reviews* directive carrying:
|
|
57
65
|
- PR URL (from `prs.json[0].url`)
|
|
58
66
|
- Session slug (from the invocation arguments)
|
|
59
67
|
- Every new review id from Step 3, as a space-separated list
|
|
@@ -62,11 +70,26 @@ The watcher does **not** classify. Classification, batching, replying, escalatio
|
|
|
62
70
|
```
|
|
63
71
|
/muggle-do address reviews <id1> <id2> ... on <pr-url> slug=<slug>
|
|
64
72
|
```
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
73
|
+
4. Append a dispatching line to `followup.log` per [`output-templates/watcher-log.md`](output-templates/watcher-log.md).
|
|
74
|
+
5. Emit a `tick` event with `reviews_seen: <count>`, `dispatched_review_ids: [<id>, ...]`.
|
|
75
|
+
6. Exit. **Reviews preempt CI** — when reviews land, this tick dispatches address-reviews and never polls CI. The watcher is now stopped; the dev cycle owns the PR and restarts the watcher when it finishes. (The watcher also self-unschedules in Step 2, terminal.)
|
|
76
|
+
|
|
77
|
+
### Step 5 — No new reviews → check mergeability
|
|
78
|
+
|
|
79
|
+
Read `mergeable` / `mergeStateStatus` from the Step 1 metadata. If `mergeable == CONFLICTING` (or `mergeStateStatus == DIRTY`), **and** `conflict_resolve_attempts[head_sha] < 2`, **and** `head_sha` ∉ `conflict_escalated_shas` → dispatch and exit:
|
|
80
|
+
|
|
81
|
+
1. Reset `last_seen.idle_tick_count` to 0.
|
|
82
|
+
2. **Stop this watcher (single-thread):** cancel its cron exactly as in Step 4 — `/muggle-do`'s resolve-conflicts respawns it when the cycle is done.
|
|
83
|
+
3. Dispatch `/muggle-do` with a *resolve-conflicts* directive (PR URL + slug; no review ids, no check names):
|
|
84
|
+
```
|
|
85
|
+
/muggle-do resolve conflicts on <pr-url> slug=<slug>
|
|
86
|
+
```
|
|
87
|
+
4. Append a dispatching line to `followup.log`; emit a `tick` event with `conflicting: true`, `dispatched_resolve_conflicts: true`.
|
|
88
|
+
5. Exit. The dev cycle owns the PR; its respawn restarts the watcher, whose next tick re-checks mergeability on the new head — the rebase is its own verify loop, bounded by the per-SHA attempt budget.
|
|
89
|
+
|
|
90
|
+
`mergeable == MERGEABLE` / `UNKNOWN` (GitHub still computing — treat as not-conflicting this tick), or budget spent (`conflict_resolve_attempts[head_sha] >= 2` or `head_sha` ∈ `conflict_escalated_shas`) → fall through to CI.
|
|
68
91
|
|
|
69
|
-
### Step
|
|
92
|
+
### Step 6 — No new reviews, mergeable → poll CI for the head SHA
|
|
70
93
|
|
|
71
94
|
Fetch the check-run rollup for `prs.json[0].head_sha` per [`../_shared/github-cli-recipes/pr-checks.md`](../_shared/github-cli-recipes/pr-checks.md), then:
|
|
72
95
|
|
|
@@ -74,17 +97,18 @@ Fetch the check-run rollup for `prs.json[0].head_sha` per [`../_shared/github-cl
|
|
|
74
97
|
- **All checks green / skipped, or no checks** → idle (green path).
|
|
75
98
|
- **One or more checks red** (`bucket == "fail"`), **and** `ci_fix_attempts[head_sha] < 3`, **and** `head_sha` ∉ `ci_escalated_shas` → dispatch and exit:
|
|
76
99
|
1. Reset `last_seen.idle_tick_count` to 0.
|
|
77
|
-
2.
|
|
100
|
+
2. **Stop this watcher (single-thread):** cancel its cron exactly as in Step 4 — `/muggle-do`'s fix-ci respawns it when the cycle is done.
|
|
101
|
+
3. Dispatch `/muggle-do` with a *fix-ci* directive carrying the PR URL, slug, and the red check names (no review ids):
|
|
78
102
|
```
|
|
79
103
|
/muggle-do fix ci <check-1> <check-2> ... on <pr-url> slug=<slug>
|
|
80
104
|
```
|
|
81
|
-
|
|
82
|
-
|
|
105
|
+
4. Append a dispatching line to `followup.log`; emit a `tick` event with `checks_red: <count>`, `dispatched_ci_fix: true`.
|
|
106
|
+
5. Exit. The dev cycle owns the PR; its respawn restarts the watcher, whose next tick re-checks CI on the new head SHA — CI itself is the verify loop.
|
|
83
107
|
- **One or more red, but `ci_fix_attempts[head_sha] >= 3` or `head_sha` ∈ `ci_escalated_shas`** → idle. The fix budget is spent; `/muggle-do`'s fix-ci stage already recorded the escalation. The watcher does not re-dispatch.
|
|
84
108
|
|
|
85
|
-
### Step
|
|
109
|
+
### Step 7 — Idle
|
|
86
110
|
|
|
87
|
-
Any idle branch (Steps 4–
|
|
111
|
+
Any idle branch (Steps 4–6 that did not dispatch): increment `last_seen.idle_tick_count`, append an idle line to `followup.log` per [`output-templates/watcher-log.md`](output-templates/watcher-log.md), emit a `tick` event with `idle: true`, `reviews_seen: 0`, `dispatched_review_ids: []`, `conflicting: <bool>`, `dispatched_resolve_conflicts: false`, `checks_red: <count or 0>`, `dispatched_ci_fix: false`. Exit. The next tick fires in 1 min via `/loop`.
|
|
88
112
|
|
|
89
113
|
## Output
|
|
90
114
|
|
|
@@ -41,7 +41,9 @@ Keyed by `"<owner>/<repo>#<n>"`. One key per PR in the slot.
|
|
|
41
41
|
"escalated_review_ids": [<int>, ...],
|
|
42
42
|
"pushed_shas": ["<sha>", ...],
|
|
43
43
|
"ci_fix_attempts": { "<sha>": <int> },
|
|
44
|
-
"ci_escalated_shas": ["<sha>", ...]
|
|
44
|
+
"ci_escalated_shas": ["<sha>", ...],
|
|
45
|
+
"conflict_resolve_attempts": { "<sha>": <int> },
|
|
46
|
+
"conflict_escalated_shas": ["<sha>", ...]
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
49
|
```
|
|
@@ -54,6 +56,8 @@ Keyed by `"<owner>/<repo>#<n>"`. One key per PR in the slot.
|
|
|
54
56
|
- `pushed_shas`: every SHA `/muggle-do` has pushed for this PR. Append-only. Used by the resolve-reminder stage to recognize threads addressed by the loop.
|
|
55
57
|
- `ci_fix_attempts`: per-SHA count of fix-ci cycles `/muggle-do` has run. The watcher stops dispatching fix-ci for a SHA once its count reaches 3. Keyed by head SHA.
|
|
56
58
|
- `ci_escalated_shas`: head SHAs whose CI the fix-ci stage gave up on (attempts exhausted or only out-of-scope checks). The watcher excludes these from CI dispatch so a hopeless SHA is never re-fixed.
|
|
59
|
+
- `conflict_resolve_attempts`: per-SHA count of resolve-conflicts cycles `/muggle-do` has run. The watcher stops dispatching resolve-conflicts for a SHA once its count reaches 2. Keyed by head SHA.
|
|
60
|
+
- `conflict_escalated_shas`: head SHAs whose merge conflict resolve-conflicts gave up on (attempts exhausted, or `autoResolveConflicts=never`). The watcher excludes these from conflict dispatch so an unresolvable SHA is never re-attempted.
|
|
57
61
|
|
|
58
62
|
## `state.md`
|
|
59
63
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# `autoRouteBuildToMuggleDo`
|
|
2
|
+
|
|
3
|
+
When the user asks to build, implement, or fix something, controls whether the front-door guardrail routes the work through `/muggle-do` — the orchestrator that runs requirements → build (delegated to superpowers' design→plan→review) → impact → unit tests → E2E → PR → watcher — or lets the request proceed however the model would otherwise handle it. Fires once per session, on the first build-intent prompt (UserPromptSubmit guardrail).
|
|
4
|
+
|
|
5
|
+
**Picker 1** — header `Route to muggle-do?`, question `"This looks like a build request — run it through /muggle-do (E2E + PR + watcher, build delegated to superpowers)?"`
|
|
6
|
+
- `Route it` — `Enter the /muggle-do pipeline.` → `always`
|
|
7
|
+
- `Ask me next time` — `Decide per request.` → `ask`
|
|
8
|
+
- `No — proceed normally` — `Handle it without /muggle-do.` → `never`
|
|
9
|
+
|
|
10
|
+
**Silent action**
|
|
11
|
+
- `always` → `Routing build requests through /muggle-do`
|
|
12
|
+
- `ask` → `Asking about routing to muggle-do`
|
|
13
|
+
- `never` → `Not routing to muggle-do`
|
|
@@ -113,13 +113,15 @@ If no changes detected (clean tree), tell the user and ask what they want to tes
|
|
|
113
113
|
|
|
114
114
|
## Step 3: Authenticate
|
|
115
115
|
|
|
116
|
-
1. Call `muggle-remote-auth-status`
|
|
117
|
-
2.
|
|
118
|
-
- `always` → reuse
|
|
116
|
+
1. Call `muggle-remote-auth-status`. Three states: **valid** (`authenticated: true`), **expired** (`authenticated: false` + `isExpired: true`, `email` still present), **absent** (`authenticated: false`, no `email`).
|
|
117
|
+
2. **Valid OR expired** (any stored identity) → gate `autoLogin` (per `preference-gates/README.md`). An expired token is NOT a reason to silently re-login the same account — surface the switch choice:
|
|
118
|
+
- `always` → reuse if valid; if expired, re-login the **same** account (`muggle-remote-auth-login`, then `muggle-remote-auth-poll`).
|
|
119
119
|
- `never` → `muggle-remote-auth-login` with `forceNewSession: true`, then `muggle-remote-auth-poll`.
|
|
120
120
|
- `ask` → run Picker 1 from `preference-gates/autoLogin.md` via `AskUserQuestion`; map the answer back to one of the actions above.
|
|
121
|
-
3.
|
|
122
|
-
4. If login pending → call `muggle-remote-auth-poll
|
|
121
|
+
3. **Absent** (no stored identity) → `muggle-remote-auth-login` directly, then `muggle-remote-auth-poll`.
|
|
122
|
+
4. If login pending → call `muggle-remote-auth-poll`.
|
|
123
|
+
|
|
124
|
+
**Account-switch caveat (`never` / "Switch account").** The device flow has no `prompt=select_account`; switching relies on `forceNewSession` first clearing the Auth0 session via `/v2/logout?returnTo=<device-activation URL>`. That redirect only works if the activation URL is in the app's Auth0 *Allowed Logout URLs* — otherwise the browser shows an Auth0 error page and the session is silently reused. If that happens, tell the user to complete login in a **fresh incognito window** (no live SSO session) so Auth0 presents an account login.
|
|
123
125
|
|
|
124
126
|
If auth fails repeatedly, suggest: `muggle logout && muggle login` from terminal.
|
|
125
127
|
|
|
@@ -147,14 +147,16 @@ Run the shared loop in [`../_shared/dev-loop/run.md`](../_shared/dev-loop/run.md
|
|
|
147
147
|
|
|
148
148
|
Caller glue: `mode` is the path chosen in §5; `localUrl` from §4; `cwd` = the repo root, or the prepared worktree when one is in use.
|
|
149
149
|
|
|
150
|
-
### 7. Execute (
|
|
150
|
+
### 7. Execute (`showUi` gated by `showElectronBrowser`)
|
|
151
151
|
|
|
152
|
-
|
|
152
|
+
Resolve the `showElectronBrowser` gate **first**, then call `muggle-local-execute-test-generation` or `muggle-local-execute-replay`. **Do not** ask the user to re-approve the Electron launch itself — choosing this skill is the approval. That run-approval suppression does **not** extend to the gate below: when `showElectronBrowser=ask` you must still fire its picker.
|
|
153
153
|
|
|
154
|
-
Gate `showElectronBrowser` (per `preference-gates/README.md`). Reuse choice within a session.
|
|
155
|
-
- `always` → omit `showUi
|
|
154
|
+
Gate `showElectronBrowser` (per `preference-gates/README.md`). Reuse the choice within a session.
|
|
155
|
+
- `always` → omit `showUi` (the browser shows by default).
|
|
156
156
|
- `never` → pass `showUi: false`.
|
|
157
|
-
- `ask` →
|
|
157
|
+
- `ask` → you **must** call `AskUserQuestion` (Picker 1 from `preference-gates/showElectronBrowser.md`) **before** the execute call, then map the answer to the `always`/`never` action above. Do not decide for the user.
|
|
158
|
+
|
|
159
|
+
`showUi` is only ever omitted or `false` — never pass `showUi: true`.
|
|
158
160
|
|
|
159
161
|
### 8. Upload run to cloud (every completed run; open `viewUrl` gated by `openTestResultsAfterRun`)
|
|
160
162
|
|