@muggleai/works 5.25.0-staging.188 → 5.25.0-staging.190
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/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 +9 -8
- package/dist/plugin/hooks/codex-hooks.json +2 -2
- package/dist/plugin/hooks/hooks.json +24 -13
- package/dist/plugin/scripts/guardrail-build-router.sh +8 -1
- package/dist/plugin/scripts/guardrail-lib.sh +28 -0
- package/dist/plugin/scripts/guardrail-pr-terminal.sh +3 -3
- package/dist/plugin/scripts/guardrail-record-stage-read.sh +5 -2
- package/dist/plugin/scripts/guardrail-record-tests.sh +6 -1
- package/dist/plugin/scripts/reconcile-stale-watchers.sh +28 -10
- 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 +9 -8
- package/plugin/hooks/codex-hooks.json +2 -2
- package/plugin/hooks/hooks.json +24 -13
- package/plugin/scripts/guardrail-build-router.sh +8 -1
- package/plugin/scripts/guardrail-lib.sh +28 -0
- package/plugin/scripts/guardrail-pr-terminal.sh +3 -3
- package/plugin/scripts/guardrail-record-stage-read.sh +5 -2
- package/plugin/scripts/guardrail-record-tests.sh +6 -1
- package/plugin/scripts/reconcile-stale-watchers.sh +28 -10
|
@@ -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.25.0-staging.
|
|
12
|
+
"version": "5.25.0-staging.190"
|
|
13
13
|
}
|
|
14
14
|
]
|
|
15
15
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "muggle",
|
|
3
3
|
"description": "Real-browser E2E acceptance for your coding agent: test the flows you changed and open the PR with screenshots. Built for flows other tools can't reach: managed test identities with live inboxes (magic links, email OTP and 2FA, verification mail, password resets), an encrypted secret store for login and test credentials, and a test graph that runs prerequisite flows first. Plain-English tests become replayable scripts on localhost or preview URLs.",
|
|
4
|
-
"version": "5.25.0-staging.
|
|
4
|
+
"version": "5.25.0-staging.190",
|
|
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.25.0-staging.
|
|
3
|
+
"version": "5.25.0-staging.190",
|
|
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.25.0-staging.
|
|
5
|
+
"version": "5.25.0-staging.190",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Muggle AI",
|
|
8
8
|
"email": "support@muggle-ai.com"
|
package/dist/plugin/.mcp.json
CHANGED
|
@@ -28,7 +28,7 @@ A recorder that *clears* an obligation — a walkthrough posted, a failure diagn
|
|
|
28
28
|
|
|
29
29
|
Each guardrail is a bash gate script in `../scripts/` holding a `guardrail_wants` pre-filter and the `guardrails.mjs` subcommand it feeds; the bundled `../scripts/guardrails.mjs` holds the decision logic (built from `src/guardrails/`, vitest-covered). The busy events — a shell command before and after it runs, and every turn end — register one `guardrail-dispatch.sh` command listing their gates, which reads the payload once, asks every gate's pre-filter in that one process, and starts Node once (`guardrails.mjs run <gates...>`) for just the gates that could fire, merging their responses. Rarer events call a gate script directly. Per-session state in `~/.muggle-ai/guardrails/<session_id>.json` tracks what fired. Any *failure* degrades to `{}` (allow) — a gate blocks only by an explicit, tested decision, never by accident; `guardrail-lib.sh` is the one place that falls back, and `run` isolates gates from each other.
|
|
30
30
|
|
|
31
|
-
Pre-filters are bash builtins only (`guardrail-lib.sh`), so an irrelevant event starts no process at all. A gate that has spent its block budget stamps a `<gate>Released` flag, which its wrapper then pre-filters on — without it a released gate keeps cold-starting Node on every remaining turn end to answer `{}`, and the walkthrough gate keeps queuing provider scans to do it. That pre-filter is a second, looser copy of what `guardrails.mjs` matches, and it is the one place a guardrail can fail *silently*: a payload it drops — a skip marker, a reopen line, a comment edit — reaches no recorder, and the gate keeps demanding an action the user already took. Over-matching is free; under-matching is a dead escape hatch. `src/test/guardrails/hook-prefilter.test.ts` pins every payload each subcommand acts on against the wrapper guarding it, and derives the skip-marker tokens from source so a new marker is covered the moment it exists.
|
|
31
|
+
Pre-filters are bash builtins only (`guardrail-lib.sh`), so an irrelevant event starts no process at all. A pre-filter reads only the payload fields its subcommand judges (`guardrail_fields_match`: the command, the tool's name, the path read, the prompt), never the whole payload — a tool's output or a read file's contents would otherwise start Node whenever they merely mention a trigger. The PreToolUse deny gates go one step further: Claude Code's `if` rules (`Bash(*gh *)`, `Bash(*glab *)` and their `PowerShell` twins) launch them only for a command naming `gh` or `glab`, so every other shell call starts no hook process. A rule's leading `*` is load-bearing: it is what reaches a `gh` inside `bash -c "…"`. A gate that has spent its block budget stamps a `<gate>Released` flag, which its wrapper then pre-filters on — without it a released gate keeps cold-starting Node on every remaining turn end to answer `{}`, and the walkthrough gate keeps queuing provider scans to do it. That pre-filter is a second, looser copy of what `guardrails.mjs` matches, and it is the one place a guardrail can fail *silently*: a payload it drops — a skip marker, a reopen line, a comment edit — reaches no recorder, and the gate keeps demanding an action the user already took. Over-matching is free; under-matching is a dead escape hatch. `src/test/guardrails/hook-prefilter.test.ts` pins every payload each subcommand acts on against the wrapper guarding it, and derives the skip-marker tokens from source so a new marker is covered the moment it exists.
|
|
32
32
|
|
|
33
33
|
## Guardrails
|
|
34
34
|
|
|
@@ -36,13 +36,13 @@ Pre-filters are bash builtins only (`guardrail-lib.sh`), so an irrelevant event
|
|
|
36
36
|
| :--------- | :------ | :------- | :-------- | :--------- | :----- |
|
|
37
37
|
| `PostToolUse` (Bash) | `guardrail-pr-opened.sh` | advise | a `gh pr create`/`gh pr ready` just succeeded | `autoWatchPR` | start a `muggle-pr-followup` watcher on the new PR |
|
|
38
38
|
| `PostToolUse` (Bash + muggle execute/replay/skill-emit MCP tools) | `guardrail-record-tests.sh` | record | a unit-test command passed, an E2E run happened (execute/replay call, or the muggle-test skill's own telemetry emit — which registers a clean SKIP verdict too), or an `echo "MUGGLE_E2E_SKIP: <reason>"` marker declared E2E un-runnable, or a walkthrough carrying the `build-pr-section` sentinel was posted / declared un-postable via `echo "MUGGLE_WALKTHROUGH_SKIP: <reason>"` | — | set `unitTestsGreen` / `e2eRun` / `e2eSkipped` / `walkthroughPosted` / `walkthroughSkipped` session state |
|
|
39
|
-
| `PostToolUse` (Bash
|
|
39
|
+
| `PostToolUse` (Bash) | `guardrail-pr-terminal.sh` | advise | a PR just went terminal — a `gh pr merge`/`gh pr close` success line or the `TERMINAL pr=N` line the watch scripts print in a shell result (never bare `"state":"MERGED"` metadata). Not registered on `Monitor`: a Monitor call returns before its script prints anything, so its result never carries that line | — | record `terminalPending`, direct the post-merge handoff: finalize the watcher slot, tear down per `autoCleanup`, offer next options via AskUserQuestion |
|
|
40
40
|
| `PostToolUse` (AskUserQuestion) | `guardrail-offer-ran.sh` | record | a next-options offer ran while a terminal PR was pending | — | clear `terminalPending` — the only exit for the post-merge Stop gate |
|
|
41
41
|
| `PostToolUse` (Skill + muggle telemetry-skill-emit) | `guardrail-skill-stages.sh` | advise | a skill this plugin ships was invoked; its `SKILL.md` frontmatter may declare `mandatoryStages`. Registered on the skill's own MCP announcement too, so the declaration still lands if the Skill payload ever stops carrying a name | — | record `lastInvokedSkillName` + `mandatoryStages`, and name the declared files as required reading at the moment of use |
|
|
42
42
|
| `PostToolUse` (Read) | `guardrail-record-stage-read.sh` | record | a markdown file under a `skills/` directory was opened | — | append to `stagesRead` — how the stage gate tells a stage that was read from one that was skipped |
|
|
43
43
|
| `PostToolUse` (Bash + muggle telemetry-event-emit / user-feedback-create) | `guardrail-record-stage-signals.sh` | record | a Step 6f `pre-execution-classification` emit, debug-path evidence for a failed run (a `*-failure-classified\|resolved` emit or feedback naming it), or a `MUGGLE_STAGE_SKIP` / `MUGGLE_CLASSIFY_SKIP` / `MUGGLE_DEBUG_SKIP` marker | — | set `classifiedTestCaseIds` / `debuggedRuns` / the matching skip flag |
|
|
44
44
|
| `PostToolUse` (Bash) | `guardrail-record-comment-replies.sh` | record | an unresolved-thread fetch named review threads still awaiting an answer (classified by the `<!-- muggle-do:bot -->` marker, never the author login), a threaded reply the provider **confirmed** answered comments in one, or a `MUGGLE_REPLY_SKIP` marker deferred them | — | claim each thread and cover the comments answered, in the per-PR ledger beside the muggle-do slot |
|
|
45
|
-
| `PreToolUse` (Bash) | `guardrail-report-format.sh` | **enforce** | a `gh pr comment\|create\|edit` body — or a `gh api … issues/comments/<id>` PATCH editing one — reads like an E2E report but lacks the `build-pr-section` sentinel | — | **deny** — render via `muggle build-pr-section` instead |
|
|
45
|
+
| `PreToolUse` (Bash, `if` a command names `gh`/`glab`) | `guardrail-report-format.sh` | **enforce** | a `gh pr comment\|create\|edit` body — or a `gh api … issues/comments/<id>` PATCH editing one — reads like an E2E report but lacks the `build-pr-section` sentinel | — | **deny** — render via `muggle build-pr-section` instead |
|
|
46
46
|
| `PreToolUse` (muggle local execute/replay) | `guardrail-classify-gate.sh` | **enforce** | `muggle-test` is the skill in play and the target test case has no `pre-execution-classification` this session | — | **deny** — run Step 6f first (it calls `muggle-remote-test-script-list`, which is where the run learns the case has never passed) or record a legitimate skip via `MUGGLE_CLASSIFY_SKIP`. Scoped to `muggle-test`, so the single-target skills that legitimately skip classification are untouched; fails open when the test case can't be resolved |
|
|
47
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) |
|
|
@@ -56,11 +56,12 @@ Pre-filters are bash builtins only (`guardrail-lib.sh`), so an irrelevant event
|
|
|
56
56
|
|
|
57
57
|
## Codex
|
|
58
58
|
|
|
59
|
-
Codex runs Claude Code-format plugin hooks, from `codex-hooks.json` rather than `hooks.json` — the Codex plugin manifest (`../.codex-plugin/plugin.json`) names it. `scripts/build-codex-hooks.mjs` generates it from `hooks.json` on every build, and `pnpm run verify:plugin` fails when the committed copy drifts, so `hooks.json` stays the one manifest to edit. The generated copy differs in
|
|
59
|
+
Codex runs Claude Code-format plugin hooks, from `codex-hooks.json` rather than `hooks.json` — the Codex plugin manifest (`../.codex-plugin/plugin.json`) names it. `scripts/build-codex-hooks.mjs` generates it from `hooks.json` on every build, and `pnpm run verify:plugin` fails when the committed copy drifts, so `hooks.json` stays the one manifest to edit. The generated copy differs in four ways, each written down rather than guessed at runtime:
|
|
60
60
|
|
|
61
61
|
- **Host stamp.** Codex exports `CLAUDE_PLUGIN_ROOT` to plugin hooks for compatibility, so nothing in the environment tells a guardrail it is not in Claude Code. Every command runs under `env MUGGLE_HOOK_HOST=codex`, and the guardrails word their instructions for Codex (`$muggle:muggle-test`, not `/muggle:muggle-test`).
|
|
62
62
|
- **Tool names.** A matcher naming a Claude Code tool becomes the Codex tool that plays its part — `AskUserQuestion` → `request_user_input` — and a group whose tools Codex lacks is dropped: Codex reports every shell call as `Bash`, opens files and skills through the shell, and delivers a background command's output as that command's own `Bash` event, so `PowerShell`, `Read`, `Skill` and `Monitor` never fire. An MCP tool reaches a Codex hook as `mcp__muggle__<tool>` with every character outside `[A-Za-z0-9_]` turned into `_` (`mcp__muggle__muggle_local_execute_replay`), so the MCP matchers are respelled; the wrappers' pre-filters and the guardrails' own tool checks accept either spelling.
|
|
63
63
|
- **Windows.** Codex runs `commandWindows` through the session shell — PowerShell, or cmd.exe as a fallback — so every hook also gets one that starts with a bare `node` (both shells parse it alike; a quoted path there is a PowerShell syntax error) and hands the same script to Git Bash through `../scripts/codex-hook-windows.mjs`. It looks for Git Bash beside `git.exe`, then in the default install paths; `MUGGLE_HOOK_BASH` names one it would not find. With no Git Bash the launcher prints `{}` and succeeds — the same allow-by-default every guardrail falls back to.
|
|
64
|
+
- **No `if` rules.** Codex has no counterpart to Claude Code's `if`, so the rule is dropped and the identical commands its variants leave collapse into one: under Codex the deny gates run on every shell call and their in-shell pre-filters decide.
|
|
64
65
|
|
|
65
66
|
What Codex sends differs too, and the guardrails read either shape: a shell result arrives as the bare output string (normalized to `tool_response.output` in `hookInput.ts`), with no exit code; the Stop payload carries the closing message as `last_assistant_message`, which the capability-claim gate judges in place of the transcript, whose format is not Claude Code's; and a stage file opened with `cat` or `sed -n` counts as read, since there is no `Read` tool. With no structured question in Codex's default mode, a turn that closes on a question to the user is the post-merge offer there — under Codex only.
|
|
66
67
|
|
|
@@ -93,15 +94,15 @@ Every hook here fires on every tool call, prompt or turn end in every open sessi
|
|
|
93
94
|
|
|
94
95
|
| Cap | Limit |
|
|
95
96
|
| :-- | :-- |
|
|
96
|
-
| Hook commands per busy slot (
|
|
97
|
+
| Hook commands an irrelevant event launches per busy slot (PostToolUse on `Bash` and `Read`, Stop, UserPromptSubmit) | 1 (PreToolUse on `Bash`: 0, its `if` rules launch nothing for a command naming neither `gh` nor `glab`) |
|
|
97
98
|
| Programs started beyond each hook's own launch on an irrelevant event | 0 (Stop: 1, a transcript `tail` until the capability-claim gate has nudged; bash cannot seek) |
|
|
98
99
|
| `node`, `gh`, `python` on that path | 0 |
|
|
99
100
|
| Median wall time of one irrelevant firing, Linux/macOS | 100 ms |
|
|
100
|
-
|
|
|
101
|
-
| Hook timeout | declared on every hook; 1 s each, 2 s summed over the hooks one firing launches |
|
|
101
|
+
| Distinct hook commands in the whole manifest (a command's `if` variants count once) | 13 |
|
|
102
|
+
| Hook timeout | declared on every hook; 1 s each, 2 s summed over the hooks one firing launches; SessionStart 5 s each, 10 s summed |
|
|
102
103
|
| Median wall time of each hook, on every scenario in `HOOK_RUNTIME_SCENARIOS`, every platform | 1 s |
|
|
103
104
|
| Summed median wall time of the hooks one firing launches | 2 s |
|
|
104
105
|
|
|
105
106
|
Counts are exec counts, so they are identical on every runner. Every count is exact: CI fails when a change exceeds a limit, and also when it beats one until `footprint/constants.ts` is lowered to match, so a gain cannot be given back later.
|
|
106
107
|
|
|
107
|
-
The harness kills a hook at its timeout, so the 1 s timeout is the hard cap; the runtime scenarios hold each hook inside it. They fire every `hooks.json` group — a group no scenario fires fails CI — on its irrelevant path and on the payloads that make its gates do real work, with `gh`, `muggle`, `npm`, `npx`, `curl` and `wget` replaced by stand-ins that stall for 5 s, so a hook that waits on the network or an install fails there rather than on a user's machine. Work that has to wait on the network leaves the hook path: the walkthrough comment's reserve and settle writes and the walkthrough gate's provider scan run as detached `guardrails.mjs` background jobs, and every other child a gate starts (`git`, the dev-server probe) is cut to what is left of a 600 ms allowance (`src/hook-budget/`).
|
|
108
|
+
The harness kills a hook at its timeout, so on the per-call, per-prompt and per-turn events the 1 s timeout is the hard cap; the runtime scenarios hold each hook inside it. SessionStart fires once per session and carries the session's whole muggle context, so its hooks declare 5 s — room for a loaded machine to start bash and Node instead of dropping that context — while the scenarios still hold their runtime to 1 s. They fire every `hooks.json` group — a group no scenario fires fails CI — on its irrelevant path and on the payloads that make its gates do real work, with `gh`, `muggle`, `npm`, `npx`, `curl` and `wget` replaced by stand-ins that stall for 5 s, so a hook that waits on the network or an install fails there rather than on a user's machine. Work that has to wait on the network leaves the hook path: the walkthrough comment's reserve and settle writes and the walkthrough gate's provider scan run as detached `guardrails.mjs` background jobs, and every other child a gate starts (`git`, the dev-server probe) is cut to what is left of a 600 ms allowance (`src/hook-budget/`).
|
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
"type": "command",
|
|
10
10
|
"command": "env MUGGLE_HOOK_HOST=codex bash \"${CLAUDE_PLUGIN_ROOT}/scripts/ensure-electron-app.sh\"",
|
|
11
11
|
"async": false,
|
|
12
|
-
"timeout":
|
|
12
|
+
"timeout": 14,
|
|
13
13
|
"commandWindows": "node \"${CLAUDE_PLUGIN_ROOT}\\scripts\\codex-hook-windows.mjs\" \"${CLAUDE_PLUGIN_ROOT}/scripts/ensure-electron-app.sh\""
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
16
|
"type": "command",
|
|
17
17
|
"command": "env MUGGLE_HOOK_HOST=codex bash \"${CLAUDE_PLUGIN_ROOT}/scripts/reconcile-stale-watchers.sh\"",
|
|
18
18
|
"async": false,
|
|
19
|
-
"timeout":
|
|
19
|
+
"timeout": 14,
|
|
20
20
|
"commandWindows": "node \"${CLAUDE_PLUGIN_ROOT}\\scripts\\codex-hook-windows.mjs\" \"${CLAUDE_PLUGIN_ROOT}/scripts/reconcile-stale-watchers.sh\""
|
|
21
21
|
}
|
|
22
22
|
]
|
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"type": "command",
|
|
9
9
|
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/ensure-electron-app.sh\"",
|
|
10
10
|
"async": false,
|
|
11
|
-
"timeout":
|
|
11
|
+
"timeout": 5
|
|
12
12
|
},
|
|
13
13
|
{
|
|
14
14
|
"type": "command",
|
|
15
15
|
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/reconcile-stale-watchers.sh\"",
|
|
16
16
|
"async": false,
|
|
17
|
-
"timeout":
|
|
17
|
+
"timeout": 5
|
|
18
18
|
}
|
|
19
19
|
]
|
|
20
20
|
}
|
|
@@ -25,6 +25,28 @@
|
|
|
25
25
|
"hooks": [
|
|
26
26
|
{
|
|
27
27
|
"type": "command",
|
|
28
|
+
"if": "Bash(*gh *)",
|
|
29
|
+
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-walkthrough-heading.sh",
|
|
30
|
+
"async": false,
|
|
31
|
+
"timeout": 1
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"type": "command",
|
|
35
|
+
"if": "Bash(*glab *)",
|
|
36
|
+
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-walkthrough-heading.sh",
|
|
37
|
+
"async": false,
|
|
38
|
+
"timeout": 1
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"type": "command",
|
|
42
|
+
"if": "PowerShell(*gh *)",
|
|
43
|
+
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-walkthrough-heading.sh",
|
|
44
|
+
"async": false,
|
|
45
|
+
"timeout": 1
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"type": "command",
|
|
49
|
+
"if": "PowerShell(*glab *)",
|
|
28
50
|
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-walkthrough-heading.sh",
|
|
29
51
|
"async": false,
|
|
30
52
|
"timeout": 1
|
|
@@ -110,17 +132,6 @@
|
|
|
110
132
|
}
|
|
111
133
|
]
|
|
112
134
|
},
|
|
113
|
-
{
|
|
114
|
-
"matcher": "Monitor",
|
|
115
|
-
"hooks": [
|
|
116
|
-
{
|
|
117
|
-
"type": "command",
|
|
118
|
-
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-pr-terminal.sh\"",
|
|
119
|
-
"async": false,
|
|
120
|
-
"timeout": 1
|
|
121
|
-
}
|
|
122
|
-
]
|
|
123
|
-
},
|
|
124
135
|
{
|
|
125
136
|
"matcher": "AskUserQuestion",
|
|
126
137
|
"hooks": [
|
|
@@ -12,6 +12,10 @@ set -uo pipefail
|
|
|
12
12
|
# then applies the real detectBuildIntent logic (question/slash exclusions,
|
|
13
13
|
# once-per-session dedupe). Over-matching here only costs an occasional needless
|
|
14
14
|
# spawn; it can never emit a spurious offer. Degrades to {} so it never blocks.
|
|
15
|
+
#
|
|
16
|
+
# The verbs are matched in the prompt alone, since a hex session id can spell
|
|
17
|
+
# "add" and a cwd can hold "build". Once the session has been routed the offer can
|
|
18
|
+
# never fire again, so its state flag ends the check in-shell.
|
|
15
19
|
|
|
16
20
|
guardrail_script_dir="${BASH_SOURCE[0]%/*}"
|
|
17
21
|
[[ $guardrail_script_dir == "${BASH_SOURCE[0]}" ]] && guardrail_script_dir=.
|
|
@@ -20,7 +24,10 @@ guardrail_script_dir="${BASH_SOURCE[0]%/*}"
|
|
|
20
24
|
GUARDRAIL_SUBCOMMAND="build-router"
|
|
21
25
|
|
|
22
26
|
guardrail_wants() {
|
|
23
|
-
|
|
27
|
+
if guardrail_load_state && guardrail_state_has '"buildIntentRouted": true'; then
|
|
28
|
+
return 1
|
|
29
|
+
fi
|
|
30
|
+
guardrail_fields_match prompt '(implement|build|add|create|write|fix|refactor|wire up|hook up|make|change the|conflict|merged|passing|green)'
|
|
24
31
|
}
|
|
25
32
|
|
|
26
33
|
if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
|
|
@@ -15,6 +15,7 @@ GUARDRAIL_STATE_FILE=""
|
|
|
15
15
|
GUARDRAIL_STATE=""
|
|
16
16
|
GUARDRAIL_STATE_LOADED=""
|
|
17
17
|
GUARDRAIL_HAS_STATE=""
|
|
18
|
+
GUARDRAIL_FIELD_VALUE=""
|
|
18
19
|
|
|
19
20
|
guardrail_read_payload() {
|
|
20
21
|
IFS= read -r -d '' GUARDRAIL_PAYLOAD || true
|
|
@@ -31,6 +32,33 @@ guardrail_payload_matches() {
|
|
|
31
32
|
return "$matched"
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
# Sets GUARDRAIL_FIELD_VALUE to the first "<name>": "<string>" in the payload, still JSON-escaped;
|
|
36
|
+
# returns 1 when the payload carries no such string field.
|
|
37
|
+
guardrail_payload_field() {
|
|
38
|
+
local field_pattern='"'"$1"'"[[:space:]]*:[[:space:]]*"(([^"\\]|\\.)*)"'
|
|
39
|
+
GUARDRAIL_FIELD_VALUE=""
|
|
40
|
+
[[ $GUARDRAIL_PAYLOAD =~ $field_pattern ]] || return 1
|
|
41
|
+
GUARDRAIL_FIELD_VALUE="${BASH_REMATCH[1]}"
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
# Case-insensitive ERE over the named payload fields, joined with a space in the order given;
|
|
45
|
+
# the last argument is the pattern. A tool's output and a read file's contents never reach it,
|
|
46
|
+
# so text that merely mentions a trigger cannot start Node on a pre-filter meant for the
|
|
47
|
+
# command that ran, the path that was read or the prompt that was sent.
|
|
48
|
+
guardrail_fields_match() {
|
|
49
|
+
local pattern="${!#}"
|
|
50
|
+
local haystack=""
|
|
51
|
+
local field_name
|
|
52
|
+
for field_name in "${@:1:$#-1}"; do
|
|
53
|
+
guardrail_payload_field "$field_name" && haystack+=" $GUARDRAIL_FIELD_VALUE"
|
|
54
|
+
done
|
|
55
|
+
local matched=1
|
|
56
|
+
shopt -s nocasematch
|
|
57
|
+
[[ $haystack =~ $pattern ]] && matched=0
|
|
58
|
+
shopt -u nocasematch
|
|
59
|
+
return "$matched"
|
|
60
|
+
}
|
|
61
|
+
|
|
34
62
|
# The home Node's os.homedir() resolves. HOME is right on macOS/Linux and most Git Bash
|
|
35
63
|
# setups; when it doesn't hold the state dir, USERPROFILE (C:\Users\x) is converted to its
|
|
36
64
|
# Git Bash form (/c/Users/x) in-shell rather than through cygpath.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
set -uo pipefail
|
|
3
3
|
|
|
4
|
-
# PR-terminal guardrail (PostToolUse/Bash
|
|
5
|
-
#
|
|
6
|
-
# watch
|
|
4
|
+
# PR-terminal guardrail (PostToolUse/Bash). When a PR just went terminal — a
|
|
5
|
+
# `gh pr merge`/`gh pr close` success line, or the `TERMINAL pr=N` line the
|
|
6
|
+
# pr-followup watch scripts print in a shell result — arm the post-merge handoff:
|
|
7
7
|
# record the PR as pending, nudge the model to finalize/tear down and offer
|
|
8
8
|
# next options, and hold the Stop gate (guardrail-terminal-gate.sh) until the
|
|
9
9
|
# AskUserQuestion offer runs. Decision logic lives in the bundled guardrails.mjs.
|
|
@@ -14,7 +14,10 @@ set -uo pipefail
|
|
|
14
14
|
# loose on purpose: a shell command quotes its path inside an escaped JSON
|
|
15
15
|
# string, or names it relative to a `cd` into the skills tree or to the `cwd`
|
|
16
16
|
# the payload carries. Over-matching costs one Node start; Node resolves the
|
|
17
|
-
# path for real.
|
|
17
|
+
# path for real. Only those three fields are read, cwd first so a relative read
|
|
18
|
+
# from inside the tree still matches: a Read's payload carries the whole file, so
|
|
19
|
+
# the whole payload would start Node for any doc that names a skills-tree path.
|
|
20
|
+
# Degrades to {}.
|
|
18
21
|
|
|
19
22
|
guardrail_script_dir="${BASH_SOURCE[0]%/*}"
|
|
20
23
|
[[ $guardrail_script_dir == "${BASH_SOURCE[0]}" ]] && guardrail_script_dir=.
|
|
@@ -23,7 +26,7 @@ guardrail_script_dir="${BASH_SOURCE[0]%/*}"
|
|
|
23
26
|
GUARDRAIL_SUBCOMMAND="record-stage-read"
|
|
24
27
|
|
|
25
28
|
guardrail_wants() {
|
|
26
|
-
|
|
29
|
+
guardrail_fields_match cwd file_path command 'skills.*\.md'
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
|
|
@@ -14,6 +14,10 @@ set -uo pipefail
|
|
|
14
14
|
# publish carrying a rendered walkthrough reaches guardrails.mjs, which then
|
|
15
15
|
# inspects the output for pass/fail and updates state. Degrades to {}.
|
|
16
16
|
#
|
|
17
|
+
# Each arm reads only the field guardrails.mjs judges it by — the command, or the
|
|
18
|
+
# tool's name. Against the whole payload, a jest config in a command's output or
|
|
19
|
+
# a cwd inside a muggle checkout would start Node on unrelated shell calls.
|
|
20
|
+
#
|
|
17
21
|
# The marker arm matches the MUGGLE_<GATE>_SKIP shape, never one token: every
|
|
18
22
|
# Stop gate documents its own marker as the escape hatch, and a per-token list
|
|
19
23
|
# left the watcher and walkthrough markers unreachable — the gates instructed
|
|
@@ -28,7 +32,8 @@ guardrail_script_dir="${BASH_SOURCE[0]%/*}"
|
|
|
28
32
|
GUARDRAIL_SUBCOMMAND="record-tests"
|
|
29
33
|
|
|
30
34
|
guardrail_wants() {
|
|
31
|
-
|
|
35
|
+
guardrail_fields_match command '(pnpm|npm|yarn)[[:space:]]+(run[[:space:]]+)?test|jest|vitest|pytest|go[[:space:]]+test|cargo[[:space:]]+test|MUGGLE_[A-Z0-9_]+_SKIP|gh[[:space:]]+pr[[:space:]]+(comment|create|edit)|issues/comments/[0-9]' \
|
|
36
|
+
|| guardrail_fields_match tool_name 'muggle.*(execute|test[-_]generation|replay)|muggle[-_]local[-_]telemetry[-_]skill[-_]emit'
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
|
|
@@ -11,7 +11,12 @@ set -euo pipefail
|
|
|
11
11
|
# run, because re-arming a stranger's PR would hand review work to a session with
|
|
12
12
|
# no context for it. Slots owned by another session (or none) are reported as
|
|
13
13
|
# orphans with the adopt command, never as work to pick up. A pure directory scan
|
|
14
|
-
# — no gh, no writes — so it stays cheap enough for every
|
|
14
|
+
# — no gh, no writes, bash builtins only — so it stays cheap enough for every
|
|
15
|
+
# session start however many slots have piled up.
|
|
16
|
+
|
|
17
|
+
hook_dir="${BASH_SOURCE[0]%/*}"
|
|
18
|
+
[ "$hook_dir" = "${BASH_SOURCE[0]}" ] && hook_dir=.
|
|
19
|
+
. "${hook_dir}/guardrail-lib.sh"
|
|
15
20
|
|
|
16
21
|
escape_for_json() {
|
|
17
22
|
local s="$1"
|
|
@@ -23,15 +28,26 @@ escape_for_json() {
|
|
|
23
28
|
printf '%s' "$s"
|
|
24
29
|
}
|
|
25
30
|
|
|
26
|
-
#
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
# Sets owner_session_id to the first "session_id": "..." in an owner.json, read
|
|
32
|
+
# in-shell: this runs for every open slot on every session start, and a
|
|
33
|
+
# sed|head|tr pipeline per slot costs seconds on Windows. jq is not guaranteed
|
|
34
|
+
# present, and on Windows it appends CRLF that makes an empty field compare
|
|
35
|
+
# non-empty.
|
|
36
|
+
read_owner_session_id() {
|
|
37
|
+
local owner_json=""
|
|
38
|
+
local session_id_pattern='"session_id"[[:space:]]*:[[:space:]]*"([^"]*)"'
|
|
39
|
+
owner_session_id=""
|
|
40
|
+
IFS= read -r -d '' owner_json <"$1" || true
|
|
41
|
+
if [[ $owner_json =~ $session_id_pattern ]]; then
|
|
42
|
+
owner_session_id="${BASH_REMATCH[1]}"
|
|
43
|
+
fi
|
|
31
44
|
}
|
|
32
45
|
|
|
33
|
-
|
|
34
|
-
current_session_id
|
|
46
|
+
guardrail_read_payload
|
|
47
|
+
current_session_id=""
|
|
48
|
+
if guardrail_payload_field session_id; then
|
|
49
|
+
current_session_id="$GUARDRAIL_FIELD_VALUE"
|
|
50
|
+
fi
|
|
35
51
|
|
|
36
52
|
# A slot is an open watcher iff it has prs.json (a tracked PR) and no result.md
|
|
37
53
|
# (not yet finalized). A *.stopped dir is the owner's kill switch — it keeps its
|
|
@@ -52,7 +68,8 @@ if [ -d "$sessions_dir" ]; then
|
|
|
52
68
|
|
|
53
69
|
slot_owner=""
|
|
54
70
|
if [ -f "${slot}owner.json" ]; then
|
|
55
|
-
|
|
71
|
+
read_owner_session_id "${slot}owner.json"
|
|
72
|
+
slot_owner="$owner_session_id"
|
|
56
73
|
fi
|
|
57
74
|
|
|
58
75
|
# Fail closed: an unidentifiable session owns nothing. Absent owner.json
|
|
@@ -62,7 +79,8 @@ if [ -d "$sessions_dir" ]; then
|
|
|
62
79
|
else
|
|
63
80
|
orphan_count=$((orphan_count + 1))
|
|
64
81
|
if [ -z "$first_orphan_slug" ]; then
|
|
65
|
-
first_orphan_slug
|
|
82
|
+
first_orphan_slug="${slot%/}"
|
|
83
|
+
first_orphan_slug="${first_orphan_slug##*/}"
|
|
66
84
|
fi
|
|
67
85
|
fi
|
|
68
86
|
done
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"release": "5.18.0",
|
|
3
|
-
"buildId": "run-
|
|
4
|
-
"commitSha": "
|
|
5
|
-
"buildTime": "2026-10-
|
|
3
|
+
"buildId": "run-190-1",
|
|
4
|
+
"commitSha": "9bdfcbcec3b9d50374eb7a0129c568f48002e97a",
|
|
5
|
+
"buildTime": "2026-10-24T07:33:10Z",
|
|
6
6
|
"serviceName": "muggle-ai-works-mcp"
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@muggleai/works",
|
|
3
3
|
"mcpName": "io.github.multiplex-ai/muggle",
|
|
4
|
-
"version": "5.25.0-staging.
|
|
4
|
+
"version": "5.25.0-staging.190",
|
|
5
5
|
"description": "13 years of Microsoft hyperscale engineering, packaged as a harness for your AI coding agent.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/index.js",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "muggle",
|
|
3
3
|
"description": "Real-browser E2E acceptance for your coding agent: test the flows you changed and open the PR with screenshots. Built for flows other tools can't reach: managed test identities with live inboxes (magic links, email OTP and 2FA, verification mail, password resets), an encrypted secret store for login and test credentials, and a test graph that runs prerequisite flows first. Plain-English tests become replayable scripts on localhost or preview URLs.",
|
|
4
|
-
"version": "5.25.0-staging.
|
|
4
|
+
"version": "5.25.0-staging.190",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Muggle AI",
|
|
7
7
|
"email": "support@muggle-ai.com"
|
package/plugin/.codex-mcp.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "muggle",
|
|
3
|
-
"version": "5.25.0-staging.
|
|
3
|
+
"version": "5.25.0-staging.190",
|
|
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.25.0-staging.
|
|
5
|
+
"version": "5.25.0-staging.190",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Muggle AI",
|
|
8
8
|
"email": "support@muggle-ai.com"
|
package/plugin/.mcp.json
CHANGED
package/plugin/hooks/README.md
CHANGED
|
@@ -28,7 +28,7 @@ A recorder that *clears* an obligation — a walkthrough posted, a failure diagn
|
|
|
28
28
|
|
|
29
29
|
Each guardrail is a bash gate script in `../scripts/` holding a `guardrail_wants` pre-filter and the `guardrails.mjs` subcommand it feeds; the bundled `../scripts/guardrails.mjs` holds the decision logic (built from `src/guardrails/`, vitest-covered). The busy events — a shell command before and after it runs, and every turn end — register one `guardrail-dispatch.sh` command listing their gates, which reads the payload once, asks every gate's pre-filter in that one process, and starts Node once (`guardrails.mjs run <gates...>`) for just the gates that could fire, merging their responses. Rarer events call a gate script directly. Per-session state in `~/.muggle-ai/guardrails/<session_id>.json` tracks what fired. Any *failure* degrades to `{}` (allow) — a gate blocks only by an explicit, tested decision, never by accident; `guardrail-lib.sh` is the one place that falls back, and `run` isolates gates from each other.
|
|
30
30
|
|
|
31
|
-
Pre-filters are bash builtins only (`guardrail-lib.sh`), so an irrelevant event starts no process at all. A gate that has spent its block budget stamps a `<gate>Released` flag, which its wrapper then pre-filters on — without it a released gate keeps cold-starting Node on every remaining turn end to answer `{}`, and the walkthrough gate keeps queuing provider scans to do it. That pre-filter is a second, looser copy of what `guardrails.mjs` matches, and it is the one place a guardrail can fail *silently*: a payload it drops — a skip marker, a reopen line, a comment edit — reaches no recorder, and the gate keeps demanding an action the user already took. Over-matching is free; under-matching is a dead escape hatch. `src/test/guardrails/hook-prefilter.test.ts` pins every payload each subcommand acts on against the wrapper guarding it, and derives the skip-marker tokens from source so a new marker is covered the moment it exists.
|
|
31
|
+
Pre-filters are bash builtins only (`guardrail-lib.sh`), so an irrelevant event starts no process at all. A pre-filter reads only the payload fields its subcommand judges (`guardrail_fields_match`: the command, the tool's name, the path read, the prompt), never the whole payload — a tool's output or a read file's contents would otherwise start Node whenever they merely mention a trigger. The PreToolUse deny gates go one step further: Claude Code's `if` rules (`Bash(*gh *)`, `Bash(*glab *)` and their `PowerShell` twins) launch them only for a command naming `gh` or `glab`, so every other shell call starts no hook process. A rule's leading `*` is load-bearing: it is what reaches a `gh` inside `bash -c "…"`. A gate that has spent its block budget stamps a `<gate>Released` flag, which its wrapper then pre-filters on — without it a released gate keeps cold-starting Node on every remaining turn end to answer `{}`, and the walkthrough gate keeps queuing provider scans to do it. That pre-filter is a second, looser copy of what `guardrails.mjs` matches, and it is the one place a guardrail can fail *silently*: a payload it drops — a skip marker, a reopen line, a comment edit — reaches no recorder, and the gate keeps demanding an action the user already took. Over-matching is free; under-matching is a dead escape hatch. `src/test/guardrails/hook-prefilter.test.ts` pins every payload each subcommand acts on against the wrapper guarding it, and derives the skip-marker tokens from source so a new marker is covered the moment it exists.
|
|
32
32
|
|
|
33
33
|
## Guardrails
|
|
34
34
|
|
|
@@ -36,13 +36,13 @@ Pre-filters are bash builtins only (`guardrail-lib.sh`), so an irrelevant event
|
|
|
36
36
|
| :--------- | :------ | :------- | :-------- | :--------- | :----- |
|
|
37
37
|
| `PostToolUse` (Bash) | `guardrail-pr-opened.sh` | advise | a `gh pr create`/`gh pr ready` just succeeded | `autoWatchPR` | start a `muggle-pr-followup` watcher on the new PR |
|
|
38
38
|
| `PostToolUse` (Bash + muggle execute/replay/skill-emit MCP tools) | `guardrail-record-tests.sh` | record | a unit-test command passed, an E2E run happened (execute/replay call, or the muggle-test skill's own telemetry emit — which registers a clean SKIP verdict too), or an `echo "MUGGLE_E2E_SKIP: <reason>"` marker declared E2E un-runnable, or a walkthrough carrying the `build-pr-section` sentinel was posted / declared un-postable via `echo "MUGGLE_WALKTHROUGH_SKIP: <reason>"` | — | set `unitTestsGreen` / `e2eRun` / `e2eSkipped` / `walkthroughPosted` / `walkthroughSkipped` session state |
|
|
39
|
-
| `PostToolUse` (Bash
|
|
39
|
+
| `PostToolUse` (Bash) | `guardrail-pr-terminal.sh` | advise | a PR just went terminal — a `gh pr merge`/`gh pr close` success line or the `TERMINAL pr=N` line the watch scripts print in a shell result (never bare `"state":"MERGED"` metadata). Not registered on `Monitor`: a Monitor call returns before its script prints anything, so its result never carries that line | — | record `terminalPending`, direct the post-merge handoff: finalize the watcher slot, tear down per `autoCleanup`, offer next options via AskUserQuestion |
|
|
40
40
|
| `PostToolUse` (AskUserQuestion) | `guardrail-offer-ran.sh` | record | a next-options offer ran while a terminal PR was pending | — | clear `terminalPending` — the only exit for the post-merge Stop gate |
|
|
41
41
|
| `PostToolUse` (Skill + muggle telemetry-skill-emit) | `guardrail-skill-stages.sh` | advise | a skill this plugin ships was invoked; its `SKILL.md` frontmatter may declare `mandatoryStages`. Registered on the skill's own MCP announcement too, so the declaration still lands if the Skill payload ever stops carrying a name | — | record `lastInvokedSkillName` + `mandatoryStages`, and name the declared files as required reading at the moment of use |
|
|
42
42
|
| `PostToolUse` (Read) | `guardrail-record-stage-read.sh` | record | a markdown file under a `skills/` directory was opened | — | append to `stagesRead` — how the stage gate tells a stage that was read from one that was skipped |
|
|
43
43
|
| `PostToolUse` (Bash + muggle telemetry-event-emit / user-feedback-create) | `guardrail-record-stage-signals.sh` | record | a Step 6f `pre-execution-classification` emit, debug-path evidence for a failed run (a `*-failure-classified\|resolved` emit or feedback naming it), or a `MUGGLE_STAGE_SKIP` / `MUGGLE_CLASSIFY_SKIP` / `MUGGLE_DEBUG_SKIP` marker | — | set `classifiedTestCaseIds` / `debuggedRuns` / the matching skip flag |
|
|
44
44
|
| `PostToolUse` (Bash) | `guardrail-record-comment-replies.sh` | record | an unresolved-thread fetch named review threads still awaiting an answer (classified by the `<!-- muggle-do:bot -->` marker, never the author login), a threaded reply the provider **confirmed** answered comments in one, or a `MUGGLE_REPLY_SKIP` marker deferred them | — | claim each thread and cover the comments answered, in the per-PR ledger beside the muggle-do slot |
|
|
45
|
-
| `PreToolUse` (Bash) | `guardrail-report-format.sh` | **enforce** | a `gh pr comment\|create\|edit` body — or a `gh api … issues/comments/<id>` PATCH editing one — reads like an E2E report but lacks the `build-pr-section` sentinel | — | **deny** — render via `muggle build-pr-section` instead |
|
|
45
|
+
| `PreToolUse` (Bash, `if` a command names `gh`/`glab`) | `guardrail-report-format.sh` | **enforce** | a `gh pr comment\|create\|edit` body — or a `gh api … issues/comments/<id>` PATCH editing one — reads like an E2E report but lacks the `build-pr-section` sentinel | — | **deny** — render via `muggle build-pr-section` instead |
|
|
46
46
|
| `PreToolUse` (muggle local execute/replay) | `guardrail-classify-gate.sh` | **enforce** | `muggle-test` is the skill in play and the target test case has no `pre-execution-classification` this session | — | **deny** — run Step 6f first (it calls `muggle-remote-test-script-list`, which is where the run learns the case has never passed) or record a legitimate skip via `MUGGLE_CLASSIFY_SKIP`. Scoped to `muggle-test`, so the single-target skills that legitimately skip classification are untouched; fails open when the test case can't be resolved |
|
|
47
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) |
|
|
@@ -56,11 +56,12 @@ Pre-filters are bash builtins only (`guardrail-lib.sh`), so an irrelevant event
|
|
|
56
56
|
|
|
57
57
|
## Codex
|
|
58
58
|
|
|
59
|
-
Codex runs Claude Code-format plugin hooks, from `codex-hooks.json` rather than `hooks.json` — the Codex plugin manifest (`../.codex-plugin/plugin.json`) names it. `scripts/build-codex-hooks.mjs` generates it from `hooks.json` on every build, and `pnpm run verify:plugin` fails when the committed copy drifts, so `hooks.json` stays the one manifest to edit. The generated copy differs in
|
|
59
|
+
Codex runs Claude Code-format plugin hooks, from `codex-hooks.json` rather than `hooks.json` — the Codex plugin manifest (`../.codex-plugin/plugin.json`) names it. `scripts/build-codex-hooks.mjs` generates it from `hooks.json` on every build, and `pnpm run verify:plugin` fails when the committed copy drifts, so `hooks.json` stays the one manifest to edit. The generated copy differs in four ways, each written down rather than guessed at runtime:
|
|
60
60
|
|
|
61
61
|
- **Host stamp.** Codex exports `CLAUDE_PLUGIN_ROOT` to plugin hooks for compatibility, so nothing in the environment tells a guardrail it is not in Claude Code. Every command runs under `env MUGGLE_HOOK_HOST=codex`, and the guardrails word their instructions for Codex (`$muggle:muggle-test`, not `/muggle:muggle-test`).
|
|
62
62
|
- **Tool names.** A matcher naming a Claude Code tool becomes the Codex tool that plays its part — `AskUserQuestion` → `request_user_input` — and a group whose tools Codex lacks is dropped: Codex reports every shell call as `Bash`, opens files and skills through the shell, and delivers a background command's output as that command's own `Bash` event, so `PowerShell`, `Read`, `Skill` and `Monitor` never fire. An MCP tool reaches a Codex hook as `mcp__muggle__<tool>` with every character outside `[A-Za-z0-9_]` turned into `_` (`mcp__muggle__muggle_local_execute_replay`), so the MCP matchers are respelled; the wrappers' pre-filters and the guardrails' own tool checks accept either spelling.
|
|
63
63
|
- **Windows.** Codex runs `commandWindows` through the session shell — PowerShell, or cmd.exe as a fallback — so every hook also gets one that starts with a bare `node` (both shells parse it alike; a quoted path there is a PowerShell syntax error) and hands the same script to Git Bash through `../scripts/codex-hook-windows.mjs`. It looks for Git Bash beside `git.exe`, then in the default install paths; `MUGGLE_HOOK_BASH` names one it would not find. With no Git Bash the launcher prints `{}` and succeeds — the same allow-by-default every guardrail falls back to.
|
|
64
|
+
- **No `if` rules.** Codex has no counterpart to Claude Code's `if`, so the rule is dropped and the identical commands its variants leave collapse into one: under Codex the deny gates run on every shell call and their in-shell pre-filters decide.
|
|
64
65
|
|
|
65
66
|
What Codex sends differs too, and the guardrails read either shape: a shell result arrives as the bare output string (normalized to `tool_response.output` in `hookInput.ts`), with no exit code; the Stop payload carries the closing message as `last_assistant_message`, which the capability-claim gate judges in place of the transcript, whose format is not Claude Code's; and a stage file opened with `cat` or `sed -n` counts as read, since there is no `Read` tool. With no structured question in Codex's default mode, a turn that closes on a question to the user is the post-merge offer there — under Codex only.
|
|
66
67
|
|
|
@@ -93,15 +94,15 @@ Every hook here fires on every tool call, prompt or turn end in every open sessi
|
|
|
93
94
|
|
|
94
95
|
| Cap | Limit |
|
|
95
96
|
| :-- | :-- |
|
|
96
|
-
| Hook commands per busy slot (
|
|
97
|
+
| Hook commands an irrelevant event launches per busy slot (PostToolUse on `Bash` and `Read`, Stop, UserPromptSubmit) | 1 (PreToolUse on `Bash`: 0, its `if` rules launch nothing for a command naming neither `gh` nor `glab`) |
|
|
97
98
|
| Programs started beyond each hook's own launch on an irrelevant event | 0 (Stop: 1, a transcript `tail` until the capability-claim gate has nudged; bash cannot seek) |
|
|
98
99
|
| `node`, `gh`, `python` on that path | 0 |
|
|
99
100
|
| Median wall time of one irrelevant firing, Linux/macOS | 100 ms |
|
|
100
|
-
|
|
|
101
|
-
| Hook timeout | declared on every hook; 1 s each, 2 s summed over the hooks one firing launches |
|
|
101
|
+
| Distinct hook commands in the whole manifest (a command's `if` variants count once) | 13 |
|
|
102
|
+
| Hook timeout | declared on every hook; 1 s each, 2 s summed over the hooks one firing launches; SessionStart 5 s each, 10 s summed |
|
|
102
103
|
| Median wall time of each hook, on every scenario in `HOOK_RUNTIME_SCENARIOS`, every platform | 1 s |
|
|
103
104
|
| Summed median wall time of the hooks one firing launches | 2 s |
|
|
104
105
|
|
|
105
106
|
Counts are exec counts, so they are identical on every runner. Every count is exact: CI fails when a change exceeds a limit, and also when it beats one until `footprint/constants.ts` is lowered to match, so a gain cannot be given back later.
|
|
106
107
|
|
|
107
|
-
The harness kills a hook at its timeout, so the 1 s timeout is the hard cap; the runtime scenarios hold each hook inside it. They fire every `hooks.json` group — a group no scenario fires fails CI — on its irrelevant path and on the payloads that make its gates do real work, with `gh`, `muggle`, `npm`, `npx`, `curl` and `wget` replaced by stand-ins that stall for 5 s, so a hook that waits on the network or an install fails there rather than on a user's machine. Work that has to wait on the network leaves the hook path: the walkthrough comment's reserve and settle writes and the walkthrough gate's provider scan run as detached `guardrails.mjs` background jobs, and every other child a gate starts (`git`, the dev-server probe) is cut to what is left of a 600 ms allowance (`src/hook-budget/`).
|
|
108
|
+
The harness kills a hook at its timeout, so on the per-call, per-prompt and per-turn events the 1 s timeout is the hard cap; the runtime scenarios hold each hook inside it. SessionStart fires once per session and carries the session's whole muggle context, so its hooks declare 5 s — room for a loaded machine to start bash and Node instead of dropping that context — while the scenarios still hold their runtime to 1 s. They fire every `hooks.json` group — a group no scenario fires fails CI — on its irrelevant path and on the payloads that make its gates do real work, with `gh`, `muggle`, `npm`, `npx`, `curl` and `wget` replaced by stand-ins that stall for 5 s, so a hook that waits on the network or an install fails there rather than on a user's machine. Work that has to wait on the network leaves the hook path: the walkthrough comment's reserve and settle writes and the walkthrough gate's provider scan run as detached `guardrails.mjs` background jobs, and every other child a gate starts (`git`, the dev-server probe) is cut to what is left of a 600 ms allowance (`src/hook-budget/`).
|
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
"type": "command",
|
|
10
10
|
"command": "env MUGGLE_HOOK_HOST=codex bash \"${CLAUDE_PLUGIN_ROOT}/scripts/ensure-electron-app.sh\"",
|
|
11
11
|
"async": false,
|
|
12
|
-
"timeout":
|
|
12
|
+
"timeout": 14,
|
|
13
13
|
"commandWindows": "node \"${CLAUDE_PLUGIN_ROOT}\\scripts\\codex-hook-windows.mjs\" \"${CLAUDE_PLUGIN_ROOT}/scripts/ensure-electron-app.sh\""
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
16
|
"type": "command",
|
|
17
17
|
"command": "env MUGGLE_HOOK_HOST=codex bash \"${CLAUDE_PLUGIN_ROOT}/scripts/reconcile-stale-watchers.sh\"",
|
|
18
18
|
"async": false,
|
|
19
|
-
"timeout":
|
|
19
|
+
"timeout": 14,
|
|
20
20
|
"commandWindows": "node \"${CLAUDE_PLUGIN_ROOT}\\scripts\\codex-hook-windows.mjs\" \"${CLAUDE_PLUGIN_ROOT}/scripts/reconcile-stale-watchers.sh\""
|
|
21
21
|
}
|
|
22
22
|
]
|
package/plugin/hooks/hooks.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"type": "command",
|
|
9
9
|
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/ensure-electron-app.sh\"",
|
|
10
10
|
"async": false,
|
|
11
|
-
"timeout":
|
|
11
|
+
"timeout": 5
|
|
12
12
|
},
|
|
13
13
|
{
|
|
14
14
|
"type": "command",
|
|
15
15
|
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/reconcile-stale-watchers.sh\"",
|
|
16
16
|
"async": false,
|
|
17
|
-
"timeout":
|
|
17
|
+
"timeout": 5
|
|
18
18
|
}
|
|
19
19
|
]
|
|
20
20
|
}
|
|
@@ -25,6 +25,28 @@
|
|
|
25
25
|
"hooks": [
|
|
26
26
|
{
|
|
27
27
|
"type": "command",
|
|
28
|
+
"if": "Bash(*gh *)",
|
|
29
|
+
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-walkthrough-heading.sh",
|
|
30
|
+
"async": false,
|
|
31
|
+
"timeout": 1
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"type": "command",
|
|
35
|
+
"if": "Bash(*glab *)",
|
|
36
|
+
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-walkthrough-heading.sh",
|
|
37
|
+
"async": false,
|
|
38
|
+
"timeout": 1
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"type": "command",
|
|
42
|
+
"if": "PowerShell(*gh *)",
|
|
43
|
+
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-walkthrough-heading.sh",
|
|
44
|
+
"async": false,
|
|
45
|
+
"timeout": 1
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"type": "command",
|
|
49
|
+
"if": "PowerShell(*glab *)",
|
|
28
50
|
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-dispatch.sh\" guardrail-report-format.sh guardrail-resolve-gate.sh guardrail-walkthrough-heading.sh",
|
|
29
51
|
"async": false,
|
|
30
52
|
"timeout": 1
|
|
@@ -110,17 +132,6 @@
|
|
|
110
132
|
}
|
|
111
133
|
]
|
|
112
134
|
},
|
|
113
|
-
{
|
|
114
|
-
"matcher": "Monitor",
|
|
115
|
-
"hooks": [
|
|
116
|
-
{
|
|
117
|
-
"type": "command",
|
|
118
|
-
"command": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/guardrail-pr-terminal.sh\"",
|
|
119
|
-
"async": false,
|
|
120
|
-
"timeout": 1
|
|
121
|
-
}
|
|
122
|
-
]
|
|
123
|
-
},
|
|
124
135
|
{
|
|
125
136
|
"matcher": "AskUserQuestion",
|
|
126
137
|
"hooks": [
|
|
@@ -12,6 +12,10 @@ set -uo pipefail
|
|
|
12
12
|
# then applies the real detectBuildIntent logic (question/slash exclusions,
|
|
13
13
|
# once-per-session dedupe). Over-matching here only costs an occasional needless
|
|
14
14
|
# spawn; it can never emit a spurious offer. Degrades to {} so it never blocks.
|
|
15
|
+
#
|
|
16
|
+
# The verbs are matched in the prompt alone, since a hex session id can spell
|
|
17
|
+
# "add" and a cwd can hold "build". Once the session has been routed the offer can
|
|
18
|
+
# never fire again, so its state flag ends the check in-shell.
|
|
15
19
|
|
|
16
20
|
guardrail_script_dir="${BASH_SOURCE[0]%/*}"
|
|
17
21
|
[[ $guardrail_script_dir == "${BASH_SOURCE[0]}" ]] && guardrail_script_dir=.
|
|
@@ -20,7 +24,10 @@ guardrail_script_dir="${BASH_SOURCE[0]%/*}"
|
|
|
20
24
|
GUARDRAIL_SUBCOMMAND="build-router"
|
|
21
25
|
|
|
22
26
|
guardrail_wants() {
|
|
23
|
-
|
|
27
|
+
if guardrail_load_state && guardrail_state_has '"buildIntentRouted": true'; then
|
|
28
|
+
return 1
|
|
29
|
+
fi
|
|
30
|
+
guardrail_fields_match prompt '(implement|build|add|create|write|fix|refactor|wire up|hook up|make|change the|conflict|merged|passing|green)'
|
|
24
31
|
}
|
|
25
32
|
|
|
26
33
|
if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
|
|
@@ -15,6 +15,7 @@ GUARDRAIL_STATE_FILE=""
|
|
|
15
15
|
GUARDRAIL_STATE=""
|
|
16
16
|
GUARDRAIL_STATE_LOADED=""
|
|
17
17
|
GUARDRAIL_HAS_STATE=""
|
|
18
|
+
GUARDRAIL_FIELD_VALUE=""
|
|
18
19
|
|
|
19
20
|
guardrail_read_payload() {
|
|
20
21
|
IFS= read -r -d '' GUARDRAIL_PAYLOAD || true
|
|
@@ -31,6 +32,33 @@ guardrail_payload_matches() {
|
|
|
31
32
|
return "$matched"
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
# Sets GUARDRAIL_FIELD_VALUE to the first "<name>": "<string>" in the payload, still JSON-escaped;
|
|
36
|
+
# returns 1 when the payload carries no such string field.
|
|
37
|
+
guardrail_payload_field() {
|
|
38
|
+
local field_pattern='"'"$1"'"[[:space:]]*:[[:space:]]*"(([^"\\]|\\.)*)"'
|
|
39
|
+
GUARDRAIL_FIELD_VALUE=""
|
|
40
|
+
[[ $GUARDRAIL_PAYLOAD =~ $field_pattern ]] || return 1
|
|
41
|
+
GUARDRAIL_FIELD_VALUE="${BASH_REMATCH[1]}"
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
# Case-insensitive ERE over the named payload fields, joined with a space in the order given;
|
|
45
|
+
# the last argument is the pattern. A tool's output and a read file's contents never reach it,
|
|
46
|
+
# so text that merely mentions a trigger cannot start Node on a pre-filter meant for the
|
|
47
|
+
# command that ran, the path that was read or the prompt that was sent.
|
|
48
|
+
guardrail_fields_match() {
|
|
49
|
+
local pattern="${!#}"
|
|
50
|
+
local haystack=""
|
|
51
|
+
local field_name
|
|
52
|
+
for field_name in "${@:1:$#-1}"; do
|
|
53
|
+
guardrail_payload_field "$field_name" && haystack+=" $GUARDRAIL_FIELD_VALUE"
|
|
54
|
+
done
|
|
55
|
+
local matched=1
|
|
56
|
+
shopt -s nocasematch
|
|
57
|
+
[[ $haystack =~ $pattern ]] && matched=0
|
|
58
|
+
shopt -u nocasematch
|
|
59
|
+
return "$matched"
|
|
60
|
+
}
|
|
61
|
+
|
|
34
62
|
# The home Node's os.homedir() resolves. HOME is right on macOS/Linux and most Git Bash
|
|
35
63
|
# setups; when it doesn't hold the state dir, USERPROFILE (C:\Users\x) is converted to its
|
|
36
64
|
# Git Bash form (/c/Users/x) in-shell rather than through cygpath.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
set -uo pipefail
|
|
3
3
|
|
|
4
|
-
# PR-terminal guardrail (PostToolUse/Bash
|
|
5
|
-
#
|
|
6
|
-
# watch
|
|
4
|
+
# PR-terminal guardrail (PostToolUse/Bash). When a PR just went terminal — a
|
|
5
|
+
# `gh pr merge`/`gh pr close` success line, or the `TERMINAL pr=N` line the
|
|
6
|
+
# pr-followup watch scripts print in a shell result — arm the post-merge handoff:
|
|
7
7
|
# record the PR as pending, nudge the model to finalize/tear down and offer
|
|
8
8
|
# next options, and hold the Stop gate (guardrail-terminal-gate.sh) until the
|
|
9
9
|
# AskUserQuestion offer runs. Decision logic lives in the bundled guardrails.mjs.
|
|
@@ -14,7 +14,10 @@ set -uo pipefail
|
|
|
14
14
|
# loose on purpose: a shell command quotes its path inside an escaped JSON
|
|
15
15
|
# string, or names it relative to a `cd` into the skills tree or to the `cwd`
|
|
16
16
|
# the payload carries. Over-matching costs one Node start; Node resolves the
|
|
17
|
-
# path for real.
|
|
17
|
+
# path for real. Only those three fields are read, cwd first so a relative read
|
|
18
|
+
# from inside the tree still matches: a Read's payload carries the whole file, so
|
|
19
|
+
# the whole payload would start Node for any doc that names a skills-tree path.
|
|
20
|
+
# Degrades to {}.
|
|
18
21
|
|
|
19
22
|
guardrail_script_dir="${BASH_SOURCE[0]%/*}"
|
|
20
23
|
[[ $guardrail_script_dir == "${BASH_SOURCE[0]}" ]] && guardrail_script_dir=.
|
|
@@ -23,7 +26,7 @@ guardrail_script_dir="${BASH_SOURCE[0]%/*}"
|
|
|
23
26
|
GUARDRAIL_SUBCOMMAND="record-stage-read"
|
|
24
27
|
|
|
25
28
|
guardrail_wants() {
|
|
26
|
-
|
|
29
|
+
guardrail_fields_match cwd file_path command 'skills.*\.md'
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
|
|
@@ -14,6 +14,10 @@ set -uo pipefail
|
|
|
14
14
|
# publish carrying a rendered walkthrough reaches guardrails.mjs, which then
|
|
15
15
|
# inspects the output for pass/fail and updates state. Degrades to {}.
|
|
16
16
|
#
|
|
17
|
+
# Each arm reads only the field guardrails.mjs judges it by — the command, or the
|
|
18
|
+
# tool's name. Against the whole payload, a jest config in a command's output or
|
|
19
|
+
# a cwd inside a muggle checkout would start Node on unrelated shell calls.
|
|
20
|
+
#
|
|
17
21
|
# The marker arm matches the MUGGLE_<GATE>_SKIP shape, never one token: every
|
|
18
22
|
# Stop gate documents its own marker as the escape hatch, and a per-token list
|
|
19
23
|
# left the watcher and walkthrough markers unreachable — the gates instructed
|
|
@@ -28,7 +32,8 @@ guardrail_script_dir="${BASH_SOURCE[0]%/*}"
|
|
|
28
32
|
GUARDRAIL_SUBCOMMAND="record-tests"
|
|
29
33
|
|
|
30
34
|
guardrail_wants() {
|
|
31
|
-
|
|
35
|
+
guardrail_fields_match command '(pnpm|npm|yarn)[[:space:]]+(run[[:space:]]+)?test|jest|vitest|pytest|go[[:space:]]+test|cargo[[:space:]]+test|MUGGLE_[A-Z0-9_]+_SKIP|gh[[:space:]]+pr[[:space:]]+(comment|create|edit)|issues/comments/[0-9]' \
|
|
36
|
+
|| guardrail_fields_match tool_name 'muggle.*(execute|test[-_]generation|replay)|muggle[-_]local[-_]telemetry[-_]skill[-_]emit'
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
|
|
@@ -11,7 +11,12 @@ set -euo pipefail
|
|
|
11
11
|
# run, because re-arming a stranger's PR would hand review work to a session with
|
|
12
12
|
# no context for it. Slots owned by another session (or none) are reported as
|
|
13
13
|
# orphans with the adopt command, never as work to pick up. A pure directory scan
|
|
14
|
-
# — no gh, no writes — so it stays cheap enough for every
|
|
14
|
+
# — no gh, no writes, bash builtins only — so it stays cheap enough for every
|
|
15
|
+
# session start however many slots have piled up.
|
|
16
|
+
|
|
17
|
+
hook_dir="${BASH_SOURCE[0]%/*}"
|
|
18
|
+
[ "$hook_dir" = "${BASH_SOURCE[0]}" ] && hook_dir=.
|
|
19
|
+
. "${hook_dir}/guardrail-lib.sh"
|
|
15
20
|
|
|
16
21
|
escape_for_json() {
|
|
17
22
|
local s="$1"
|
|
@@ -23,15 +28,26 @@ escape_for_json() {
|
|
|
23
28
|
printf '%s' "$s"
|
|
24
29
|
}
|
|
25
30
|
|
|
26
|
-
#
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
# Sets owner_session_id to the first "session_id": "..." in an owner.json, read
|
|
32
|
+
# in-shell: this runs for every open slot on every session start, and a
|
|
33
|
+
# sed|head|tr pipeline per slot costs seconds on Windows. jq is not guaranteed
|
|
34
|
+
# present, and on Windows it appends CRLF that makes an empty field compare
|
|
35
|
+
# non-empty.
|
|
36
|
+
read_owner_session_id() {
|
|
37
|
+
local owner_json=""
|
|
38
|
+
local session_id_pattern='"session_id"[[:space:]]*:[[:space:]]*"([^"]*)"'
|
|
39
|
+
owner_session_id=""
|
|
40
|
+
IFS= read -r -d '' owner_json <"$1" || true
|
|
41
|
+
if [[ $owner_json =~ $session_id_pattern ]]; then
|
|
42
|
+
owner_session_id="${BASH_REMATCH[1]}"
|
|
43
|
+
fi
|
|
31
44
|
}
|
|
32
45
|
|
|
33
|
-
|
|
34
|
-
current_session_id
|
|
46
|
+
guardrail_read_payload
|
|
47
|
+
current_session_id=""
|
|
48
|
+
if guardrail_payload_field session_id; then
|
|
49
|
+
current_session_id="$GUARDRAIL_FIELD_VALUE"
|
|
50
|
+
fi
|
|
35
51
|
|
|
36
52
|
# A slot is an open watcher iff it has prs.json (a tracked PR) and no result.md
|
|
37
53
|
# (not yet finalized). A *.stopped dir is the owner's kill switch — it keeps its
|
|
@@ -52,7 +68,8 @@ if [ -d "$sessions_dir" ]; then
|
|
|
52
68
|
|
|
53
69
|
slot_owner=""
|
|
54
70
|
if [ -f "${slot}owner.json" ]; then
|
|
55
|
-
|
|
71
|
+
read_owner_session_id "${slot}owner.json"
|
|
72
|
+
slot_owner="$owner_session_id"
|
|
56
73
|
fi
|
|
57
74
|
|
|
58
75
|
# Fail closed: an unidentifiable session owns nothing. Absent owner.json
|
|
@@ -62,7 +79,8 @@ if [ -d "$sessions_dir" ]; then
|
|
|
62
79
|
else
|
|
63
80
|
orphan_count=$((orphan_count + 1))
|
|
64
81
|
if [ -z "$first_orphan_slug" ]; then
|
|
65
|
-
first_orphan_slug
|
|
82
|
+
first_orphan_slug="${slot%/}"
|
|
83
|
+
first_orphan_slug="${first_orphan_slug##*/}"
|
|
66
84
|
fi
|
|
67
85
|
fi
|
|
68
86
|
done
|