@muggleai/works 5.26.0-staging.197 → 5.26.0-staging.199

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.
Files changed (44) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/README.md +3 -3
  3. package/dist/{chunk-SLU7LHVJ.js → chunk-IL5E5YGY.js} +1 -1
  4. package/dist/{chunk-Y6JJ2SN7.js → chunk-MKQYUSIW.js} +1487 -36
  5. package/dist/cli.js +2 -2
  6. package/dist/index.js +2 -2
  7. package/dist/plugin/.claude-plugin/plugin.json +1 -1
  8. package/dist/plugin/.codex-mcp.json +1 -1
  9. package/dist/plugin/.codex-plugin/plugin.json +1 -1
  10. package/dist/plugin/.cursor-plugin/plugin.json +1 -1
  11. package/dist/plugin/.mcp.json +1 -1
  12. package/dist/plugin/hooks/README.md +1 -1
  13. package/dist/plugin/scripts/guardrail-walkthrough-gate.sh +15 -12
  14. package/dist/plugin/scripts/guardrails.mjs +134 -91
  15. package/dist/plugin/scripts/pr-watch-arm.sh +8 -1
  16. package/dist/plugin/skills/do/open-prs/forward.md +4 -2
  17. package/dist/plugin/skills/muggle-do/SKILL.md +1 -1
  18. package/dist/plugin/skills/muggle-pr-followup/arm-watcher.md +2 -0
  19. package/dist/plugin/skills/muggle-pr-followup/reconcile.md +4 -2
  20. package/dist/plugin/skills/muggle-pr-followup/state-schemas.md +15 -0
  21. package/dist/plugin/skills/muggle-pr-followup/stop.md +1 -1
  22. package/dist/plugin/skills/muggle-preferences/preference-gates/autoInstallCiWorkflow.md +1 -1
  23. package/dist/release-manifest.json +3 -3
  24. package/dist/{src-3HZTU2TJ.js → src-UVZTYRQY.js} +1 -1
  25. package/package.json +2 -1
  26. package/plugin/.claude-plugin/plugin.json +1 -1
  27. package/plugin/.codex-mcp.json +1 -1
  28. package/plugin/.codex-plugin/plugin.json +1 -1
  29. package/plugin/.cursor-plugin/plugin.json +1 -1
  30. package/plugin/.mcp.json +1 -1
  31. package/plugin/hooks/README.md +1 -1
  32. package/plugin/scripts/guardrail-walkthrough-gate.sh +15 -12
  33. package/plugin/scripts/guardrails.mjs +134 -91
  34. package/plugin/scripts/pr-watch-arm.sh +8 -1
  35. package/plugin/skills/do/open-prs/forward.md +4 -2
  36. package/plugin/skills/muggle-do/SKILL.md +1 -1
  37. package/plugin/skills/muggle-pr-followup/arm-watcher.md +2 -0
  38. package/plugin/skills/muggle-pr-followup/reconcile.md +4 -2
  39. package/plugin/skills/muggle-pr-followup/state-schemas.md +15 -0
  40. package/plugin/skills/muggle-pr-followup/stop.md +1 -1
  41. package/plugin/skills/muggle-preferences/preference-gates/autoInstallCiWorkflow.md +1 -1
  42. package/scripts/muggle-watch/README.md +45 -0
  43. package/scripts/muggle-watch/install-muggle-watch.ps1 +92 -0
  44. package/scripts/muggle-watch/muggle-watch-hidden.vbs +39 -0
