@muggleai/works 5.26.0-staging.207 → 5.26.0-staging.208
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/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 +2 -1
- package/dist/plugin/hooks/codex-hooks.json +2 -2
- package/dist/plugin/hooks/hooks.json +1 -1
- package/dist/plugin/scripts/guardrail-watch-follow-through-gate.sh +48 -0
- package/dist/plugin/scripts/guardrails.mjs +282 -32
- package/dist/plugin/scripts/pr-watch-arm.sh +64 -37
- package/dist/plugin/scripts/pr-watch-due.sh +31 -0
- package/dist/plugin/scripts/pr-watch-events.sh +20 -6
- package/dist/plugin/scripts/pr-watch-loop.sh +21 -2
- package/dist/plugin/scripts/pr-watch-verdict.mjs +197 -0
- package/dist/plugin/skills/_shared/ci-check-to-command.md +2 -1
- package/dist/plugin/skills/do/fix-ci.md +24 -8
- package/dist/plugin/skills/do/resolve-conflicts.md +7 -3
- package/dist/plugin/skills/muggle-pr-followup/SKILL.md +1 -1
- package/dist/plugin/skills/muggle-pr-followup/arm-watcher.md +5 -3
- package/dist/plugin/skills/muggle-pr-followup/blocked-tick.md +2 -0
- package/dist/plugin/skills/muggle-pr-followup/contract.md +40 -25
- package/dist/plugin/skills/muggle-pr-followup/state-schemas.md +22 -8
- package/dist/release-manifest.json +3 -3
- 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 +2 -1
- package/plugin/hooks/codex-hooks.json +2 -2
- package/plugin/hooks/hooks.json +1 -1
- package/plugin/scripts/guardrail-watch-follow-through-gate.sh +48 -0
- package/plugin/scripts/guardrails.mjs +282 -32
- package/plugin/scripts/pr-watch-arm.sh +64 -37
- package/plugin/scripts/pr-watch-due.sh +31 -0
- package/plugin/scripts/pr-watch-events.sh +20 -6
- package/plugin/scripts/pr-watch-loop.sh +21 -2
- package/plugin/scripts/pr-watch-verdict.mjs +197 -0
- package/plugin/skills/_shared/ci-check-to-command.md +2 -1
- package/plugin/skills/do/fix-ci.md +24 -8
- package/plugin/skills/do/resolve-conflicts.md +7 -3
- package/plugin/skills/muggle-pr-followup/SKILL.md +1 -1
- package/plugin/skills/muggle-pr-followup/arm-watcher.md +5 -3
- package/plugin/skills/muggle-pr-followup/blocked-tick.md +2 -0
- package/plugin/skills/muggle-pr-followup/contract.md +40 -25
- package/plugin/skills/muggle-pr-followup/state-schemas.md +22 -8
- /package/dist/{chunk-HGN35NEP.js → chunk-HOKMW4AL.js} +0 -0
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"name": "muggleai",
|
|
10
10
|
"source": "./plugin",
|
|
11
11
|
"description": "Real-browser E2E acceptance for your coding agent: test the flows you changed and open the PR with screenshots. Built for flows other tools can't reach: managed test identities with live inboxes (magic links, email OTP and 2FA, verification mail, password resets), an encrypted secret store for login and test credentials, and a test graph that runs prerequisite flows first. Plain-English tests become replayable scripts on localhost or preview URLs.",
|
|
12
|
-
"version": "5.26.0-staging.
|
|
12
|
+
"version": "5.26.0-staging.208"
|
|
13
13
|
}
|
|
14
14
|
]
|
|
15
15
|
}
|
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { src_exports as commands, createUnifiedMcpServer, server_exports as server } from './chunk-
|
|
1
|
+
export { src_exports as commands, createUnifiedMcpServer, server_exports as server } from './chunk-HOKMW4AL.js';
|
|
2
2
|
export { createChildLogger, e2e_exports as e2e, getConfig, getLocalQaTools, getLogger, getQaTools, local_exports as localQa, mcp_exports as mcp, e2e_exports as qa, src_exports as shared } from './chunk-ZR7KLGHQ.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "muggle",
|
|
3
3
|
"description": "Real-browser E2E acceptance for your coding agent: test the flows you changed and open the PR with screenshots. Built for flows other tools can't reach: managed test identities with live inboxes (magic links, email OTP and 2FA, verification mail, password resets), an encrypted secret store for login and test credentials, and a test graph that runs prerequisite flows first. Plain-English tests become replayable scripts on localhost or preview URLs.",
|
|
4
|
-
"version": "5.26.0-staging.
|
|
4
|
+
"version": "5.26.0-staging.208",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Muggle AI",
|
|
7
7
|
"email": "support@muggle-ai.com"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "muggle",
|
|
3
|
-
"version": "5.26.0-staging.
|
|
3
|
+
"version": "5.26.0-staging.208",
|
|
4
4
|
"description": "Real-browser E2E acceptance for your coding agent: test the flows you changed and open the PR with screenshots. Built for flows other tools can't reach: managed test identities with live inboxes (magic links, email OTP and 2FA, verification mail, password resets), an encrypted secret store for login and test credentials, and a test graph that runs prerequisite flows first. Plain-English tests become replayable scripts on localhost or preview URLs.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Muggle AI",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "muggle",
|
|
3
3
|
"displayName": "Muggle AI",
|
|
4
4
|
"description": "Real-browser E2E acceptance for your coding agent: test the flows you changed and open the PR with screenshots. Built for flows other tools can't reach: managed test identities with live inboxes (magic links, email OTP and 2FA, verification mail, password resets), an encrypted secret store for login and test credentials, and a test graph that runs prerequisite flows first. Plain-English tests become replayable scripts on localhost or preview URLs.",
|
|
5
|
-
"version": "5.26.0-staging.
|
|
5
|
+
"version": "5.26.0-staging.208",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Muggle AI",
|
|
8
8
|
"email": "support@muggle-ai.com"
|
package/dist/plugin/.mcp.json
CHANGED
|
@@ -20,7 +20,7 @@ A guardrail emits one of two strengths:
|
|
|
20
20
|
- **Advise** — `additionalContext` (PostToolUse/UserPromptSubmit) or a plain Stop message. A soft nudge the model can ignore.
|
|
21
21
|
- **Enforce** — a `Stop` `decision: "block"` that refuses to end the turn, or a `PreToolUse` `permissionDecision: "deny"` that refuses a tool call. The model cannot proceed until the condition is met.
|
|
22
22
|
|
|
23
|
-
Enforcement is reserved for the handoffs that were being skipped: the E2E acceptance run, posting a deterministically-rendered report, and the post-merge handoff. Each enforcing gate carries an escape so it can't trap a turn — the E2E gate accepts an explicit skip declaration (`echo "MUGGLE_E2E_SKIP: <reason>"`, session-durable) and hard-releases after `MAX_E2E_BLOCKS` (3) blocks; the report gate only denies a body it can positively see is a hand-written report and fails open otherwise; the post-merge gate hard-releases after `MAX_PR_TERMINAL_BLOCKS` (3) blocks, and only the AskUserQuestion next-options offer clears it — nothing else resets its counter.
|
|
23
|
+
Enforcement is reserved for the handoffs that were being skipped: the E2E acceptance run, posting a deterministically-rendered report, and the post-merge handoff. Each enforcing gate carries an escape so it can't trap a turn — the E2E gate accepts an explicit skip declaration (`echo "MUGGLE_E2E_SKIP: <reason>"`, session-durable) and hard-releases after `MAX_E2E_BLOCKS` (3) blocks; the report gate only denies a body it can positively see is a hand-written report and fails open otherwise; the post-merge gate hard-releases after `MAX_PR_TERMINAL_BLOCKS` (3) blocks, and only the AskUserQuestion next-options offer clears it — nothing else resets its counter. The watcher follow-through gate is the one with no block budget, because a budget the session can wait out is the very hold it must not take: its escape is doing the work, or the user's own `HOLD WATCH #<pr-number>`.
|
|
24
24
|
|
|
25
25
|
## Mechanism
|
|
26
26
|
|
|
@@ -47,6 +47,7 @@ Pre-filters are bash builtins only (`guardrail-lib.sh`), so an irrelevant event
|
|
|
47
47
|
| `Stop` | `guardrail-e2e-gate.sh` | **enforce** | unit tests passed this session, no E2E ran yet, and no skip was recorded | `autoE2ETest` | **block** the turn until E2E runs via `muggle-test` or a `MUGGLE_E2E_SKIP` marker records a legitimate skip (full message once, one-line reminders after; releases after 3 blocks) |
|
|
48
48
|
| `Stop` | `guardrail-terminal-gate.sh` | **enforce** | a PR went terminal this session and the AskUserQuestion next-options offer hasn't run since | — | **block** the turn until the post-merge handoff runs (full message once, one-line reminders after; releases after 3 blocks; nothing but the offer resets the counter) |
|
|
49
49
|
| `Stop` | `guardrail-watch-gate.sh` | **enforce** | a PR opened this session that is still open and has no live watch — no session slot for it is terminal, stopped by its owner, or carries a `watch-heartbeat` touched within 15 minutes; a slot that is only seeded does not count | `autoWatchPR` | **block** the turn until the watch is armed per `muggle-pr-followup`'s `arm-watcher.md` or a `MUGGLE_WATCH_SKIP` marker records a legitimate skip (releases after 3 blocks). A PR clears once the session sees it go terminal or a provider lookup reports it merged or closed — what lets a PR whose slot post-merge cleanup deleted through. The lookup runs in a detached scan queued at turn end; a PR it has not reached yet still blocks, and one it could not reach fails open |
|
|
50
|
+
| `Stop` | `guardrail-watch-follow-through-gate.sh` | **enforce** | a `muggle-pr-followup` watch this session owns (the slot's `owner.json`) recorded due work in `watch-due.env` — a branch behind or conflicting with its base, or a head whose checks settled red — and `last_seen.json` records no attempt for it: no `conflict_resolve_attempts` entry for the rebase key (enforced under `autoRebase=always` while catch-up budget is left), no `ci_fix_attempts` entry for the red head. An escalation entry with no attempt behind it counts for nothing, and re-arming the watch changes nothing | `autoRebase` | **block** the turn, naming each PR and its `/muggle-do rebase` or `fix ci` dispatch. No release after N blocks: only a recorded attempt, a newer head in the slot's `prs.json`, or the user's literal `HOLD WATCH #<pr-number>` clears it. The hold must come from a turn the user typed — never a tool result, a loaded skill, a hook's message, a task notification, a compaction summary, or the agent's own text — and is kept for the session once read. Reads local files only, never a provider: the pre-filter is a builtins glob for a non-empty `watch-due.env` whose `owner.json` names the session, so Node starts only when a slot has due work |
|
|
50
51
|
| `Stop` | `guardrail-walkthrough-gate.sh` | **enforce** | an E2E acceptance run happened this session and a PR in play — opened this session or on the working branch — carries no walkthrough in its body or comments; or an E2E skip was accepted and a PR in play still shows the empty placeholder instead of the skip's record | `postPRVisualWalkthrough` | **block** the turn until the walkthrough is posted via `muggle-pr-visual-walkthrough` or a `MUGGLE_WALKTHROUGH_SKIP` marker records a legitimate skip. For an accepted E2E skip, the block hands over the foreground `settle-walkthrough-skipped <pr> <session>` command, which prints `{"settled":true}` once the PR reads back the skip, and re-queues the detached write (releases after 3 blocks; an unreachable PR fails open to not-owed). A skip accepted before its PR existed is written straight into the PR's slot when it opens. The provider lookups run in a detached scan, queued when the gate arms, when a PR opens, and at each turn end; the gate decides on the last scan for the session's current PRs and stays open until one lands |
|
|
51
52
|
| `Stop` | `guardrail-stage-gate.sh` | **enforce** | a skill invoked this session declared `mandatoryStages` and one of those files was never opened | — | **block** the turn until the stages are read or a `MUGGLE_STAGE_SKIP` marker records a legitimate skip (releases after 3 blocks) |
|
|
52
53
|
| `Stop` | `guardrail-debug-path-gate.sh` | **enforce** | a local execution returned a non-passing run this session and nothing routed it through `_shared/debug-failed-run.md` | — | **block** the turn until the run is diagnosed (its `*-failure-classified` emit or feedback naming it) or a `MUGGLE_DEBUG_SKIP: <runId> <reason>` marker clears that run (releases after 3 blocks) |
|
|
@@ -115,10 +115,10 @@
|
|
|
115
115
|
"hooks": [
|
|
116
116
|
{
|
|
117
117
|
"type": "command",
|
|
118
|
-
"command": "env MUGGLE_HOOK_HOST=codex bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-e2e-gate.sh guardrail-terminal-gate.sh guardrail-watch-gate.sh guardrail-build-followthrough-gate.sh guardrail-walkthrough-gate.sh guardrail-comment-reply-gate.sh guardrail-stage-gate.sh guardrail-debug-path-gate.sh guardrail-capability-claim.sh",
|
|
118
|
+
"command": "env MUGGLE_HOOK_HOST=codex bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-e2e-gate.sh guardrail-terminal-gate.sh guardrail-watch-gate.sh guardrail-watch-follow-through-gate.sh guardrail-build-followthrough-gate.sh guardrail-walkthrough-gate.sh guardrail-comment-reply-gate.sh guardrail-stage-gate.sh guardrail-debug-path-gate.sh guardrail-capability-claim.sh",
|
|
119
119
|
"async": false,
|
|
120
120
|
"timeout": 10,
|
|
121
|
-
"commandWindows": "node \"${CLAUDE_PLUGIN_ROOT}\\scripts\\codex-hook-windows.mjs\" \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-e2e-gate.sh guardrail-terminal-gate.sh guardrail-watch-gate.sh guardrail-build-followthrough-gate.sh guardrail-walkthrough-gate.sh guardrail-comment-reply-gate.sh guardrail-stage-gate.sh guardrail-debug-path-gate.sh guardrail-capability-claim.sh"
|
|
121
|
+
"commandWindows": "node \"${CLAUDE_PLUGIN_ROOT}\\scripts\\codex-hook-windows.mjs\" \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-e2e-gate.sh guardrail-terminal-gate.sh guardrail-watch-gate.sh guardrail-watch-follow-through-gate.sh guardrail-build-followthrough-gate.sh guardrail-walkthrough-gate.sh guardrail-comment-reply-gate.sh guardrail-stage-gate.sh guardrail-debug-path-gate.sh guardrail-capability-claim.sh"
|
|
122
122
|
}
|
|
123
123
|
]
|
|
124
124
|
}
|
|
@@ -149,7 +149,7 @@
|
|
|
149
149
|
"hooks": [
|
|
150
150
|
{
|
|
151
151
|
"type": "command",
|
|
152
|
-
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-e2e-gate.sh guardrail-terminal-gate.sh guardrail-watch-gate.sh guardrail-build-followthrough-gate.sh guardrail-walkthrough-gate.sh guardrail-comment-reply-gate.sh guardrail-stage-gate.sh guardrail-debug-path-gate.sh guardrail-capability-claim.sh",
|
|
152
|
+
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-e2e-gate.sh guardrail-terminal-gate.sh guardrail-watch-gate.sh guardrail-watch-follow-through-gate.sh guardrail-build-followthrough-gate.sh guardrail-walkthrough-gate.sh guardrail-comment-reply-gate.sh guardrail-stage-gate.sh guardrail-debug-path-gate.sh guardrail-capability-claim.sh",
|
|
153
153
|
"async": false,
|
|
154
154
|
"timeout": 1
|
|
155
155
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -uo pipefail
|
|
3
|
+
|
|
4
|
+
# watcher follow-through gate (Stop). When a muggle-pr-followup watch this
|
|
5
|
+
# session owns has recorded due work — a rebase on a stale branch, a fix on a red
|
|
6
|
+
# head — and no attempt for it is recorded, block the turn end and name the
|
|
7
|
+
# dispatch. Released only by the attempt itself, a new head, or the user's own
|
|
8
|
+
# HOLD WATCH #<pr-number>: a session once sat on both for a day, re-arming its
|
|
9
|
+
# watch and asking "needs input" at every wake, and every prose rule against it
|
|
10
|
+
# held only as long as the session agreed with it.
|
|
11
|
+
#
|
|
12
|
+
# Synchronous (only a sync Stop hook can block the turn end) and fires on every
|
|
13
|
+
# turn end, so the pre-filter is bash builtins only: a glob over the slots for a
|
|
14
|
+
# non-empty watch-due.env (the watch loop empties it when nothing is due) whose
|
|
15
|
+
# owner.json names this session. No slot has one on nearly every turn, so Node
|
|
16
|
+
# never starts. The attempt counters, preferences, and the hold are judged in
|
|
17
|
+
# guardrails.mjs, from local files alone — no provider call. Degrades to {}.
|
|
18
|
+
|
|
19
|
+
guardrail_script_dir="${BASH_SOURCE[0]%/*}"
|
|
20
|
+
[[ $guardrail_script_dir == "${BASH_SOURCE[0]}" ]] && guardrail_script_dir=.
|
|
21
|
+
. "$guardrail_script_dir/guardrail-lib.sh"
|
|
22
|
+
|
|
23
|
+
GUARDRAIL_SUBCOMMAND="watch-follow-through-gate"
|
|
24
|
+
|
|
25
|
+
guardrail_wants() {
|
|
26
|
+
guardrail_payload_field session_id || return 1
|
|
27
|
+
local session_id="$GUARDRAIL_FIELD_VALUE"
|
|
28
|
+
[[ -n $session_id ]] || return 1
|
|
29
|
+
guardrail_resolve_home
|
|
30
|
+
# A backslash in a glob escapes the next character, so a native Windows HOME
|
|
31
|
+
# would match nothing; forward slashes name the same directory.
|
|
32
|
+
local sessions_dir="${GUARDRAIL_HOME//\\//}/.muggle-ai/muggle-do/sessions"
|
|
33
|
+
local due_file slot_dir owner_json
|
|
34
|
+
for due_file in "$sessions_dir"/*/watch-due.env; do
|
|
35
|
+
[[ -s $due_file ]] || continue
|
|
36
|
+
slot_dir="${due_file%/watch-due.env}"
|
|
37
|
+
[[ $slot_dir == *.stopped ]] && continue
|
|
38
|
+
[[ -f $slot_dir/owner.json ]] || continue
|
|
39
|
+
owner_json=""
|
|
40
|
+
IFS= read -r -d '' owner_json <"$slot_dir/owner.json" || true
|
|
41
|
+
[[ $owner_json == *"\"$session_id\""* ]] && return 0
|
|
42
|
+
done
|
|
43
|
+
return 1
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
|
|
47
|
+
guardrail_run_standalone "$GUARDRAIL_SUBCOMMAND"
|
|
48
|
+
fi
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readFileSync, existsSync, readdirSync, mkdirSync, statSync, writeFileSync, renameSync,
|
|
1
|
+
import { readFileSync, existsSync, readdirSync, mkdirSync, openSync, fstatSync, readSync, closeSync, statSync, writeFileSync, renameSync, writeSync, unlinkSync } from 'fs';
|
|
2
2
|
import { join, basename, isAbsolute, resolve, dirname } from 'path';
|
|
3
3
|
import { homedir, hostname } from 'os';
|
|
4
4
|
import { execFileSync, spawn } from 'child_process';
|
|
@@ -34,6 +34,9 @@ var MAX_WATCH_BLOCKS = 3;
|
|
|
34
34
|
var WATCH_HEARTBEAT_STALE_MS = 15 * 6e4;
|
|
35
35
|
var TERMINAL_SLOT_PR_STATES = ["merged", "closed"];
|
|
36
36
|
var STOPPED_SLOT_SUFFIX = ".stopped";
|
|
37
|
+
var WATCH_HOLD_PHRASE_PREFIX = "HOLD WATCH #";
|
|
38
|
+
var WATCH_HOLD_INSTRUCTION = /HOLD WATCH #(\d+)\b/g;
|
|
39
|
+
var WATCH_HOLD_TRANSCRIPT_TAIL_BYTES = 4e6;
|
|
37
40
|
var MAX_BUILD_BLOCKS = 3;
|
|
38
41
|
var MAX_WALKTHROUGH_BLOCKS = 3;
|
|
39
42
|
var GH_LOOKUP_TIMEOUT_MS = 1e4;
|
|
@@ -370,6 +373,11 @@ function lastAssistantText(transcriptJsonl) {
|
|
|
370
373
|
}
|
|
371
374
|
return "";
|
|
372
375
|
}
|
|
376
|
+
function resolvePluginRoot(env = process.env) {
|
|
377
|
+
return env.CLAUDE_PLUGIN_ROOT || env.CURSOR_PLUGIN_ROOT || dirname(dirname(fileURLToPath(import.meta.url)));
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// src/guardrails/mandatoryStages.ts
|
|
373
381
|
var FRONTMATTER = /^---\r?\n([\s\S]*?)\r?\n---/;
|
|
374
382
|
var SEQUENCE_ENTRY = /^\s*-\s*(.+?)\s*$/;
|
|
375
383
|
var FLOW_LIST = /^\s*\[(.*)\]\s*$/;
|
|
@@ -413,9 +421,7 @@ function stageLabel(normalizedStagePath) {
|
|
|
413
421
|
return normalizedStagePath.slice(insideSkills + SKILLS_PATH_SEGMENT.length);
|
|
414
422
|
}
|
|
415
423
|
function resolvePluginSkillsRoot() {
|
|
416
|
-
|
|
417
|
-
if (pluginRoot) return join(pluginRoot, SKILLS_DIR_NAME);
|
|
418
|
-
return join(dirname(dirname(fileURLToPath(import.meta.url))), SKILLS_DIR_NAME);
|
|
424
|
+
return join(resolvePluginRoot(), SKILLS_DIR_NAME);
|
|
419
425
|
}
|
|
420
426
|
function resolveSkillNameFromToolInput(toolInput) {
|
|
421
427
|
if (!toolInput) return void 0;
|
|
@@ -916,6 +922,75 @@ function patchPrComment(pr, commentId, body, run) {
|
|
|
916
922
|
);
|
|
917
923
|
}
|
|
918
924
|
|
|
925
|
+
// src/pr-watch/constants.ts
|
|
926
|
+
var MUGGLE_DO_SESSIONS_PATH_SEGMENTS = [".muggle-ai", "muggle-do", "sessions"];
|
|
927
|
+
var PRS_FILE_NAME = "prs.json";
|
|
928
|
+
var OWNER_FILE_NAME = "owner.json";
|
|
929
|
+
var LAST_SEEN_FILE_NAME = "last_seen.json";
|
|
930
|
+
var RESULT_FILE_NAME = "result.md";
|
|
931
|
+
var WATCH_DUE_FILE_NAME = "watch-due.env";
|
|
932
|
+
var WATCH_DUE_HEAD_FIELD = "HEAD";
|
|
933
|
+
var WATCH_DUE_REBASE_FIELD = "REBASE_DUE";
|
|
934
|
+
var WATCH_DUE_CI_RED_FIELD = "CI_RED_HEAD";
|
|
935
|
+
var ENV_FILE_LINE = /^([A-Z_]+)="?([^"]*)"?$/;
|
|
936
|
+
var USER_PREFERENCES_PATH_SEGMENTS = [".muggle-ai", "preferences.json"];
|
|
937
|
+
var PREFERENCE_DEFAULTS_PATH_SEGMENTS = ["config", "preference-defaults.json"];
|
|
938
|
+
var AUTO_REBASE_PREFERENCE_KEY = "autoRebase";
|
|
939
|
+
var MAX_CATCH_UP_REBASES_PREFERENCE_KEY = "maxCatchUpRebases";
|
|
940
|
+
var ALWAYS_PREFERENCE_VALUE = "always";
|
|
941
|
+
var UNBOUNDED_PREFERENCE_VALUE = "never";
|
|
942
|
+
var POSITIVE_INTEGER = /^[1-9]\d*$/;
|
|
943
|
+
function readSlotText(filePath) {
|
|
944
|
+
try {
|
|
945
|
+
return readFileSync(filePath, "utf-8");
|
|
946
|
+
} catch {
|
|
947
|
+
return "";
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
function readSlotPr(slotPath) {
|
|
951
|
+
try {
|
|
952
|
+
const parsed = JSON.parse(readFileSync(join(slotPath, PRS_FILE_NAME), "utf-8"));
|
|
953
|
+
const slotPr = Array.isArray(parsed) ? parsed[0] : parsed;
|
|
954
|
+
return slotPr !== null && typeof slotPr === "object" ? slotPr : void 0;
|
|
955
|
+
} catch {
|
|
956
|
+
return void 0;
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
function readJsonRecord(filePath) {
|
|
960
|
+
try {
|
|
961
|
+
return asRecord(JSON.parse(readFileSync(filePath, "utf-8")));
|
|
962
|
+
} catch {
|
|
963
|
+
return {};
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
function asRecord(candidate) {
|
|
967
|
+
return candidate !== null && typeof candidate === "object" && !Array.isArray(candidate) ? candidate : {};
|
|
968
|
+
}
|
|
969
|
+
function lastSeenEntryFor(lastSeenJson, prKey) {
|
|
970
|
+
try {
|
|
971
|
+
return asRecord(asRecord(JSON.parse(lastSeenJson))[prKey]);
|
|
972
|
+
} catch {
|
|
973
|
+
return {};
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
function parseEnvFileLines(envFileText) {
|
|
977
|
+
const fields = {};
|
|
978
|
+
for (const rawLine of envFileText.split("\n")) {
|
|
979
|
+
const fieldMatch = ENV_FILE_LINE.exec(rawLine.replace(/\r$/, ""));
|
|
980
|
+
if (fieldMatch) fields[fieldMatch[1]] = fieldMatch[2];
|
|
981
|
+
}
|
|
982
|
+
return fields;
|
|
983
|
+
}
|
|
984
|
+
function parseWatchDueRecord(watchDueText) {
|
|
985
|
+
const fields = parseEnvFileLines(watchDueText);
|
|
986
|
+
const dueRecord = {
|
|
987
|
+
headSha: fields[WATCH_DUE_HEAD_FIELD] ?? "",
|
|
988
|
+
rebaseDueKey: fields[WATCH_DUE_REBASE_FIELD] ?? "",
|
|
989
|
+
ciRedHeadSha: fields[WATCH_DUE_CI_RED_FIELD] ?? ""
|
|
990
|
+
};
|
|
991
|
+
return dueRecord.rebaseDueKey || dueRecord.ciRedHeadSha ? dueRecord : null;
|
|
992
|
+
}
|
|
993
|
+
|
|
919
994
|
// src/guardrails/watchArmed.ts
|
|
920
995
|
var WATCH_SKIP_MARKER = /^\s*echo\s+["']?MUGGLE_WATCH_SKIP\b/;
|
|
921
996
|
function isWatchSkipMarker(cmd) {
|
|
@@ -943,7 +1018,7 @@ function readHeartbeatMtimeMs(slotPath) {
|
|
|
943
1018
|
}
|
|
944
1019
|
function findUnwatchedHandledPrs(handledUrls, sessionsDirOverride) {
|
|
945
1020
|
if (handledUrls.length === 0) return [];
|
|
946
|
-
const sessionsDir = join(homedir(),
|
|
1021
|
+
const sessionsDir = join(homedir(), ...MUGGLE_DO_SESSIONS_PATH_SEGMENTS);
|
|
947
1022
|
let slugs;
|
|
948
1023
|
try {
|
|
949
1024
|
slugs = readdirSync(sessionsDir);
|
|
@@ -954,18 +1029,12 @@ function findUnwatchedHandledPrs(handledUrls, sessionsDirOverride) {
|
|
|
954
1029
|
const watchedUrls = /* @__PURE__ */ new Set();
|
|
955
1030
|
for (const slug of slugs) {
|
|
956
1031
|
const slotPath = join(sessionsDir, slug);
|
|
957
|
-
|
|
958
|
-
try {
|
|
959
|
-
const parsed = JSON.parse(readFileSync(join(slotPath, "prs.json"), "utf-8"));
|
|
960
|
-
slotPr = Array.isArray(parsed) ? parsed[0] : parsed;
|
|
961
|
-
} catch {
|
|
962
|
-
continue;
|
|
963
|
-
}
|
|
1032
|
+
const slotPr = readSlotPr(slotPath);
|
|
964
1033
|
const slotUrl = slotPr?.url;
|
|
965
1034
|
if (typeof slotUrl !== "string" || !handledUrls.includes(slotUrl)) continue;
|
|
966
1035
|
const evidence = {
|
|
967
1036
|
isStopped: slug.endsWith(STOPPED_SLOT_SUFFIX),
|
|
968
|
-
isFinalized: existsSync(join(slotPath,
|
|
1037
|
+
isFinalized: existsSync(join(slotPath, RESULT_FILE_NAME)),
|
|
969
1038
|
recordedPrState: typeof slotPr?.state === "string" ? slotPr.state : void 0,
|
|
970
1039
|
heartbeatMtimeMs: readHeartbeatMtimeMs(slotPath)
|
|
971
1040
|
};
|
|
@@ -1023,6 +1092,166 @@ function watchGateDecision(state, unwatchedPrUrls, maxBlocks = MAX_WATCH_BLOCKS)
|
|
|
1023
1092
|
};
|
|
1024
1093
|
}
|
|
1025
1094
|
|
|
1095
|
+
// src/pr-watch/attempts.ts
|
|
1096
|
+
function recordedCount(counts, key) {
|
|
1097
|
+
const recorded = counts?.[key];
|
|
1098
|
+
return typeof recorded === "number" && Number.isFinite(recorded) ? recorded : 0;
|
|
1099
|
+
}
|
|
1100
|
+
function rebaseAttemptsFor(lastSeenEntry, rebaseKey) {
|
|
1101
|
+
return recordedCount(lastSeenEntry.conflict_resolve_attempts, rebaseKey);
|
|
1102
|
+
}
|
|
1103
|
+
function ciFixAttemptsFor(lastSeenEntry, headSha) {
|
|
1104
|
+
return recordedCount(lastSeenEntry.ci_fix_attempts, headSha);
|
|
1105
|
+
}
|
|
1106
|
+
function isRebaseKeyAttempted(lastSeenEntry, rebaseKey) {
|
|
1107
|
+
return rebaseAttemptsFor(lastSeenEntry, rebaseKey) >= 1;
|
|
1108
|
+
}
|
|
1109
|
+
function isCiHeadAttempted(lastSeenEntry, headSha) {
|
|
1110
|
+
return ciFixAttemptsFor(lastSeenEntry, headSha) >= 1;
|
|
1111
|
+
}
|
|
1112
|
+
function isRebaseBudgetExhausted(lastSeenEntry, maxCatchUpRebases) {
|
|
1113
|
+
const catchUpRebases = lastSeenEntry.catch_up_rebases;
|
|
1114
|
+
return maxCatchUpRebases !== null && typeof catchUpRebases === "number" && catchUpRebases >= maxCatchUpRebases;
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
// src/transcript/constants.ts
|
|
1118
|
+
var USER_ENTRY_TYPE = "user";
|
|
1119
|
+
var HUMAN_ORIGIN_KIND = "human";
|
|
1120
|
+
var TEXT_CONTENT_PART_TYPE = "text";
|
|
1121
|
+
var TOOL_RESULT_CONTENT_PART_TYPE = "tool_result";
|
|
1122
|
+
|
|
1123
|
+
// src/transcript/userTurns.ts
|
|
1124
|
+
function userAuthoredText(entry) {
|
|
1125
|
+
if (entry.type !== USER_ENTRY_TYPE) return null;
|
|
1126
|
+
if (entry.isMeta || entry.isCompactSummary || entry.isSidechain || entry.toolUseResult !== void 0) return null;
|
|
1127
|
+
if (entry.origin != null && entry.origin.kind !== HUMAN_ORIGIN_KIND) return null;
|
|
1128
|
+
const content = entry.message?.content;
|
|
1129
|
+
if (typeof content === "string") return content;
|
|
1130
|
+
if (!Array.isArray(content)) return null;
|
|
1131
|
+
const parts = content;
|
|
1132
|
+
if (parts.some((part) => part?.type === TOOL_RESULT_CONTENT_PART_TYPE)) return null;
|
|
1133
|
+
return parts.filter((part) => part?.type === TEXT_CONTENT_PART_TYPE && typeof part.text === "string").map((part) => part.text).join("\n");
|
|
1134
|
+
}
|
|
1135
|
+
function userAuthoredTextsContaining(transcriptJsonl, literal) {
|
|
1136
|
+
const texts = [];
|
|
1137
|
+
for (const line of transcriptJsonl.split("\n")) {
|
|
1138
|
+
if (!line.includes(literal)) continue;
|
|
1139
|
+
let entry;
|
|
1140
|
+
try {
|
|
1141
|
+
entry = JSON.parse(line);
|
|
1142
|
+
} catch {
|
|
1143
|
+
continue;
|
|
1144
|
+
}
|
|
1145
|
+
const text = userAuthoredText(entry);
|
|
1146
|
+
if (text !== null && text.includes(literal)) texts.push(text);
|
|
1147
|
+
}
|
|
1148
|
+
return texts;
|
|
1149
|
+
}
|
|
1150
|
+
function readFileTail(filePath, maxBytes) {
|
|
1151
|
+
let descriptor;
|
|
1152
|
+
try {
|
|
1153
|
+
descriptor = openSync(filePath, "r");
|
|
1154
|
+
const fileSize = fstatSync(descriptor).size;
|
|
1155
|
+
const length = Math.min(fileSize, maxBytes);
|
|
1156
|
+
const tail = Buffer.alloc(length);
|
|
1157
|
+
readSync(descriptor, tail, 0, length, fileSize - length);
|
|
1158
|
+
return tail.toString("utf-8");
|
|
1159
|
+
} catch {
|
|
1160
|
+
return null;
|
|
1161
|
+
} finally {
|
|
1162
|
+
if (descriptor !== void 0) closeSync(descriptor);
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
// src/guardrails/watchFollowThrough.ts
|
|
1167
|
+
function mtimeMsOf(filePath) {
|
|
1168
|
+
try {
|
|
1169
|
+
return statSync(filePath).mtimeMs;
|
|
1170
|
+
} catch {
|
|
1171
|
+
return void 0;
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
function isDueRecordSuperseded(slotPath, slotPr, dueRecord) {
|
|
1175
|
+
if (!slotPr.head_sha || slotPr.head_sha === dueRecord.headSha) return false;
|
|
1176
|
+
const prsWrittenAtMs = mtimeMsOf(join(slotPath, PRS_FILE_NAME));
|
|
1177
|
+
const dueWrittenAtMs = mtimeMsOf(join(slotPath, WATCH_DUE_FILE_NAME));
|
|
1178
|
+
return prsWrittenAtMs !== void 0 && dueWrittenAtMs !== void 0 && prsWrittenAtMs > dueWrittenAtMs;
|
|
1179
|
+
}
|
|
1180
|
+
function owedWorkInSlot(slotPath, slug, sessionId2, preferences) {
|
|
1181
|
+
if (slug.endsWith(STOPPED_SLOT_SUFFIX)) return [];
|
|
1182
|
+
const dueRecord = parseWatchDueRecord(readSlotText(join(slotPath, WATCH_DUE_FILE_NAME)));
|
|
1183
|
+
if (!dueRecord) return [];
|
|
1184
|
+
if (readJsonRecord(join(slotPath, OWNER_FILE_NAME)).session_id !== sessionId2) return [];
|
|
1185
|
+
if (existsSync(join(slotPath, RESULT_FILE_NAME))) return [];
|
|
1186
|
+
const slotPr = readSlotPr(slotPath);
|
|
1187
|
+
const prUrl = slotPr?.url;
|
|
1188
|
+
const prNumber = slotPr?.number;
|
|
1189
|
+
if (!slotPr?.repo || typeof prUrl !== "string" || typeof prNumber !== "number") return [];
|
|
1190
|
+
if (TERMINAL_SLOT_PR_STATES.includes((slotPr.state ?? "").toLowerCase())) return [];
|
|
1191
|
+
if (isDueRecordSuperseded(slotPath, slotPr, dueRecord)) return [];
|
|
1192
|
+
const lastSeenEntry = lastSeenEntryFor(readSlotText(join(slotPath, LAST_SEEN_FILE_NAME)), `${slotPr.repo}#${prNumber}`);
|
|
1193
|
+
const workOn = (kind, dueOn) => ({
|
|
1194
|
+
kind,
|
|
1195
|
+
slug,
|
|
1196
|
+
prUrl,
|
|
1197
|
+
prNumber,
|
|
1198
|
+
dueOn
|
|
1199
|
+
});
|
|
1200
|
+
const owed = [];
|
|
1201
|
+
const isRebaseOwed = dueRecord.rebaseDueKey !== "" && preferences.autoRebase === ALWAYS_PREFERENCE_VALUE && !isRebaseBudgetExhausted(lastSeenEntry, preferences.maxCatchUpRebases) && !isRebaseKeyAttempted(lastSeenEntry, dueRecord.rebaseDueKey);
|
|
1202
|
+
if (isRebaseOwed) owed.push(workOn("rebase" /* Rebase */, dueRecord.rebaseDueKey));
|
|
1203
|
+
if (dueRecord.ciRedHeadSha !== "" && !isCiHeadAttempted(lastSeenEntry, dueRecord.ciRedHeadSha)) {
|
|
1204
|
+
owed.push(workOn("fix-ci" /* FixCi */, dueRecord.ciRedHeadSha));
|
|
1205
|
+
}
|
|
1206
|
+
return owed;
|
|
1207
|
+
}
|
|
1208
|
+
function findOwedWatchWork(sessionId2, preferences, sessionsDirOverride) {
|
|
1209
|
+
const sessionsDir = join(homedir(), ...MUGGLE_DO_SESSIONS_PATH_SEGMENTS);
|
|
1210
|
+
let slugs;
|
|
1211
|
+
try {
|
|
1212
|
+
slugs = readdirSync(sessionsDir);
|
|
1213
|
+
} catch {
|
|
1214
|
+
return [];
|
|
1215
|
+
}
|
|
1216
|
+
return slugs.flatMap((slug) => owedWorkInSlot(join(sessionsDir, slug), slug, sessionId2, preferences));
|
|
1217
|
+
}
|
|
1218
|
+
function heldPrNumbersIn(transcriptJsonl) {
|
|
1219
|
+
const heldPrNumbers = /* @__PURE__ */ new Set();
|
|
1220
|
+
for (const userText of userAuthoredTextsContaining(transcriptJsonl, WATCH_HOLD_PHRASE_PREFIX)) {
|
|
1221
|
+
for (const hold of userText.matchAll(WATCH_HOLD_INSTRUCTION)) heldPrNumbers.add(Number(hold[1]));
|
|
1222
|
+
}
|
|
1223
|
+
return [...heldPrNumbers];
|
|
1224
|
+
}
|
|
1225
|
+
function applyWatchHolds(state, heldPrNumbers) {
|
|
1226
|
+
const recorded = state.watchHeldPrNumbers ?? [];
|
|
1227
|
+
const newlyHeld = heldPrNumbers.filter((prNumber) => !recorded.includes(prNumber));
|
|
1228
|
+
if (newlyHeld.length === 0) return state;
|
|
1229
|
+
return { ...state, watchHeldPrNumbers: [...recorded, ...newlyHeld] };
|
|
1230
|
+
}
|
|
1231
|
+
function watchFollowThroughDecision(state, owedWork) {
|
|
1232
|
+
const heldPrNumbers = state.watchHeldPrNumbers ?? [];
|
|
1233
|
+
const owed = owedWork.filter((work) => !heldPrNumbers.includes(work.prNumber));
|
|
1234
|
+
const blockCount = state.watchFollowThroughBlockCount ?? 0;
|
|
1235
|
+
if (owed.length === 0) return { action: "none" /* None */, blockCount, owed };
|
|
1236
|
+
return { action: "block" /* Block */, blockCount: blockCount + 1, owed };
|
|
1237
|
+
}
|
|
1238
|
+
function parseMaxCatchUpRebases(configuredValue) {
|
|
1239
|
+
if (configuredValue === UNBOUNDED_PREFERENCE_VALUE) return null;
|
|
1240
|
+
const spelled = typeof configuredValue === "number" ? String(configuredValue) : configuredValue;
|
|
1241
|
+
return typeof spelled === "string" && POSITIVE_INTEGER.test(spelled) ? Number(spelled) : void 0;
|
|
1242
|
+
}
|
|
1243
|
+
function resolveWatchPreferences(homeDir = homedir(), pluginRoot = resolvePluginRoot()) {
|
|
1244
|
+
const shippedDefaults = readJsonRecord(join(pluginRoot, ...PREFERENCE_DEFAULTS_PATH_SEGMENTS));
|
|
1245
|
+
const userPreferences = asRecord(readJsonRecord(join(homeDir, ...USER_PREFERENCES_PATH_SEGMENTS)).preferences);
|
|
1246
|
+
const autoRebase = userPreferences[AUTO_REBASE_PREFERENCE_KEY] ?? shippedDefaults[AUTO_REBASE_PREFERENCE_KEY];
|
|
1247
|
+
const userCap = parseMaxCatchUpRebases(userPreferences[MAX_CATCH_UP_REBASES_PREFERENCE_KEY]);
|
|
1248
|
+
const shippedCap = parseMaxCatchUpRebases(shippedDefaults[MAX_CATCH_UP_REBASES_PREFERENCE_KEY]);
|
|
1249
|
+
return {
|
|
1250
|
+
autoRebase: typeof autoRebase === "string" ? autoRebase : void 0,
|
|
1251
|
+
maxCatchUpRebases: userCap !== void 0 ? userCap : shippedCap ?? null
|
|
1252
|
+
};
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1026
1255
|
// src/guardrails/buildFollowthrough.ts
|
|
1027
1256
|
var BUILD_SKIP_MARKER = /^\s*echo\s+["']?MUGGLE_BUILD_SKIP\b/;
|
|
1028
1257
|
function isBuildSkipMarker(cmd) {
|
|
@@ -1397,17 +1626,7 @@ var verifyUserWaived = (context) => {
|
|
|
1397
1626
|
const transcript = context.probe.readTextFile(context.transcriptPath);
|
|
1398
1627
|
if (!transcript) return refuted("the transcript could not be read");
|
|
1399
1628
|
const tail = transcript.slice(-64e3);
|
|
1400
|
-
|
|
1401
|
-
if (!line.includes(USER_WAIVE_PHRASE)) return false;
|
|
1402
|
-
try {
|
|
1403
|
-
const entry = JSON.parse(line);
|
|
1404
|
-
const isUserTurn = entry.type === "user" || entry.message?.role === "user";
|
|
1405
|
-
return isUserTurn && JSON.stringify(entry.message?.content ?? "").includes(USER_WAIVE_PHRASE);
|
|
1406
|
-
} catch {
|
|
1407
|
-
return false;
|
|
1408
|
-
}
|
|
1409
|
-
});
|
|
1410
|
-
if (waived) return verified;
|
|
1629
|
+
if (userAuthoredTextsContaining(tail, USER_WAIVE_PHRASE).length > 0) return verified;
|
|
1411
1630
|
return refuted(`no user turn in the transcript contains "${USER_WAIVE_PHRASE}"`);
|
|
1412
1631
|
};
|
|
1413
1632
|
var namePaths = (paths) => {
|
|
@@ -1757,17 +1976,11 @@ function threadForReplyTarget(ledger, targetId) {
|
|
|
1757
1976
|
return void 0;
|
|
1758
1977
|
}
|
|
1759
1978
|
function resolveSlotForPr(prUrl, sessionsDirOverride) {
|
|
1760
|
-
const sessionsDir = join(homedir(),
|
|
1979
|
+
const sessionsDir = join(homedir(), ...MUGGLE_DO_SESSIONS_PATH_SEGMENTS);
|
|
1761
1980
|
if (!existsSync(sessionsDir)) return void 0;
|
|
1762
1981
|
for (const slug of readdirSync(sessionsDir)) {
|
|
1763
1982
|
const slotPath = join(sessionsDir, slug);
|
|
1764
|
-
|
|
1765
|
-
const parsed = JSON.parse(readFileSync(join(slotPath, "prs.json"), "utf-8"));
|
|
1766
|
-
const slotPr = Array.isArray(parsed) ? parsed[0] : parsed;
|
|
1767
|
-
if (slotPr?.url === prUrl) return slotPath;
|
|
1768
|
-
} catch {
|
|
1769
|
-
continue;
|
|
1770
|
-
}
|
|
1983
|
+
if (readSlotPr(slotPath)?.url === prUrl) return slotPath;
|
|
1771
1984
|
}
|
|
1772
1985
|
return void 0;
|
|
1773
1986
|
}
|
|
@@ -2156,6 +2369,42 @@ function watchGate() {
|
|
|
2156
2369
|
const reason = decision.blockCount === 1 ? `Do not end the turn yet. A PR opened this session is open with no live muggle-pr-followup watch: ${prList}. Arm its watch per the muggle-pr-followup arming procedure (arm-watcher.md) \u2014 invoking ${armCommand} bootstraps it and arms it that way (add --resume when its slot already exists). A seeded slot does not count: only a running watch loop does, shown by a watch-heartbeat it touches every poll and that goes stale after ${staleMinutes} minutes (a watch armed moments ago writes it on its first poll). If the PR already merged or closed, end the turn again \u2014 a provider check started now clears it. If it genuinely should not be watched (autoWatchPR=never, handed off elsewhere), tell the user why and run \`echo "MUGGLE_WATCH_SKIP: <reason>"\` \u2014 that records the skip and keeps this gate quiet for the rest of the session.` : `PR watch still owed for ${prList} (reminder ${decision.blockCount}/${MAX_WATCH_BLOCKS}): arm it per arm-watcher.md via ${armCommand} (--resume when its slot exists), or record a legitimate skip via \`echo "MUGGLE_WATCH_SKIP: <reason>"\`.`;
|
|
2157
2370
|
return blockStop(reason, host);
|
|
2158
2371
|
}
|
|
2372
|
+
function owedWatchWorkLine(work) {
|
|
2373
|
+
const muggleDo = muggleSkill("/muggle-do");
|
|
2374
|
+
if (work.kind === "rebase" /* Rebase */) {
|
|
2375
|
+
return `- PR #${work.prNumber} (${work.prUrl}) is behind or conflicting with its base (key ${work.dueOn}) and no rebase was attempted: dispatch \`${muggleDo} rebase on ${work.prUrl} slug=${work.slug}\`.`;
|
|
2376
|
+
}
|
|
2377
|
+
return `- PR #${work.prNumber} (${work.prUrl}) has red CI on head ${work.dueOn.slice(0, 8)} and no fix was attempted: dispatch \`${muggleDo} fix ci <red checks> on ${work.prUrl} slug=${work.slug}\` \u2014 the tick \`${muggleSkill("/muggle:muggle-pr-followup")} ${work.slug} ${work.prNumber} --wake=follow-through\` names the checks.`;
|
|
2378
|
+
}
|
|
2379
|
+
function watchFollowThroughGate() {
|
|
2380
|
+
const owedWork = findOwedWatchWork(sessionId, resolveWatchPreferences());
|
|
2381
|
+
const stateBefore = readState(sessionId);
|
|
2382
|
+
const transcriptTail = watchFollowThroughDecision(stateBefore, owedWork).action === "block" /* Block */ && input.transcript_path ? readFileTail(input.transcript_path, WATCH_HOLD_TRANSCRIPT_TAIL_BYTES) : null;
|
|
2383
|
+
const heldPrNumbers = transcriptTail ? heldPrNumbersIn(transcriptTail) : [];
|
|
2384
|
+
const state = applyWatchHolds(stateBefore, heldPrNumbers);
|
|
2385
|
+
const decision = watchFollowThroughDecision(state, owedWork);
|
|
2386
|
+
if (decision.action === "none" /* None */) {
|
|
2387
|
+
if (state !== stateBefore || (state.watchFollowThroughBlockCount ?? 0) > 0) {
|
|
2388
|
+
updateState(sessionId, (current) => ({
|
|
2389
|
+
...applyWatchHolds(current, heldPrNumbers),
|
|
2390
|
+
watchFollowThroughBlockCount: 0
|
|
2391
|
+
}));
|
|
2392
|
+
}
|
|
2393
|
+
return "{}";
|
|
2394
|
+
}
|
|
2395
|
+
updateState(sessionId, (current) => ({
|
|
2396
|
+
...applyWatchHolds(current, heldPrNumbers),
|
|
2397
|
+
watchFollowThroughBlockCount: decision.blockCount
|
|
2398
|
+
}));
|
|
2399
|
+
const owedList = decision.owed.map(owedWatchWorkLine).join("\n");
|
|
2400
|
+
const holdInstruction = `Only the user can hold it: their own message containing \`${WATCH_HOLD_PHRASE_PREFIX}<pr-number>\` for that PR. Ask if you must; never decide it for them.`;
|
|
2401
|
+
const reason = decision.blockCount === 1 ? `Do not end the turn yet. A muggle-pr-followup watch this session owns found work due that nothing acted on:
|
|
2402
|
+
${owedList}
|
|
2403
|
+
autoRebase=always makes a due rebase binding, and how long a CI run or an eval takes is never a reason to wait. Act now \u2014 if the tick finds actionable review feedback it dispatches that first. A recorded attempt (conflict_resolve_attempts / ci_fix_attempts) or a new head clears this; an escalation entry with no attempt behind it does not, and neither does re-arming the watch. ${holdInstruction}` : `Watcher work still owed (reminder ${decision.blockCount}):
|
|
2404
|
+
${owedList}
|
|
2405
|
+
${holdInstruction}`;
|
|
2406
|
+
return blockStop(reason, host);
|
|
2407
|
+
}
|
|
2159
2408
|
function buildFollowthroughGate() {
|
|
2160
2409
|
const state = readState(sessionId);
|
|
2161
2410
|
const decision = buildFollowthroughDecision(state);
|
|
@@ -2319,6 +2568,7 @@ var handlers = {
|
|
|
2319
2568
|
"e2e-gate": e2eGate,
|
|
2320
2569
|
"terminal-gate": terminalGate,
|
|
2321
2570
|
"watch-gate": watchGate,
|
|
2571
|
+
"watch-follow-through-gate": watchFollowThroughGate,
|
|
2322
2572
|
"build-followthrough-gate": buildFollowthroughGate,
|
|
2323
2573
|
"walkthrough-gate": walkthroughGate,
|
|
2324
2574
|
"record-comment-replies": recordCommentReplies,
|