@muggleai/works 5.36.0-staging.336 → 5.36.0-staging.337
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/dist/{chunk-X3GQII63.js → chunk-HTCBHSL6.js} +130 -38
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/dist/plugin/.claude-plugin/plugin.json +1 -1
- package/dist/plugin/.codex-mcp.json +1 -1
- package/dist/plugin/.codex-plugin/plugin.json +1 -1
- package/dist/plugin/.cursor-plugin/plugin.json +1 -1
- package/dist/plugin/.mcp.json +1 -1
- package/dist/plugin/hooks/README.md +1 -1
- package/dist/plugin/scripts/guardrail-watch-follow-through-gate.sh +22 -7
- package/dist/plugin/scripts/guardrails.mjs +21 -3
- package/dist/plugin/scripts/pr-watch-arm.sh +11 -6
- package/dist/plugin/scripts/pr-watch-loop.sh +3 -2
- package/dist/plugin/scripts/pr-watch-verdict.mjs +1 -0
- package/dist/plugin/skills/do/audit-trail.md +1 -1
- package/dist/plugin/skills/do/e2e-repair.md +1 -1
- package/dist/plugin/skills/do/open-prs/forward.md +17 -15
- package/dist/plugin/skills/do/open-prs.md +1 -1
- package/dist/plugin/skills/muggle-pr-followup/SKILL.md +1 -1
- package/dist/plugin/skills/muggle-pr-followup/arm-watcher.md +2 -2
- package/dist/plugin/skills/muggle-pr-followup/contract.md +6 -0
- package/dist/plugin/skills/muggle-pr-followup/reconcile.md +1 -1
- package/dist/plugin/skills/muggle-pr-followup/state-schemas.md +8 -2
- package/dist/release-manifest.json +4 -4
- package/package.json +1 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/.codex-mcp.json +1 -1
- package/plugin/.codex-plugin/plugin.json +1 -1
- package/plugin/.cursor-plugin/plugin.json +1 -1
- package/plugin/.mcp.json +1 -1
- package/plugin/hooks/README.md +1 -1
- package/plugin/scripts/guardrail-watch-follow-through-gate.sh +22 -7
- package/plugin/scripts/guardrails.mjs +21 -3
- package/plugin/scripts/pr-watch-arm.sh +11 -6
- package/plugin/scripts/pr-watch-loop.sh +3 -2
- package/plugin/scripts/pr-watch-verdict.mjs +1 -0
- package/plugin/skills/do/audit-trail.md +1 -1
- package/plugin/skills/do/e2e-repair.md +1 -1
- package/plugin/skills/do/open-prs/forward.md +17 -15
- package/plugin/skills/do/open-prs.md +1 -1
- package/plugin/skills/muggle-pr-followup/SKILL.md +1 -1
- package/plugin/skills/muggle-pr-followup/arm-watcher.md +2 -2
- package/plugin/skills/muggle-pr-followup/contract.md +6 -0
- package/plugin/skills/muggle-pr-followup/reconcile.md +1 -1
- package/plugin/skills/muggle-pr-followup/state-schemas.md +8 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Open PR — forward mode
|
|
2
2
|
|
|
3
|
-
The forward pipeline's PR stages, which run on either side of Stage 6. **Stage 5.5** opens the change — a PR on GitHub (`gh pr create`) or an MR on GitLab (`glab mr create`), provider resolved in Step 5 — as soon as unit tests pass, before any browser run. **Stage 7** settles that run's result on it,
|
|
3
|
+
The forward pipeline's PR stages, which run on either side of Stage 6. **Stage 5.5** opens the change — a PR on GitHub (`gh pr create`) or an MR on GitLab (`glab mr create`), provider resolved in Step 5 — as soon as unit tests pass, before any browser run, and arms its watch with every cycle held. **Stage 7** settles that run's result on it, and **Stage 8** lifts the hold.
|
|
4
4
|
|
|
5
5
|
The PR goes up first because opening it needs nothing from the run: CI and reviewers start on the diff while E2E runs, and the run's [PR progress](../../_shared/dev-loop/run.md#pr-progress) fills the PR's walkthrough comment case by case. The walkthrough check stays red until Stage 7 settles that comment, so an open PR never passes as tested before its run lands.
|
|
6
6
|
|
|
@@ -62,6 +62,16 @@ Per repo:
|
|
|
62
62
|
|
|
63
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.
|
|
64
64
|
|
|
65
|
+
6. **Seed and arm the watch, held.** Write `~/.muggle-ai/muggle-do/sessions/<slug>/prs.json` per [`../../muggle-pr-followup/state-schemas.md`](../../muggle-pr-followup/state-schemas.md#prsjson), one entry per PR this stage opened:
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
[{ "repo": "owner/repo", "number": 142, "url": "...", "head_sha": "...", "state": "open" }]
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Seed `last_seen.json` per [`../../muggle-pr-followup/state-schemas.md`](../../muggle-pr-followup/state-schemas.md#last_seenjson): the empty-watermark shape with `pushed_shas: []`, `lastBodyReviewId: 0` and `lastConversationCommentId: 0` (forward mode has no prior reviews to skip), and `"forward_stages_in_flight": true`. **Do not** seed `cycle.json` or `requirements.md`. Then arm each PR's watch per [`../../muggle-pr-followup/arm-watcher.md`](../../muggle-pr-followup/arm-watcher.md). The arm writes `owner.json` and `watch-registration.json`, so from here on the PR is watched, owned by this session, and visible to the muggle watch service and to reconcile, however Stage 6 ends.
|
|
72
|
+
|
|
73
|
+
The flag is the hold. While it is set the watch still reports, but the tick dispatches nothing — no address-reviews, rebase, or fix-ci — and logs a `deferred` line instead (the verdict is `hold-forward-stages`), because Stage 6 is testing the head any such cycle would push over. A watch wake that arrives during Stages 6–7.5 runs that tick between steps of this cycle and goes back to the stage in flight; it never pre-empts it. Reviews, CI and branch drift wait in the watermarks, undispatched, for Stage 8.
|
|
74
|
+
|
|
65
75
|
## Stage 7 — report on the PR
|
|
66
76
|
|
|
67
77
|
Runs once Stage 6 has recorded this change's verdict; a Stage 6 readiness halt never reaches it. Per repo, using the provider resolved in Stage 5.5:
|
|
@@ -86,25 +96,17 @@ The E2E repair loop ([`../e2e-repair.md`](../e2e-repair.md)) runs once Stage 7 h
|
|
|
86
96
|
|
|
87
97
|
## Stage 8 handoff
|
|
88
98
|
|
|
89
|
-
After every repo is processed and Stage 7.5 has cleared,
|
|
90
|
-
|
|
91
|
-
Write `~/.muggle-ai/muggle-do/sessions/<slug>/prs.json` per [`../../muggle-pr-followup/state-schemas.md`](../../muggle-pr-followup/state-schemas.md#prsjson):
|
|
92
|
-
|
|
93
|
-
```json
|
|
94
|
-
[{ "repo": "owner/repo", "number": 142, "url": "...", "head_sha": "...", "state": "open" }]
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
Seed `~/.muggle-ai/muggle-do/sessions/<slug>/last_seen.json` per [`../../muggle-pr-followup/state-schemas.md`](../../muggle-pr-followup/state-schemas.md#last_seenjson) — empty-watermark shape with `pushed_shas: []`. Forward mode never has prior reviews to skip, so `lastBodyReviewId: 0` and `lastConversationCommentId: 0`.
|
|
99
|
+
After every repo is processed and Stage 7.5 has cleared, lift the hold Stage 5.5 set and hand each PR to its watch. The handoff ticks are the LAST action this stage takes.
|
|
98
100
|
|
|
99
|
-
|
|
101
|
+
Per PR: rewrite `last_seen.json` without `forward_stages_in_flight` (whole-file rewrite), then run its tick, `/muggle:muggle-pr-followup <slug> <n> --wake=stage-handoff`. The tick refreshes `prs.json` from the provider (Stage 7 may have force-pushed the tested head), dispatches whatever the hold kept back — reviews first, then a rebase or fix-ci — or idles, and leaves one loop polling per [`../../muggle-pr-followup/arm-watcher.md`](../../muggle-pr-followup/arm-watcher.md), the same procedure [`../respawn-watcher.md`](../respawn-watcher.md) settles every later watch with. A loop that died during Stage 6 is re-armed there. Never a recurring `/loop` cron — every cron fire is a model turn, while the loop polls token-free. The PR counts as watched only while that loop is running; a seeded slot alone is not a watch.
|
|
100
102
|
|
|
101
|
-
|
|
103
|
+
Stage 7.5 keeps its meaning: it is still the gate in front of every cycle the watch dispatches, because nothing dispatches until this handoff lifts the hold. A cycle that exits before Stage 8 — a Stage 6 readiness halt, a stalled run — leaves the hold set and says so on the **Stage 8** line: the PR stays watched and its reports still reach this session, but no cycle runs on it until the forward cycle resumes or the user asks for the hold to be lifted.
|
|
102
104
|
|
|
103
|
-
If
|
|
105
|
+
If Stage 5.5 opened no PR, there is no slot and nothing to hand off — record the reason in `result.md` and exit.
|
|
104
106
|
|
|
105
107
|
## Invariants
|
|
106
108
|
|
|
107
|
-
- 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
|
|
109
|
+
- 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 and the watch armed, held, when the PR opens (no `cycle.json`, no `requirements.md`); Stage 7.5 cleared before the hold lifts; the handoff tick is the last action.
|
|
108
110
|
|
|
109
111
|
## Output
|
|
110
112
|
|
|
@@ -117,7 +119,7 @@ The cycle's closing message opens with the [audit trail](../audit-trail.md), on
|
|
|
117
119
|
**Overflow comments posted:** repo → PR #
|
|
118
120
|
**Recurring run:** `already scheduled` | `<recommended options>` (bug fixes only)
|
|
119
121
|
**Stage 7.5:** `green` | `waived — <reason>` | `decision-pending`
|
|
120
|
-
**Stage 8:** `Watching <N> PR(s) — one watch loop per PR,
|
|
122
|
+
**Stage 8:** `Watching <N> PR(s) — hold lifted, one watch loop per PR` | `Held — <reason>; watched since Stage 5.5, cycles wait for the hold to lift` | `No PRs to watch — no slot seeded`
|
|
121
123
|
**Errors:** repo → message
|
|
122
124
|
|
|
123
125
|
## Post-merge cleanup
|
|
@@ -4,5 +4,5 @@ Two modes, set by the `/muggle-do` invocation. Each consumer loads only its mode
|
|
|
4
4
|
|
|
5
5
|
| Mode | When | Procedure |
|
|
6
6
|
| :--- | :--- | :-------- |
|
|
7
|
-
| Forward | A fresh feature, called by `/muggle-do`'s forward pipeline. Opens the PR after Stage 5 (Stage 5.5), settles its walkthrough after Stage 6 (Stage 7),
|
|
7
|
+
| Forward | A fresh feature, called by `/muggle-do`'s forward pipeline. Opens the PR after Stage 5 (Stage 5.5) and arms its watch with cycles held, settles its walkthrough after Stage 6 (Stage 7), lifts the hold at Stage 8. | [`open-prs/forward.md`](open-prs/forward.md) |
|
|
8
8
|
| Update | The PR already exists; the address-reviews orchestrator called this stage to push + refresh title/description/walkthrough. | [`open-prs/update.md`](open-prs/update.md) |
|
|
@@ -45,7 +45,7 @@ The skill recognizes its mode by inspecting `$ARGUMENTS` and falling back to on-
|
|
|
45
45
|
| `reconcile` / `sweep` (optional `<slug>`) | — | **reconcile** → [`reconcile.md`](reconcile.md) |
|
|
46
46
|
| `adopt` (optional `<slug>`) | — | **adopt** → [`adopt.md`](adopt.md) — take over a slot owned by a dead session; no slug lists the adoptable ones |
|
|
47
47
|
|
|
48
|
-
**`--wake=<event>`** is passed only by an event wake's dispatch ([`arm-watcher.md`](arm-watcher.md) step 5),
|
|
48
|
+
**`--wake=<event>`** is passed only by an event wake's dispatch ([`arm-watcher.md`](arm-watcher.md) step 5), by the follow-through Stop gate's instruction (`--wake=follow-through`) when the watch recorded due work nothing attempted or holds a report that never reached the session, or by the pipeline that opened the PR when it hands the PR over (`--wake=stage-handoff`) — each asserts something is waiting, so the tick's poll is justified. A service wake may carry `--also=<slug>:<n>:<kind>,…`: the owner's other slots whose watch reports also wait. After this tick, run `/muggle:muggle-pr-followup <slug> <n> --wake=<kind>` for each listed slot, one at a time, so no owned PR's report is left unread. Manual invocations never pass it; with a live watcher they get watch-status, because a poll that nothing prompted is a main-session poll wasted. Recovery fires need no flag — a recoverable slot's watcher is dead by definition, so the gate falls through to tick. A stale cron firing against a re-armed slot hits the live-`watch.pid` branch and is absorbed as a status line, no provider calls.
|
|
49
49
|
|
|
50
50
|
Auto-track runs **reconcile** first, so a no-arg invocation also finalizes any slot whose PR merged or closed while its watcher was down (expired cron, ended session) and re-arms this session's own open slots whose watcher stopped silently (a dropped respawn). Reconcile recovers a watcher that was already running; it never seeds a first watcher for a PR — that is auto-track's / bootstrap's job — and never re-arms one this session does not own. A no-arg invocation is a request to track *your* PRs, so it can only ever end with the session watching PRs it pushed plus watchers it already had.
|
|
51
51
|
|
|
@@ -16,13 +16,13 @@ The `DRAIN` lines it prints, in the watch's output, are the outstanding work as
|
|
|
16
16
|
|
|
17
17
|
1. **Drain.** Run one tick per [`contract.md`](contract.md). It acts on everything already outstanding — actionable threads (`gitlab`: discussions), body-only reviews past the watermark (GitHub-only — GitLab has no review envelope), conversation comments past theirs (GitHub-only), a stale branch, red CI — and finalizes a terminal PR. If the tick dispatched a cycle, stop here: the cycle's exit path settles the watch when it finishes.
|
|
18
18
|
2. **Seed the watermark.** *(`pr-watch-arm.sh` does this; the reasoning is kept because the floors are subtle and wrong ones are quiet.)* Resolve the provider once per [`../_shared/vcs/detect-vcs.md`](../_shared/vcs/detect-vcs.md) — every fetch in this sequence uses that provider's recipes. Write the slot's watch watermark ([`state-schemas.md`](state-schemas.md#watch-watermarkenv)) to the ids the **drain itself read** — the max review-id, comment-id and human conversation-comment id (`CONV`) observed at the drain's own fetch (Step 1), snapshotted at that read. Never let the loop capture its own baseline — the arming session writes it; and **never** from a fresh fetch taken after the drain, which would include a comment that arrived after the drain read the wave and mark it seen unread. Seeded to the drain's floor, anything landing after that read stays above the watermark and the loop's first iteration surfaces it. Seed the CI floor (`CIRED`) from the same drain read: set it to the red key (`<head_sha>@<red-check-runs>`) only when the checks have **already settled red** at that read (no check pending, one or more in the `fail` bucket per [`../_shared/vcs/common/ci-rollup.md`](../_shared/vcs/common/ci-rollup.md)) **and** fix-ci is finished with that head — it escalated, or spent the tick's per-head budget — and empty otherwise. A lone attempt does not floor: the count is written before the fix runs, so a cycle that recorded it and changed nothing would otherwise leave the red silent. Seed the rebase floor (`REBASED`) the same way, from the drain's branch-standing read per [`../_shared/vcs/common/branch-standing.md`](../_shared/vcs/common/branch-standing.md): the current `rebase_key` (`<head_sha>..<base_tip_sha>`) only when the drain found the branch behind or conflicting **and** a rebase attempt is recorded for that key, empty otherwise. An escalation entry alone never floors anything: one with no attempt behind it records a decision nobody acted on, and flooring it is how a re-arming session once kept a stale branch and a red head silent for a day ([`state-schemas.md`](state-schemas.md#watch-watermarkenv) names the fields). Seed the blocked-CI floor (`BLOCKED_CIDIGEST`) to the blocked fingerprint's `ci_digest` when arming while `last_seen.blocked` is already set, and empty otherwise — empty is the not-blocked state, in which the loop's blocked-resume probe stays dormant. Seed the rebase hold (`REBASE_HELD`) to `1` when `last_seen.json`'s `catch_up_rebases` has reached `maxCatchUpRebases` — the same check the tick's verdict blocks on — and empty otherwise: while it is set the loop raises no rebase wake on any base move. The script reads all four facts from `last_seen.json` through [`../../scripts/pr-watch-verdict.mjs`](../../scripts/pr-watch-verdict.mjs) `arm-floors`, and records what it found due in `watch-due.env` ([`state-schemas.md`](state-schemas.md#watch-dueenv)).
|
|
19
|
-
3. **Dedup, then watch.** First read `<slot>/watch.pid` ([`state-schemas.md`](state-schemas.md#watchpid)): if it names a live process (`kill -0 "$pid"` succeeds)
|
|
19
|
+
3. **Dedup, then watch.** First read `<slot>/watch.pid` ([`state-schemas.md`](state-schemas.md#watchpid)): if it names a live process (`kill -0 "$pid"` succeeds), **`owner.json` records this session**, and the slot has no [`watch-listener`](state-schemas.md#watch-listener) file, a watcher already owns this slot — **skip arming, do not start a second**. A live loop whose `watch-listener` names `muggle-watch` was started by the muggle watch service and reports to the service, not to this session: arm over it. The new loop supersedes it, takes the slot back, and deletes the service's undelivered reports, which this arm's drain covers. This is what stops orphaned watchers from accumulating: the in-session task dying does not stop the OS loop it launched (on Windows a detached Git Bash loop keeps running and polling `gh` forever after the session ends), so checking a live task list is not enough — the PID lease is.
|
|
20
20
|
|
|
21
21
|
**A live lease owned by a different session does not count as owned** — check it with `watcher_lease_is_foreign` from [`../../scripts/pr-watch-guards.sh`](../../scripts/pr-watch-guards.sh). A live PID proves the loop is running, never that anything is listening: an orphan left by a dead session keeps polling and keeps touching its heartbeat while its stdout is that session's closed pipe, so every liveness signal reads healthy and the events reach nobody. Skipping on the PID alone let such a corpse block this session from arming the PR for the whole lifetime cap — seven days, since the default moved off six hours. When the guard reports a foreign lease, kill that PID, delete `watch.pid`, and arm fresh; note it in the slot's `followup.log` so the reclaim is visible.
|
|
22
22
|
|
|
23
23
|
This is narrow on purpose. It reclaims only a lease held on behalf of *another* session, which is decidable from `owner.json` alone. A loop orphaned by its **own** session still reads as owned, and nothing on disk distinguishes it — so the signal comes from the reader instead. **When this arm answers the slot's own loop ending — its `EXPIRED` or `ROLLOVER` line, or a monitor's expiry notice — skip this dedup and arm.** Each means the previous loop is gone or no longer heard. The new loop writes its PID to `watch.pid`, and `watcher_superseded` retires any survivor at its next iteration. Treat an armed watcher as evidence a poller exists, never as proof a review will be seen.
|
|
24
24
|
|
|
25
|
-
Otherwise **claim the slot for this session** before starting anything: write `owner.json` ([`state-schemas.md`](state-schemas.md#ownerjson)) with `session_id` from `$CLAUDE_CODE_SESSION_ID` and `claimed_at` now. Arming is what establishes ownership, so every arming point records it here rather than each caller remembering to. If `$CLAUDE_CODE_SESSION_ID` is unset, write no `owner.json` — an unidentifiable owner is worse than none, since [`reconcile.md`](reconcile.md) would read a bogus id as some other session's claim and could never recover the slot.
|
|
25
|
+
Otherwise **claim the slot for this session** before starting anything: write `owner.json` ([`state-schemas.md`](state-schemas.md#ownerjson)) with `session_id` from `$CLAUDE_CODE_SESSION_ID` and `claimed_at` now. `pr-watch-arm.sh --owner <session-id>` claims for that session instead; the muggle watch service passes the id `owner.json` already records, so the loops it restarts stay owned. Arming is what establishes ownership, so every arming point records it here rather than each caller remembering to. If `$CLAUDE_CODE_SESSION_ID` is unset, write no `owner.json` — an unidentifiable owner is worse than none, since [`reconcile.md`](reconcile.md) would read a bogus id as some other session's claim and could never recover the slot.
|
|
26
26
|
|
|
27
27
|
The same claim **registers the slot with the muggle watch service**: `pr-watch-arm.sh` writes [`watch-registration.json`](state-schemas.md#watch-registrationjson) beside `owner.json`. The service is a per-user scheduled job that runs outside every session. When a registered slot's loop is gone, it starts the loop itself as a detached program, so no session spends a turn on it. When that loop reports, the service wakes the owner session with that one PR's tick, and only between turns. It never sends a session a reconcile or anything about another PR. A slot armed any other way is registered with `muggle watch register --slot <slot>`. `muggle watch unregister --slot <slot>` keeps a slot session-scoped. The service still reports on it, but never starts its loop or wakes its owner.
|
|
28
28
|
|
|
@@ -92,6 +92,10 @@ The watcher's dispatch trigger is **derived from current provider state**, not a
|
|
|
92
92
|
|
|
93
93
|
- **`gitlab`** — single source. Fetch unresolved discussions per [`../_shared/vcs/gitlab/unresolved-discussions.md`](../_shared/vcs/gitlab/unresolved-discussions.md) (drop to [`../_shared/vcs/gitlab/mr-discussions.md`](../_shared/vcs/gitlab/mr-discussions.md) for the raw notes if a thread's classification needs them). A discussion is **actionable** when it is unresolved **and** its newest note lacks the loop marker `<!-- muggle-do:bot -->` — same marker classification, never `author.username`. There is no body-only watermark: discussion state is the sole authority. The dispatch list is the **discussion ids** of the actionable discussions.
|
|
94
94
|
|
|
95
|
+
### Step 3.5 — Forward-stage hold
|
|
96
|
+
|
|
97
|
+
When `last_seen[<pr>].forward_stages_in_flight` is `true` ([`state-schemas.md`](state-schemas.md#last_seenjson)), the pipeline that opened this PR still owns it: it set the flag when it opened the PR and armed this watch, and clears it at its handoff, which then runs this tick with `--wake=stage-handoff`. Dispatch nothing, reviews included: that pipeline is still testing the head a cycle would push over, and it alone decides when the watch may act. Append a `deferred` line to `followup.log` naming what the tick would have dispatched (review ids, conversation comment ids), skip Steps 4–6 and exit as transient idle through Step 7.5, so the loop keeps watching. Nothing is lost: the review and conversation watermarks are not advanced, so the handoff's tick finds the same actionable set. A terminal PR still finalizes in Step 2.
|
|
98
|
+
|
|
95
99
|
### Step 4 — If the actionable set is non-empty → dispatch (reviews preempt CI)
|
|
96
100
|
|
|
97
101
|
The watcher does **not** classify. Classification, batching, replying, escalation, and cycle execution all live in `/muggle-do`. The watcher hands over the dispatch ids from Step 3 (GitHub: owning review ids; GitLab: discussion ids) and exits — `/muggle-do`'s address-reviews re-derives the unresolved threads itself (its authority), so the watcher only needs to decide *that* there is work, not enumerate it exhaustively.
|
|
@@ -143,6 +147,7 @@ node "<abs>/scripts/pr-watch-verdict.mjs" tick --pr-key "<owner>/<repo>#<n>" --h
|
|
|
143
147
|
|
|
144
148
|
It prints one line, `VERDICT=<verdict>`. A non-zero exit is a broken install: report it and stop, never improvise a verdict. What it applies, in order:
|
|
145
149
|
|
|
150
|
+
0. `forward_stages_in_flight` is `true` → `hold-forward-stages`, whatever the branch and CI say (Step 3.5).
|
|
146
151
|
1. A rebase is due and `catch_up_rebases >= maxCatchUpRebases` (the cap from the user's preferences; the `rebase_budget_exhausted` flag is not consulted) → `block-rebase-budget-exhausted`.
|
|
147
152
|
2. A rebase is due, `conflict_resolve_attempts[rebase_key] < 2`, and `rebase_key` ∉ `conflict_escalated_keys` → `dispatch-rebase`. With the per-key budget spent — `conflict_resolve_attempts[rebase_key] >= 2` or `rebase_key` ∈ `conflict_escalated_keys` — it falls through to CI.
|
|
148
153
|
3. CI is `red`, `ci_fix_attempts[head_sha] < 3`, and `head_sha` ∉ `ci_escalated_shas` → `dispatch-fix-ci`. Red with `ci_fix_attempts[head_sha] >= 3` or `head_sha` ∈ `ci_escalated_shas` dispatches nothing — the fix budget is spent and the watcher does not re-dispatch; it holds as `block-ci-escalated` (Step 4) even when fix-ci never wrote the escalation, because idling there leaves a red PR with nobody told. A check still pending (`bucket == "pending"`) never dispatches: the tick idles until CI settles, and a green head idles too.
|
|
@@ -176,6 +181,7 @@ Act on the verdict:
|
|
|
176
181
|
4. Append a dispatching line to `followup.log`; emit a `tick` event with `checks_red: <count>`, `dispatched_ci_fix: true`.
|
|
177
182
|
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.
|
|
178
183
|
- `block-conflict-escalated`, `block-ci-escalated`, `block-reviews-escalated` → blocked pending a human (Step 7).
|
|
184
|
+
- `hold-forward-stages` → transient idle (Step 7), with a `deferred` line in `followup.log` naming the rebase or fix-ci the hold kept back (Step 3.5).
|
|
179
185
|
- `idle` → transient idle (Step 7).
|
|
180
186
|
|
|
181
187
|
### Step 7 — Idle (remind when blocked pending a human)
|
|
@@ -18,7 +18,7 @@ Two invariants hold on every trigger, however the sweep was reached: it never se
|
|
|
18
18
|
|
|
19
19
|
A watcher reports to its session: a loop armed in a session prints into it, so a session that ends or hits its usage limit stops hearing its watches. No poller acts on a PR out of session. This is deliberate: a review is addressed only inside a session that carries the context to address it, never by a headless process that would reply without that context.
|
|
20
20
|
|
|
21
|
-
What does run out of session is the muggle watch service (`muggle watch`, a per-user scheduled job). It addresses nothing on any PR, and it never sends a session this sweep. For a slot registered in [`watch-registration.json`](state-schemas.md#watch-registrationjson) whose loop is gone, it restarts the loop itself as a detached program, which costs no session a turn. When that loop reports, it wakes the **owning** session with that one PR's tick, `/muggle:muggle-pr-followup <slug> <n> --wake=<event
|
|
21
|
+
What does run out of session is the muggle watch service (`muggle watch`, a per-user scheduled job). It addresses nothing on any PR, and it never sends a session this sweep. For a slot registered in [`watch-registration.json`](state-schemas.md#watch-registrationjson) whose loop is gone, it restarts the loop itself as a detached program, which costs no session a turn. When that loop reports, it wakes the **owning** session with that one PR's tick, `/muggle:muggle-pr-followup <slug> <n> --wake=<event>`, naming the owner's other waiting reports in `--also`. It does so only between turns, never while the session works or waits on its user. A report waiting on a busy owner never leaves the PR unwatched: the service queues it and restarts the loop, claimed for the owner `owner.json` records. A plugin reload leaves a session that owns open watches running. A slot whose PR went terminal while neither its loop nor its owner is running it finalizes itself, as Step 3 would, leaving the post-merge cleanup unrun. Everything else it finds (red CI, a stale branch, a report its owner cannot take yet) it only reports.
|
|
22
22
|
|
|
23
23
|
**Ownership is session-scoped too, and that is what bounds recovery.** Each slot records the session that armed it in [`owner.json`](state-schemas.md#ownerjson). Step 3.6 re-arms only slots the running session owns — watchers it armed itself, whose poller died under it. A slot owned by another session, or by none, is **never** re-armed here however dead its poller looks. The same argument that forbids a headless daemon forbids a fresh session inheriting a stranger's PR: it would be picking up review work it has no context for, on a branch it never built, and every push it made would be as context-blind as the daemon the design already rejected. Adoption exists precisely so that step is a deliberate act by the owner ([`adopt.md`](adopt.md)) rather than a side effect of starting a session.
|
|
24
24
|
|
|
@@ -59,9 +59,9 @@ The slot's opt-in to recovery by the muggle watch service (`muggle watch`, a per
|
|
|
59
59
|
}
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
Recovery requires all of: the slot is registered, the PR is open on GitHub, no loop is heard (no loop process carries the slot's `--slot` path, or the one that does prints into a session that has ended), the heartbeat is older than the re-arm hand-off, `polling.disabled` is absent, `owner.json` names an owner, and that owner is not mid-turn. The service then runs `pr-watch-arm.sh` itself, detached, with `MUGGLE_PR_WATCH_LISTENER=muggle-watch
|
|
62
|
+
Recovery requires all of: the slot is registered, the PR is open on GitHub, no loop is heard (no loop process carries the slot's `--slot` path, or the one that does prints into a session that has ended), the heartbeat is older than the re-arm hand-off, `polling.disabled` is absent, `owner.json` names an owner, and that owner is not mid-turn. A report the owner has not been woken for never holds the PR unwatched: the service sets it aside in [`watch-service.queued.out`](#watch-servicequeuedout) and starts the fresh loop, mid-turn owner or not. The service then runs `pr-watch-arm.sh` itself, detached, with `MUGGLE_PR_WATCH_LISTENER=muggle-watch` and `--owner <session_id>` from `owner.json`, so the arm claims the slot for its recorded owner rather than leaving it unowned. The loop records [`watch-listener`](#watch-listener) and writes its output to [`watch-service.out`](#watch-serviceout), and no session spends a turn on it.
|
|
63
63
|
|
|
64
|
-
When that loop exits on an `EVENT` or `TERMINAL` line, the service wakes the owner with `/muggle:muggle-pr-followup <slug> <n> --wake=<event|terminal>`, naming that slot and PR
|
|
64
|
+
When that loop exits on an `EVENT` or `TERMINAL` line, or a queued report waits, the service wakes the owner with `/muggle:muggle-pr-followup <slug> <n> --wake=<event|terminal>`, naming that slot and PR. Every other slot of the same owner with a report waiting rides along as `--also=<slug>:<n>:<kind>,…`, so one wake tells the session about all of them. It resumes the owner in the background from the project dir its transcript records. A running owner is woken only as a background session idle between turns: it is stopped first, and only after a throwaway background launch confirms Claude will resume it in that workspace. The resume runs only once neither `claude agents` nor Claude's own session registry shows a process for the owner. If Claude still answers with a copy under a new id, the service stops and removes that copy and counts the wake as failed, so the agent view never gains a duplicate. An owner that is mid-turn, waiting on its user, or open in a terminal keeps the report, the service alerts once the report is overdue, and the follow-through Stop gate names the report's tick at the owner's next turn end. The service never wakes the ended owner of a merged or closed PR; it closes that slot out instead. An `EXPIRED` loop is restarted without waking anyone. The service caps loop starts and wakes per pass, caps failed wakes per owner, and holds every wake while the account sits at a usage limit.
|
|
65
65
|
|
|
66
66
|
**Absent ⇒ observed only.** The service still reports on the slot's watcher, CI and branch standing, but never starts its loop or wakes its owner. Slots armed before this file existed stay that way until their next arm. The file lives in the slot, so a `.stopped` rename or a `result.md` retires it with the slot.
|
|
67
67
|
|
|
@@ -73,6 +73,10 @@ Who hears the leased loop's exit. A loop started with `MUGGLE_PR_WATCH_LISTENER`
|
|
|
73
73
|
|
|
74
74
|
The output of the last loop the muggle watch service started for the slot. Its `EVENT`, `TERMINAL`, `EXPIRED`, `WATCH-FAIL` or `ARM-FAIL` line says why the loop ended. Once the owner is woken for an `EVENT` or `TERMINAL` report, the file is renamed `watch-service.delivered.out`, so no later pass wakes the owner for it again. A loop a session arms deletes the file, because that arm's drain covers whatever it held.
|
|
75
75
|
|
|
76
|
+
## `watch-service.queued.out`
|
|
77
|
+
|
|
78
|
+
Service loop reports the owner has not been woken for, set aside when the service starts a fresh loop over them, so the PR stays watched while the report waits. Each report is appended; the file's time is when the first one was reported. The owner's wake renames it, with any `watch-service.out` report, into `watch-service.delivered.out`, and a loop a session arms deletes it, as it does `watch-service.out`. While it is non-empty in a slot this session owns, the follow-through Stop gate blocks the turn end naming `/muggle:muggle-pr-followup <slug> <n> --wake=follow-through`.
|
|
79
|
+
|
|
76
80
|
## `cron.json`
|
|
77
81
|
|
|
78
82
|
A durable, on-disk handle to this slot's watcher cron. Its whole reason to exist: `CronList` goes **blind to crons that outlive a session continue / compaction** (the watcher's `/loop` cron survives, but the tool can no longer enumerate it), so a teardown that can only find crons through `CronList` can never delete the orphan — it re-fires until the 7-day `/loop` expiry. A cron id recorded to disk **while the cron was still visible** stays a valid `CronDelete` target afterward. See [`record-cron-id.md`](record-cron-id.md) (who writes it) and [`cancel-cron.md`](cancel-cron.md) (who deletes by it).
|
|
@@ -112,6 +116,7 @@ Keyed by `"<owner>/<repo>#<n>"`. One key per PR in the slot.
|
|
|
112
116
|
"conflict_escalated_keys": ["<head-sha>..<base-tip-sha>", ...],
|
|
113
117
|
"catch_up_rebases": <int>,
|
|
114
118
|
"rebase_budget_exhausted": <bool>,
|
|
119
|
+
"forward_stages_in_flight": <bool>,
|
|
115
120
|
"e2e_decision": {
|
|
116
121
|
"head_sha": "<sha>",
|
|
117
122
|
"cases": [{ "name": "<test case>", "testCaseId": "<id>", "bucket": "<bucket>", "failedStep": <int>, "waived": <bool> }]
|
|
@@ -132,6 +137,7 @@ Keyed by `"<owner>/<repo>#<n>"`. One key per PR in the slot.
|
|
|
132
137
|
|
|
133
138
|
- `lastBodyReviewId`: narrow watermark for **body-only** reviews (a submitted review carrying no line comments). The watcher dispatches a body-only review only when `id > lastBodyReviewId`. Line-comment threads do **not** use it — they are dispatched from live thread state (unresolved + not outdated + newest comment unmarked by the loop), so there is no cursor that can pin past them. Bootstrap sets it to the highest existing submitted review id with `--forward-only`, else `0`. The cursor keeps its name under GitLab, where it holds the highest note / discussion id.
|
|
134
139
|
- `lastConversationCommentId` (GitHub only): narrow watermark for **conversation comments** — top-level PR comments on the Conversation tab, which belong to no review and no thread. The watcher dispatches one only when `id > lastConversationCommentId` ([`../_shared/vcs/github/conversation-comments.md`](../_shared/vcs/github/conversation-comments.md)). Issue-comment ids are their own sequence, so this never shares `lastBodyReviewId`. Bootstrap, auto-track and forward mode write it beside `lastBodyReviewId` — `0`, or the highest existing conversation comment id under `--forward-only`. An entry **without** the key predates conversation comments being watched: the tick seeds it to the highest actionable id it reads and dispatches none of them, so an upgrade never re-answers a PR's comment history.
|
|
140
|
+
- `forward_stages_in_flight`: `true` while the pipeline that opened the PR still owns it. That pipeline opens the PR, seeds the slot with the flag set and arms the watch in one step, so the PR is watched and registered with the muggle watch service from the moment it exists. While it is set the tick dispatches nothing ([`contract.md`](contract.md) Step 3.5), the verdict script answers `hold-forward-stages`, and the follow-through Stop gate owes nothing for the PR. The pipeline removes the key at its handoff and runs the tick with `--wake=stage-handoff`, which dispatches whatever the hold kept back. Absent means `false`.
|
|
135
141
|
- `last_pushed_sha`: most recent SHA `/muggle-do` pushed in this PR's life; `null` until the first push.
|
|
136
142
|
- `idle_tick_count`: incremented each tick whose actionable set is empty. Reset to 0 on any tick that dispatches `/muggle-do`. Diagnostic only — does not gate behavior.
|
|
137
143
|
- `cycles_completed`: incremented each time `/muggle-do` completes an address-reviews invocation (regardless of actionable/ambiguous/mixed).
|