@@ -0,0 +1,45 @@
1
+ # muggle watch service
2
+
3
+ A standing per-user scheduled task that runs `muggle watch tick` every few minutes, outside any agent session. Each tick:
4
+
5
+ - **Tracks** active Claude Code sessions (`claude agents --json`) and Codex sessions (recent `~/.codex/sessions` rollouts). It also tracks their processes: claude, codex, muggle MCP servers, and PR watch loops.
6
+ - **Checks every open PR-watch slot** under `~/.muggle-ai/muggle-do/sessions/`. Is its loop running, and heard by a live session? Is CI red? Is the branch behind or conflicting? Are review threads unresolved?
7
+ - **Keeps registered watchers running.** A slot carrying `watch-registration.json` (written by `pr-watch-arm.sh` on every arm) has its owner session resumed in the background when its loop is gone and the owner is down. The resumed session's `/muggle:muggle-pr-followup reconcile` re-arms it with that session's own context. The service never addresses a review, pushes, or kills a process.
8
+ - **Fans plugin reloads out.** When the user-scope plugins in `~/.claude/plugins/installed_plugins.json` change, idle background sessions are respawned (`claude respawn`), up to 3 per tick. Busy ones wait for a later tick, and terminal sessions get one notification to run `/reload-plugins`. No interface runs a slash command inside another session.
9
+ - **Records and alerts.** Results go to `status.json` (last snapshot), `state.json` (active findings, recovery attempts, plugin fingerprint) and `events.jsonl` (raise/clear/resume/respawn history) under `~/.muggle-ai/watch/`. New alerts raise one desktop notification per tick.
10
+
11
+ ## Install (Windows)
12
+
13
+ Requires the global package (`npm install -g @muggleai/works`), plus `claude` and `gh` on PATH.
14
+
15
+ ```powershell
16
+ & "$(npm root -g)\@muggleai\works\scripts\muggle-watch\install-muggle-watch.ps1"
17
+ ```
18
+
19
+ | Flag | Effect |
20
+ | :--- | :----- |
21
+ | `-IntervalMinutes <n>` | Tick interval, default 2 |
22
+ | `-NoRecovery` | Report dead watchers without resuming their owners |
23
+ | `-NoAutoReload` | Never start a reload fan-out on a plugin change |
24
+ | `-MuggleEntry <path>` | Run a specific `bin\muggle.js` instead of the global install |
25
+ | `-Uninstall` | Remove the task; the ledger is kept |
26
+
27
+ Re-running the installer replaces the task in place. The task runs `wscript.exe` on a copied shim, so no console window flashes. Its output goes to `~/.muggle-ai/watch/tick.log`.
28
+
29
+ ## macOS / Linux
30
+
31
+ There is no installer yet. Add a crontab line:
32
+
33
+ ```sh
34
+ */2 * * * * muggle watch tick >> ~/.muggle-ai/watch/tick.log 2>&1
35
+ ```
36
+
37
+ ## Commands
38
+
39
+ ```sh
40
+ muggle watch status # last snapshot: sessions, processes, PR watches, findings
41
+ muggle watch tick # one pass now
42
+ muggle watch reload-plugins # reload plugins across sessions now (--dry-run to preview)
43
+ muggle watch register --slot <dir> # opt a slot into recovery
44
+ muggle watch unregister --slot <dir> # keep a slot session-scoped
45
+ ```
@@ -0,0 +1,92 @@
1
+ # Installs the MuggleWatch scheduled task for the current user (no elevation):
2
+ # every -IntervalMinutes it runs `muggle watch tick`, which snapshots Claude and
3
+ # Codex sessions, their processes and every PR-watch slot, alerts on dead or deaf
4
+ # watchers, red CI and stale branches, resumes the owner session of a registered
5
+ # slot whose watcher died, and fans plugin reloads out across sessions.
6
+ #
7
+ # The task runs the global @muggleai/works install, whose path survives
8
+ # `muggle upgrade`, so the service always runs the current release. Only the
9
+ # launcher shim is copied, to ~\.muggle-ai\watch\bin, so the task never points
10
+ # into a checkout or worktree that may be deleted.
11
+ [CmdletBinding()]
12
+ param(
13
+ [ValidateRange(1, 60)]
14
+ [int]$IntervalMinutes = 2,
15
+ [string]$TaskName = "MuggleWatch",
16
+ [string]$MuggleEntry,
17
+ [switch]$NoAutoReload,
18
+ [switch]$NoRecovery,
19
+ [switch]$Uninstall
20
+ )
21
+
22
+ $ErrorActionPreference = "Stop"
23
+
24
+ if ($Uninstall) {
25
+ if (Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue) {
26
+ Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false
27
+ "task $TaskName removed; ledger kept at $(Join-Path $env:USERPROFILE '.muggle-ai\watch')"
28
+ } else {
29
+ "task $TaskName is not installed"
30
+ }
31
+ return
32
+ }
33
+
34
+ if (-not $MuggleEntry) {
35
+ $npmRoot = (& npm root -g 2>$null | Select-Object -First 1)
36
+ if ($npmRoot) { $MuggleEntry = Join-Path $npmRoot "@muggleai\works\bin\muggle.js" }
37
+ }
38
+ if (-not $MuggleEntry -or -not (Test-Path $MuggleEntry)) {
39
+ throw "No global @muggleai/works install found. Run 'npm install -g @muggleai/works', or pass -MuggleEntry <path to bin\muggle.js>."
40
+ }
41
+ $nodeCommand = Get-Command node -ErrorAction SilentlyContinue
42
+ if (-not $nodeCommand) { throw "node is not on PATH; the task needs it to run muggle." }
43
+ foreach ($requiredTool in @("claude", "gh")) {
44
+ if (-not (Get-Command $requiredTool -ErrorAction SilentlyContinue)) {
45
+ Write-Warning "$requiredTool is not on PATH — the watch will report without the data it provides."
46
+ }
47
+ }
48
+
49
+ $watchDir = Join-Path $env:USERPROFILE ".muggle-ai\watch"
50
+ $installDir = Join-Path $watchDir "bin"
51
+ New-Item -ItemType Directory -Force -Path $installDir | Out-Null
52
+ $installedLauncher = Join-Path $installDir "muggle-watch-hidden.vbs"
53
+ Copy-Item (Join-Path $PSScriptRoot "muggle-watch-hidden.vbs") $installedLauncher -Force
54
+
55
+ $tickFlags = @()
56
+ if ($NoAutoReload) { $tickFlags += "--no-auto-reload" }
57
+ if ($NoRecovery) { $tickFlags += "--no-recovery" }
58
+ $launcherArguments = @("`"$installedLauncher`"", "`"$($nodeCommand.Source)`"", "`"$MuggleEntry`"") + $tickFlags
59
+
60
+ # wscript.exe rather than node.exe is what keeps every run off the desktop — see
61
+ # the header of muggle-watch-hidden.vbs.
62
+ $taskAction = New-ScheduledTaskAction -Execute (Join-Path $env:SystemRoot "System32\wscript.exe") `
63
+ -Argument ($launcherArguments -join " ")
64
+ # Omitting RepetitionDuration is what makes the repetition indefinite; passing
65
+ # [TimeSpan]::MaxValue serializes to a duration Windows PowerShell 5.1 rejects.
66
+ $taskTrigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(1) `
67
+ -RepetitionInterval (New-TimeSpan -Minutes $IntervalMinutes)
68
+ # The battery switches matter on laptops: the defaults skip every run on battery.
69
+ $taskSettings = New-ScheduledTaskSettingsSet -MultipleInstances IgnoreNew -StartWhenAvailable `
70
+ -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries `
71
+ -ExecutionTimeLimit (New-TimeSpan -Minutes 10)
72
+ # -Force replaces the task in place: unregistering first would leave a window with
73
+ # no watch at all, and no watch for good if the registration then failed.
74
+ Register-ScheduledTask -TaskName $TaskName -Action $taskAction -Trigger $taskTrigger `
75
+ -Settings $taskSettings -Force `
76
+ -Description "Muggle watch service: tracks agent sessions, processes and PR watchers (@muggleai/works)" | Out-Null
77
+
78
+ $statusFile = Join-Path $watchDir "status.json"
79
+ $previousSnapshotTime = if (Test-Path $statusFile) { (Get-Item $statusFile).LastWriteTime } else { [DateTime]::MinValue }
80
+ Start-ScheduledTask -TaskName $TaskName
81
+ $deadline = (Get-Date).AddSeconds(120)
82
+ while ((Get-Date) -lt $deadline) {
83
+ if ((Test-Path $statusFile) -and (Get-Item $statusFile).LastWriteTime -gt $previousSnapshotTime) { break }
84
+ Start-Sleep -Seconds 2
85
+ }
86
+ $taskInfo = Get-ScheduledTaskInfo -TaskName $TaskName
87
+ "task $TaskName registered every $IntervalMinutes min; state=$((Get-ScheduledTask -TaskName $TaskName).State) lastResult=$($taskInfo.LastTaskResult)"
88
+ if ((Test-Path $statusFile) -and (Get-Item $statusFile).LastWriteTime -gt $previousSnapshotTime) {
89
+ "first tick written: $statusFile — run 'muggle watch status' to read it"
90
+ } else {
91
+ Write-Warning "no tick finished within 120s; check $(Join-Path $watchDir 'tick.log')"
92
+ }
@@ -0,0 +1,39 @@
1
+ ' Console-free launcher for `muggle watch tick`, used as the MuggleWatch task action.
2
+ '
3
+ ' node.exe is a console-subsystem binary, so launching it straight from the task
4
+ ' paints a console window on every run. wscript.exe is GUI-subsystem, and the
5
+ ' child it starts with intWindowStyle 0 is created hidden.
6
+ '
7
+ ' Arguments: <node.exe> <muggle.js> [extra tick flags...]
8
+ '
9
+ ' Output is appended to tick.log beside this script's install dir, capped at
10
+ ' 1 MB by starting over, since the snapshot and events ledger are the record and
11
+ ' the log only needs the recent failures. The Run call waits, so the task's
12
+ ' IgnoreNew overlap guard and LastTaskResult describe the tick, not this shim.
13
+ Option Explicit
14
+
15
+ Const LOG_CAP_BYTES = 1048576
16
+
17
+ Dim fileSystem, windowsShell, watchDir, logPath, nodePath, muggleEntry, tickFlags, argumentIndex, tickExitCode
18
+ Set fileSystem = CreateObject("Scripting.FileSystemObject")
19
+ Set windowsShell = CreateObject("WScript.Shell")
20
+
21
+ If WScript.Arguments.Count < 2 Then WScript.Quit 2
22
+ nodePath = WScript.Arguments(0)
23
+ muggleEntry = WScript.Arguments(1)
24
+ tickFlags = ""
25
+ For argumentIndex = 2 To WScript.Arguments.Count - 1
26
+ tickFlags = tickFlags & " " & WScript.Arguments(argumentIndex)
27
+ Next
28
+
29
+ watchDir = fileSystem.GetParentFolderName(fileSystem.GetParentFolderName(WScript.ScriptFullName))
30
+ logPath = watchDir & "\tick.log"
31
+ If fileSystem.FileExists(logPath) Then
32
+ If fileSystem.GetFile(logPath).Size > LOG_CAP_BYTES Then fileSystem.DeleteFile logPath
33
+ End If
34
+
35
+ tickExitCode = windowsShell.Run( _
36
+ "cmd.exe /d /s /c """"" & nodePath & """ """ & muggleEntry & """ watch tick" & tickFlags & " >> """ & logPath & """ 2>&1""", _
37
+ 0, True)
38
+
39
+ WScript.Quit tickExitCode