@muggleai/works 5.24.0 → 5.25.0-staging.184

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 (66) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/README.md +1 -0
  3. package/dist/{chunk-FEHTWWVH.js → chunk-BJGZAKBB.js} +234 -5
  4. package/dist/{chunk-GLTZIZVT.js → chunk-CE5HUVNQ.js} +26 -2
  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/agents/test-prepare-runner.md +3 -3
  13. package/dist/plugin/skills/_shared/dev-loop/run.md +4 -1
  14. package/dist/plugin/skills/_shared/post-merge-cleanup.md +7 -6
  15. package/dist/plugin/skills/_shared/pr-branch-worktree.md +7 -6
  16. package/dist/plugin/skills/_shared/sync-branch-with-base.md +39 -4
  17. package/dist/plugin/skills/_shared/use-worktrees.md +12 -6
  18. package/dist/plugin/skills/do/e2e-acceptance.md +1 -1
  19. package/dist/plugin/skills/do/pre-flight.md +1 -1
  20. package/dist/plugin/skills/do/wave-e2e.md +2 -2
  21. package/dist/plugin/skills/muggle-preferences/preference-gates/autoRebase.md +3 -3
  22. package/dist/plugin/skills/muggle-test/execute-local.md +2 -2
  23. package/dist/plugin/skills/muggle-test-feature-local/SKILL.md +3 -8
  24. package/dist/plugin/skills/muggle-test-prepare/SKILL.md +42 -29
  25. package/dist/plugin/skills/muggle-test-prepare/steps/check-running.md +25 -10
  26. package/dist/plugin/skills/muggle-test-prepare/steps/e2e-instructions.md +1 -1
  27. package/dist/plugin/skills/muggle-test-prepare/steps/env-file.md +8 -5
  28. package/dist/plugin/skills/muggle-test-prepare/steps/readiness-report.md +22 -18
  29. package/dist/plugin/skills/muggle-test-prepare/steps/rebase-check.md +13 -1
  30. package/dist/plugin/skills/muggle-test-prepare/steps/replay-or-learn.md +2 -2
  31. package/dist/plugin/skills/muggle-test-prepare/steps/resolve-sources.md +39 -0
  32. package/dist/plugin/skills/muggle-test-prepare/steps/reuse-plan.md +7 -5
  33. package/dist/plugin/skills/muggle-test-prepare/steps/smoke-test.md +2 -2
  34. package/dist/plugin/skills/muggle-test-prepare/steps/start-services.md +4 -4
  35. package/dist/release-manifest.json +3 -3
  36. package/dist/src-BYDDPSF6.js +1 -0
  37. package/package.json +2 -2
  38. package/plugin/.claude-plugin/plugin.json +1 -1
  39. package/plugin/.codex-mcp.json +1 -1
  40. package/plugin/.codex-plugin/plugin.json +1 -1
  41. package/plugin/.cursor-plugin/plugin.json +1 -1
  42. package/plugin/.mcp.json +1 -1
  43. package/plugin/agents/test-prepare-runner.md +3 -3
  44. package/plugin/skills/_shared/dev-loop/run.md +4 -1
  45. package/plugin/skills/_shared/post-merge-cleanup.md +7 -6
  46. package/plugin/skills/_shared/pr-branch-worktree.md +7 -6
  47. package/plugin/skills/_shared/sync-branch-with-base.md +39 -4
  48. package/plugin/skills/_shared/use-worktrees.md +12 -6
  49. package/plugin/skills/do/e2e-acceptance.md +1 -1
  50. package/plugin/skills/do/pre-flight.md +1 -1
  51. package/plugin/skills/do/wave-e2e.md +2 -2
  52. package/plugin/skills/muggle-preferences/preference-gates/autoRebase.md +3 -3
  53. package/plugin/skills/muggle-test/execute-local.md +2 -2
  54. package/plugin/skills/muggle-test-feature-local/SKILL.md +3 -8
  55. package/plugin/skills/muggle-test-prepare/SKILL.md +42 -29
  56. package/plugin/skills/muggle-test-prepare/steps/check-running.md +25 -10
  57. package/plugin/skills/muggle-test-prepare/steps/e2e-instructions.md +1 -1
  58. package/plugin/skills/muggle-test-prepare/steps/env-file.md +8 -5
  59. package/plugin/skills/muggle-test-prepare/steps/readiness-report.md +22 -18
  60. package/plugin/skills/muggle-test-prepare/steps/rebase-check.md +13 -1
  61. package/plugin/skills/muggle-test-prepare/steps/replay-or-learn.md +2 -2
  62. package/plugin/skills/muggle-test-prepare/steps/resolve-sources.md +39 -0
  63. package/plugin/skills/muggle-test-prepare/steps/reuse-plan.md +7 -5
  64. package/plugin/skills/muggle-test-prepare/steps/smoke-test.md +2 -2
  65. package/plugin/skills/muggle-test-prepare/steps/start-services.md +4 -4
  66. package/dist/src-3MQ2UWSP.js +0 -1
@@ -6,15 +6,27 @@ Bring the working branch up to date with the branch it merges into — before a
6
6
 
7
7
  `base` is the branch the work merges into, which is not automatically the remote default — pre-flight lets the user target a different branch, and once a change exists its `baseRefName` is authoritative. A caller holding a base passes it in; fall back to the remote default only when no target was chosen.
8
8
 
9
- **Fire only when `behind > 0`:**
9
+ ## Checking freshness
10
+
11
+ `muggle checkout-freshness` fetches the base and returns one verdict. Run it in the checkout:
10
12
 
11
13
  ```bash
12
- git fetch origin
13
14
  base="${base:-$(git symbolic-ref refs/remotes/origin/HEAD --short | sed 's|origin/||')}"
14
- behind=$(git rev-list --count "HEAD..origin/${base}")
15
+ muggle checkout-freshness --base "${base}" --json
15
16
  ```
16
17
 
17
- Pass `{behind}` and `{base}` to the picker prompts. On `always`:
18
+ | Verdict | Meaning | Action |
19
+ | :------ | :------ | :----- |
20
+ | `FRESH` | HEAD contains `origin/${base}` | None |
21
+ | `NOT_APPLICABLE` | Not a git checkout, no `origin`, or no such base | None — nothing to check |
22
+ | `BEHIND_BASE` | HEAD lacks `behindBy` commits of `origin/${base}` | [Rebase](#rebasing) |
23
+ | `FOREIGN_BASE` | The branch was cut from another branch's unmerged commits (`inheritedCommits`) | [Stop](#foreign-base) |
24
+
25
+ Pass `{behind}` (the report's `behindBy`) and `{base}` to the picker prompts. A report with `hasFetchFailed: true` judged against the last fetched base — say so in one line and act on the verdict.
26
+
27
+ ## Rebasing
28
+
29
+ On `always`:
18
30
 
19
31
  1. Capture the rollback point: `pre_rebase_sha=$(git rev-parse HEAD)`.
20
32
  2. `git rebase origin/${base}`.
@@ -22,6 +34,29 @@ Pass `{behind}` and `{base}` to the picker prompts. On `always`:
22
34
  - `never` → `git rebase --abort`; stop and report, naming the conflicted files. Never auto-resolve.
23
35
  - `always` → hand off to [`resolve-rebase-conflicts.md`](resolve-rebase-conflicts.md) with `pre_rebase_sha` to resolve the conflicts, then run the [`verify-or-rollback-gate.md`](verify-or-rollback-gate.md) with `pre_rebase_sha`; it either proceeds or restores `pre_rebase_sha` and escalates.
24
36
 
37
+ A dev server already running from this checkout still serves the pre-rebase code: restart it before testing.
38
+
39
+ ## Before a dev server or E2E run
40
+
41
+ The code under test always contains the latest `origin/${base}`. `autoRebase` decides only whether the rebase happens without asking, never whether stale code runs:
42
+
43
+ - `always` → rebase.
44
+ - `ask` → Picker 1. `Rebase first` rebases; `Don't rebase` stops the run.
45
+ - `never` → stop the run.
46
+
47
+ A stop names the checkout, the verdict and `behindBy`, and starts nothing. There is no run-as-is: a stale tree produces false failures and false greens, and the local execute tools refuse a stale loopback run regardless, so running as-is only moves the failure later.
48
+
49
+ ## Foreign base
50
+
51
+ `FOREIGN_BASE` stops the run or push whatever `autoRebase` says — a rebase would carry the inherited commits along. Report the branch they came from and `inheritedCommits`. The fix is a decision about someone else's work, so it is the user's:
52
+
53
+ - Recreate the branch with `origin/${base}` as its explicit start point and carry over only the change's own commits.
54
+ - Or, when the change deliberately stacks on that branch, name it as the base and re-check.
55
+
56
+ ## Before a push
57
+
58
+ `BEHIND_BASE` → rebase per `autoRebase`; on `never` the push goes ahead as-is, and the remote's merge checks own that decision. `FOREIGN_BASE` → [stop](#foreign-base).
59
+
25
60
  ## Branches already on the remote
26
61
 
27
62
  The rebase rewrites history, so a branch the remote already has needs a force-push to land it. Never force-push from here. A caller in that position hands the sync to its own rebase mode, which owns the per-SHA attempt budget and the verify-or-rollback gate wrapped around the force-push.
@@ -10,13 +10,18 @@ Use this for feature development, local validation, and PR iteration.
10
10
 
11
11
  ## Start new change work
12
12
 
13
- 1. Update the base branch (usually `main`).
14
- 2. Create a new worktree and branch:
13
+ Every new branch starts at the latest `origin/<base>` — never at HEAD, never at a local branch. The directory a session stands in may be a detached main checkout months old, or a sibling worktree on someone else's feature branch; a branch created without a start point silently inherits that code. A local `<base>` branch is no better: it is often checked out, stale, in another worktree.
14
+
15
+ 1. Resolve `<main-root>` — the clone's main working tree, the first `worktree` line of `git worktree list --porcelain` — and `<base>` (the change's target branch; the remote default when none was chosen).
16
+ 2. Fetch and create from the remote-tracking ref:
15
17
  ```bash
16
- git worktree add <repo>/.claude/worktrees/<sanitized-branch> -b <branch>
18
+ git -C <main-root> fetch --no-tags origin "+refs/heads/<base>:refs/remotes/origin/<base>"
19
+ git -C <main-root> worktree add <main-root>/.claude/worktrees/<sanitized-branch> -b <branch> origin/<base>
17
20
  ```
18
- 3. Install dependencies and run setup in that worktree.
19
- 4. Keep all edits and commits for the change in that same worktree.
21
+ Under `<main-root>` even when the session stands in another worktree, so worktrees never nest.
22
+ 3. Confirm with `muggle checkout-freshness --cwd <worktree>` — it must report `FRESH`.
23
+ 4. Install dependencies and run setup in that worktree.
24
+ 5. Keep all edits and commits for the change in that same worktree.
20
25
 
21
26
  ## Test in the worktree
22
27
 
@@ -27,7 +32,7 @@ Use this for feature development, local validation, and PR iteration.
27
32
 
28
33
  ## E2E + worktree checklist
29
34
 
30
- 1. Confirm command cwd, checked-out branch, and server source are the same worktree.
35
+ 1. Confirm command cwd, checked-out branch, and server source are the same worktree, and that the worktree is still on the latest base per [`sync-branch-with-base.md`](sync-branch-with-base.md).
31
36
  2. Start the app from that worktree and verify readiness first (see [`dev-server-readiness.md`](dev-server-readiness.md)).
32
37
  3. Run local E2E acceptance checks in that same session.
33
38
  4. Isolate test data across parallel branches (separate users/accounts/orgs or resettable fixtures).
@@ -39,6 +44,7 @@ Use this for feature development, local validation, and PR iteration.
39
44
  - **Port collision:** Multiple branches share a dev-server port.
40
45
  - **Shared mutable state:** Parallel runs mutate the same account or fixtures.
41
46
  - **Stale server:** Old process still serves previous branch code.
47
+ - **Inherited base:** A branch created from whatever HEAD the session stood on carries that checkout's age or another branch's commits.
42
48
 
43
49
  ## Pull request workflow
44
50
 
@@ -69,7 +69,7 @@ For a `local-e2e` block, use `localUrl`, `projectId`, and the working-tree path
69
69
 
70
70
  A `local-e2e` cycle runs these before any `muggle-local-execute-*` call, every cycle — even when pre-flight already reported the app ready, since a server can die while stages 2–5 run and a healthy one fast-exits:
71
71
 
72
- 1. **Dev-server + backend readiness** — invoke [`muggle-test-prepare`](../muggle-test-prepare/SKILL.md), the readiness/service-start owner (idempotent fast-exit when healthy; probes via `dev-server-readiness.md` and starts what is down). Still not ready after its start attempts → the readiness halt below.
72
+ 1. **Dev-server + backend readiness** — invoke [`muggle-test-prepare`](../muggle-test-prepare/SKILL.md) from the cycle's worktree, passing the PR target as `base` — the readiness/service-start owner (idempotent fast-exit when healthy; probes via `dev-server-readiness.md` and starts what is down). It syncs the worktree onto the latest base before starting anything, and serves every other repo from its latest default branch. Its readiness table must show the cycle's worktree as the `Source` of the changed repo's services, at the worktree's current HEAD; any other source is not ready. Still not ready after its start attempts → the readiness halt below.
73
73
  2. **Auth** — `muggle-remote-auth-status` must be `authenticated`; else escalate.
74
74
  3. **Identity tenant/domain match** — if test credentials were marked `existing`, confirm the repo's configured identity tenant/domain matches the recorded tenant/domain. Mismatch → halt.
75
75
 
@@ -34,7 +34,7 @@ Before asking anything, gather every fact you can resolve without the user:
34
34
  8. **Auth0 tenant in use for local dev.** Grep the repo's env file for `*AUTH0_DOMAIN*`; record the tenant. This tells the user whether the staging-tenant test user will work or not.
35
35
  9. **Branch hygiene signals** for the `autoUseWorktree` and `autoRebase` gates (see [`../_shared/use-worktrees.md`](../_shared/use-worktrees.md), [`../_shared/sync-branch-with-base.md`](../_shared/sync-branch-with-base.md)):
36
36
  - Is the current checkout already a worktree? `git -C <repo> rev-parse --is-inside-work-tree` plus `git -C <repo> worktree list`.
37
- - How many commits behind `origin/<default>`? `git -C <repo> fetch origin && git -C <repo> rev-list --count "HEAD..origin/$(git -C <repo> symbolic-ref refs/remotes/origin/HEAD --short | sed 's|origin/||')"`.
37
+ - Is the current checkout on the latest base? `muggle checkout-freshness --cwd <repo> --json` fetches and reports the verdict and `behindBy`. However stale or foreign the current checkout, a new worktree starts from `origin/<base>`, never from it.
38
38
  10. **`autoE2ETest` preference.** Read the session-context preferences line. Unset → treat as `always` (this gate's default — opposite of the system-wide `ask` default). `ask` → surface in Q13. `always` → no question; stage 6 runs.
39
39
  11. **Wave candidate?** Two or more candidate repos, one PR each, and validation leaning `local-e2e` → the cycle is a wave per [`wave-e2e.md`](wave-e2e.md): the repos' services start together from their branches and one E2E run covers every PR. Record each repo's worktree path for the `Wave members` block. Not a wave → note why.
40
40
  12. **CI check present?** For each GitHub repo, whether `.github/workflows/muggle-walkthrough.yml` exists on its default branch. Missing and [`autoInstallCiWorkflow`](../muggle-preferences/preference-gates/autoInstallCiWorkflow.md) resolves to `ask` → surface in Q14.
@@ -34,8 +34,8 @@ The worktree path is where that repo's wave branch is checked out — the path i
34
34
 
35
35
  Run [`e2e-acceptance.md`](e2e-acceptance.md) **once**, not once per repo, with these changes:
36
36
 
37
- 1. **Start the wave stack.** Invoke [`muggle-test-prepare`](../muggle-test-prepare/SKILL.md) with the wave members as `directoryOverrides` (repo → worktree path): every service whose repo is a wave member starts from that member's worktree path, not from the repo's usual checkout. Services from repos outside the wave start as the saved recipe says.
38
- 2. **Confirm each wave service runs the wave branch.** A port that answers is not enough — the process on it may be a dev server the user left running from the default checkout. Check the readiness table: every wave service must report its member's worktree as its directory. A service that doesn't → halt and escalate with the table; never test a wave against a service running another branch.
37
+ 1. **Start the wave stack.** Invoke [`muggle-test-prepare`](../muggle-test-prepare/SKILL.md) with the wave members as `directoryOverrides` (repo → worktree path): every service whose repo is a wave member starts from that member's worktree path, synced onto its base first, not from the repo's usual checkout. Services from repos outside the wave start from that repo's base checkout on its latest default branch.
38
+ 2. **Confirm each wave service runs the wave branch.** A port that answers is not enough — the process on it may be a dev server the user left running from the default checkout. Check the readiness table: every wave service must report its member's worktree as its `Source`, at that worktree's current HEAD. A service that doesn't → halt and escalate with the table; never test a wave against a service running another branch.
39
39
  3. **Merge every member's scope.** Steps 1.5–3 read impact analysis for every wave repo, and the run's scope is the union of each member's `e2eScope`: a test case several members scope runs once, and a new case two members plan for the same criterion is created once. `EMPTY_DIFF` applies only when every member's diff is empty.
40
40
  4. **Run each selected test case once** against the combined stack. Do not repeat a case per repo.
41
41
  5. **Attribute failures.** For each Failed entry, name the member whose change the failing step implicates (`implicatedRepo: <owner/repo>`), or `unknown` when the evidence does not point at one. Stage 7.5 repairs in that repo.
@@ -1,11 +1,11 @@
1
1
  # `autoRebase`
2
2
 
3
- Sync onto `origin/{base}` before dev servers / E2E and before a push, or run as-is. Substitute `{behind}` and `{base}`.
3
+ Sync onto `origin/{base}` before dev servers / E2E and before a push, without asking. Stale code is never tested: before a dev server or E2E run, not rebasing stops the run. Substitute `{behind}` and `{base}`.
4
4
 
5
5
  **Picker 1** — header `Rebase first`, question `"Branch is {behind} commits behind origin/{base} — rebase first?"`
6
6
  - `Rebase first` — `Pull in the base branch's changes so the run reflects the merged main line.` → `always`
7
- - `Run as-is` — `Skip the rebase.` → `never`
7
+ - `Don't rebase` — `Leave the branch as it is. A dev server or E2E run stops instead of testing stale code; a push goes ahead.` → `never`
8
8
 
9
9
  **Silent action**
10
10
  - `always` → `Rebasing onto origin/{base} ({behind} behind)`
11
- - `never` → `Running as-is ({behind} behind origin/{base})`
11
+ - `never` → `Not rebasing ({behind} behind origin/{base}) — a dev server or E2E run stops here`
@@ -10,7 +10,7 @@
10
10
 
11
11
  ## Local environment readiness
12
12
 
13
- Before anything else, invoke [`muggle-test-prepare`](../muggle-test-prepare/SKILL.md) — the readiness/service-start owner (idempotent; halt on what it surfaces). The URL gate below only *selects* the target; prepare is what guarantees something is listening and compiled.
13
+ Before anything else, invoke [`muggle-test-prepare`](../muggle-test-prepare/SKILL.md) from `cwd` — the readiness/service-start owner (idempotent; halt on what it surfaces). It syncs `cwd` onto the latest base before starting anything, and serves every other repo from its latest default branch. The URL gate below only *selects* the target; prepare is what guarantees the right code is listening and compiled. Confirm its readiness table shows `cwd` as the `Source` of this repo's services, at `cwd`'s current HEAD — a different source means the run would test someone else's code; halt.
14
14
 
15
15
  Then read `~/.muggle-ai/e2e-instructions/<key>.md` when it exists — this stack's recorded startup order, manual steps, and local gotchas. Use it to interpret what you see: a gotcha listed there explains a symptom that would otherwise read as a failure. Absent is normal.
16
16
 
@@ -40,7 +40,7 @@ Execute each test case via the shared loop in [`../_shared/dev-loop/run.md`](../
40
40
 
41
41
  Caller glue:
42
42
  - `mode` per test case is the input from the router; `localUrl` from the pre-flight question; `showUi` from the `showElectronBrowser` resolution.
43
- - `cwd` is the input from the router — it drives the cross-worktree single-flight lock so concurrent muggle-test runs from different branches serialize.
43
+ - `cwd` is the input from the router — it drives the cross-worktree single-flight lock so concurrent muggle-test runs from different branches serialize, and the execute tools refuse it when it is not on the latest base. For a PR whose base is not the remote default, pass its `baseRefName` as `baseBranch`.
44
44
  - On a failed run, continue the batch; the router routes failures through the debug path after this path returns.
45
45
 
46
46
  ## Collect results
@@ -26,12 +26,12 @@ The local URL only changes where the browser opens; it does not change the remot
26
26
  Three gates apply, each per the standard procedure in [`preference-gates/README.md`](../muggle-preferences/preference-gates/README.md):
27
27
 
28
28
  - `autoUseWorktree` at pre-flight (see [`_shared/use-worktrees.md`](../_shared/use-worktrees.md)).
29
- - `autoRebase` before Step 7 (Execute) when `behind > 0` (see [`_shared/sync-branch-with-base.md`](../_shared/sync-branch-with-base.md)).
29
+ - `autoRebase` before any service starts — `muggle-test-prepare` syncs the checkout first — and again before Step 7 (Execute) when the base moved meanwhile, re-invoking `muggle-test-prepare` after that rebase so the dev server serves it. Stale code is never tested (see [`_shared/sync-branch-with-base.md`](../_shared/sync-branch-with-base.md)).
30
30
  - `autoCleanup` after the PR is merged (see [`_shared/post-merge-cleanup.md`](../_shared/post-merge-cleanup.md)).
31
31
 
32
32
  ## Local environment prerequisites
33
33
 
34
- Before any workflow step, invoke [`muggle-test-prepare`](../muggle-test-prepare/SKILL.md). Halt on what it surfaces.
34
+ Before any workflow step, invoke [`muggle-test-prepare`](../muggle-test-prepare/SKILL.md) from the checkout under test. Halt on what it surfaces — a checkout it cannot bring onto the latest base included.
35
35
 
36
36
  Then read `~/.muggle-ai/e2e-instructions/<key>.md` when it exists — this stack's recorded startup order, manual steps, and local gotchas. A gotcha listed there explains a symptom that would otherwise read as a failure. Absent is normal.
37
37
 
@@ -112,12 +112,7 @@ Prompt for projects: "Pick the project to group this test into:"
112
112
 
113
113
  ### 3. Ensure Local Services Are Ready
114
114
 
115
- Before detecting the local URL, verify that the services the user needs are actually running. Use the `muggle:muggle-test-prepare` integration contract:
116
-
117
- 1. Check if `/tmp/muggle-test-prepare.json` exists.
118
- 2. If it exists, verify tracked PIDs are alive with `kill -0`.
119
- 3. If all live → services are ready, proceed to Step 4 (Local URL).
120
- 4. If the file is missing or has stale PIDs → invoke the `muggle:muggle-test-prepare` skill via the `Skill` tool to get services started. Once it completes, proceed to Step 4.
115
+ Before detecting the local URL, invoke the `muggle:muggle-test-prepare` skill via the `Skill` tool from the checkout under test — every run, even when services look up. Live PIDs prove nothing about which code they serve: prepare syncs this checkout onto the latest base, starts sibling services from base checkouts on the latest default branch, and keeps a running service only when it still serves the right commit. It fast-exits when everything is proven. Once it reports ready, check its readiness table: this checkout's services must show this checkout as their `Source` at its current HEAD. Then proceed to Step 4.
121
116
 
122
117
  This step is especially important when the user's app depends on sibling services (a backend API, an auth service, etc.) that may not be running yet. The prepare skill handles discovery, startup, and cleanup so this skill doesn't have to.
123
118
 
@@ -26,42 +26,46 @@ This skill touches the user's local machine — processes, ports, directories ou
26
26
 
27
27
  ## PID Tracking
28
28
 
29
- All launched processes are tracked in `/tmp/muggle-test-prepare.json`:
29
+ Every launched process is tracked by the **checkout it runs from**, one file per checkout, so parallel sessions never share — or tear down — each other's state:
30
+
31
+ ```
32
+ ~/.muggle-ai/prepare/running/<source-key>.json services started from that checkout
33
+ ~/.muggle-ai/prepare/logs/<source-key>/<name>.log their logs
34
+ ```
35
+
36
+ `<source-key>` is the checkout root's absolute path, made filename-safe exactly as the E2E instructions key is ([e2e-instructions](./steps/e2e-instructions.md#resolve-the-saved-file)).
30
37
 
31
38
  ```json
32
39
  {
33
- "session_started": "2025-01-15T10:30:00Z",
34
- "testing_scope": "frontend",
35
- "excluded_services": [
36
- {"name": "payment-gateway", "reason": "Needs production certificates"}
37
- ],
40
+ "source": "/Users/user/Github/app/.claude/worktrees/feat-x",
38
41
  "services": [
39
42
  {
40
- "name": "backend-api",
41
- "dir": "/Users/user/Github/backend-api",
43
+ "name": "frontend",
44
+ "dir": "/Users/user/Github/app/.claude/worktrees/feat-x/web",
42
45
  "command": "npm run dev",
43
46
  "pid": 12345,
44
- "port": 3001,
45
- "log": "/tmp/muggle-prepare-backend-api.log"
47
+ "port": 3999,
48
+ "headSha": "9f8e7d6c5b4a39281706f5e4d3c2b1a098f7e6d5",
49
+ "startedAt": "2026-10-22T10:30:00Z",
50
+ "log": "/Users/user/.muggle-ai/prepare/logs/-Users-user-Github-app-.claude-worktrees-feat-x/frontend.log"
46
51
  }
47
52
  ]
48
53
  }
49
54
  ```
50
55
 
51
- `testing_scope` records what the user is testing (from [scope](./steps/scope.md)). `excluded_services` records services the user said can't run locally (from [viability-check](./steps/viability-check.md)).
56
+ `headSha` is the commit the checkout had out when the service started — what [check-running](./steps/check-running.md) compares against before trusting a listener. These files are machine-wide and readable by every session: they are how one session learns that a port belongs to another.
52
57
 
53
- This file is **ephemeral runtime state**, not the saved recipe. The durable plan lives in `~/.muggle-ai/prepare-plans.json`, under the entry keyed on this stack, and is consulted in [reuse-plan](./steps/reuse-plan.md) before any other stage. The two files never merge. The `test-prepare-runner` agent writes this file during execution; the triage below and Cleanup read it.
58
+ This is **ephemeral runtime state**, not the saved recipe. The durable plan lives in `~/.muggle-ai/prepare-plans.json`, under the entry keyed on this stack, and is consulted in [reuse-plan](./steps/reuse-plan.md) before any other stage. The two never merge. The `test-prepare-runner` agent writes the tracking files during execution; Cleanup reads them.
54
59
 
55
60
  The prose companion to the plan is `~/.muggle-ai/e2e-instructions/<key>.md`, written by [e2e-instructions](./steps/e2e-instructions.md), holding startup order, manual steps, and local gotchas. The plan remains the single source of truth for each service's start command; the markdown never restates one.
56
61
 
57
62
  **Everything this skill saves is machine-local, user-level data and lives under the Muggle home directory — never inside the user's project.** A project directory is shared, versioned, and cloned onto machines set up differently; a local run recipe is none of those things. Both files are keyed on the same stack identity, so they stay in lockstep.
58
63
 
59
- **On every invocation**, check this file first. If it exists with live PIDs (verify with `kill -0`), `AskUserQuestion`:
60
- - Option 1: "Keep them running — skip to testing"
61
- - Option 2: "Tear down and start fresh"
62
- - Option 3: "Add more services to the running set"
64
+ **On every invocation**, prune dead PIDs from the tracking files silently (verify with `kill -0`). Whether a live service is kept is never asked: [check-running](./steps/check-running.md) keeps one still serving its checkout's current HEAD and restarts one serving older code.
65
+
66
+ ## Code freshness
63
67
 
64
- Prune dead PIDs silently.
68
+ Every service runs code built on the latest base: the caller's own checkout, synced onto `origin/<base>`, for the repo under test; a base checkout pinned to the latest `origin/<default>` for every other repo. [rebase-check](./steps/rebase-check.md) and [resolve-sources](./steps/resolve-sources.md) run on **every** invocation, replays included — a saved recipe makes the start commands reusable, never the code they start.
65
69
 
66
70
  ## Preferences
67
71
 
@@ -69,7 +73,7 @@ Gates run per [`preference-gates/README.md`](../muggle-preferences/preference-ga
69
73
 
70
74
  | Preference | Gates |
71
75
  |------------|-------|
72
- | `autoRebase` | [rebase-check](./steps/rebase-check.md) — rebase onto `origin/<default>` before starting dev servers |
76
+ | `autoRebase` | [rebase-check](./steps/rebase-check.md) — rebase onto `origin/<base>` without asking before starting dev servers; not rebasing stops the run |
73
77
  | `reusePreparePlan` | [reuse-plan](./steps/reuse-plan.md) — reuse the saved prepare plan for this stack, or rediscover; also [e2e-instructions](./steps/e2e-instructions.md), which goes stale for the same reason |
74
78
  | `autoSelectLocalHost` | [check-running](./steps/check-running.md) — reuse the recorded dev-server URL silently, or confirm it each run |
75
79
 
@@ -85,13 +89,16 @@ Decide stages, in order; read each detail file when you reach it:
85
89
  |:------|:--------|
86
90
  | [replay-or-learn](./steps/replay-or-learn.md) | Replay the saved recipe, or learn a new one |
87
91
  | [derive-service-graph](./steps/derive-service-graph.md) | Derive services from workspace manifests |
88
- | [rebase-check](./steps/rebase-check.md) | Rebase onto default branch |
92
+ | [rebase-check](./steps/rebase-check.md) | Sync every checkout under test onto the latest base — replays too |
93
+ | [resolve-sources](./steps/resolve-sources.md) | Pick the checkout each service runs from — replays too |
89
94
  | [scope](./steps/scope.md) | Frontend / backend / full stack |
90
95
  | [viability-check](./steps/viability-check.md) | Exclude services that can't run locally |
91
96
  | [identify-services](./steps/identify-services.md) | Confirm the derived graph; fill the gaps |
92
97
  | [e2e-instructions](./steps/e2e-instructions.md) | Startup order, manual steps, local gotchas |
93
98
 
94
- The Decide phase's output is the **resolved prepare plan**: `services[]` (name, dir, start command, expected port, `external` flag, approval granted), `testingScope`, `excludedServices[]`, the recorded dev-server URL, the E2E run instructions, and resolved gate outcomes.
99
+ The Decide phase's output is the **resolved prepare plan**: `services[]` (name, run directory from [resolve-sources](./steps/resolve-sources.md), start command, expected port, `external` flag, approval granted), `testingScope`, `excludedServices[]`, the recorded dev-server URL, the E2E run instructions, and resolved gate outcomes.
100
+
101
+ A replay runs [rebase-check](./steps/rebase-check.md) and [resolve-sources](./steps/resolve-sources.md) before dispatching — they ask nothing unless a checkout cannot be brought up to date.
95
102
 
96
103
  **Execute (agent).** Dispatch the `test-prepare-runner` agent (subagent type `muggle:test-prepare-runner`; bare `test-prepare-runner` where the plugin namespace is absent), synchronously, passing the resolved plan; it returns `READY` / `DEGRADED` plus the readiness table. The agent's own definition lists its stage files; in a harness with no agent/subagent facility, run the execute-phase stages ([check-running](./steps/check-running.md) through [readiness-report](./steps/readiness-report.md)) inline instead.
97
104
 
@@ -103,13 +110,14 @@ The agent also returns the problems it hit and what cleared them. On a learning
103
110
 
104
111
  Triggered when the user says "stop services", "tear down", "clean up", "I'm done testing", another skill signals run complete, or this skill is re-invoked with "tear down and start fresh". Runs in-session, not in the agent.
105
112
 
106
- 1. Read `/tmp/muggle-test-prepare.json`
113
+ Cleanup stops only what runs from the caller's own checkout. Another checkout's services may be mid-run in a peer session, and base-checkout services are shared — they stay up unless the user explicitly asks to stop everything.
114
+
115
+ 1. Read the caller's checkout's tracking file (see [PID Tracking](#pid-tracking))
107
116
  2. Skip services marked `external: true`
108
117
  3. For each managed service: `kill <pid>` (SIGTERM)
109
118
  4. Wait ~2 s, verify with `kill -0`
110
119
  5. If still alive: `kill -9 <pid>`
111
- 6. `rm -f /tmp/muggle-prepare-*.log`
112
- 7. `rm -f /tmp/muggle-test-prepare.json`
120
+ 6. Delete that checkout's log directory and tracking file
113
121
 
114
122
  Report:
115
123
 
@@ -126,12 +134,15 @@ Stopped 3 services:
126
134
 
127
135
  After a test run, the caller can re-invoke for cleanup or leave services running for the next run.
128
136
 
129
- **Directory overrides.** A caller testing changes that span several repos at once may pass `directoryOverrides`: a map from a service's repo (its usual directory, or `owner/repo`) to the checkout that service must start from this run — typically a worktree on a feature branch. Apply them to the resolved plan before execution:
137
+ **The caller's checkout.** Invoke from the checkout under test — the worktree the change lives in. Its repo is the repo under test, and its services start from that checkout; every other repo's services start from that repo's base checkout ([resolve-sources](./steps/resolve-sources.md)). Pass `base` when the change targets a branch other than the remote default.
130
138
 
131
- - An overridden service starts from the override directory, with its recorded start command. Its install and env-file steps run there too.
132
- - An overridden service already listening counts as running only when its process's working directory is inside the override directory (`lsof -p <pid> -a -d cwd` on POSIX). Otherwise it is the wrong checkout: stop it and start it from the override, under the same approval rules as any restart.
139
+ **Directory overrides.** A caller testing changes that span several repos at once may pass `directoryOverrides`: a map from a service's repo (its usual directory, or `owner/repo`) to the checkout that service must start from this run — typically a worktree on a feature branch. Each override makes its repo a repo under test, exactly like the caller's own checkout:
140
+
141
+ - An overridden service starts from the override directory, with its recorded start command. Its install and env-file steps run there too, and [rebase-check](./steps/rebase-check.md) syncs the override first.
142
+ - An overridden service already listening counts as running only when [check-running](./steps/check-running.md) proves it serves the override's current HEAD. Otherwise it is the wrong checkout: it is never tested against, and is restarted from the override under the same approval rules as any restart.
133
143
  - Overrides are per-run. They never enter the saved recipe — a worktree path is not this stack's durable layout.
134
- - The readiness table names the directory each service runs from, so the caller can confirm every override took.
144
+
145
+ The readiness table names the directory and commit each service runs from, so the caller can confirm its own code is the code being served.
135
146
 
136
147
  ## Guardrails
137
148
 
@@ -142,11 +153,13 @@ After a test run, the caller can re-invoke for cleanup or leave services running
142
153
  - **Never start a process the user didn't approve** — approvals are granted in Decide and travel in the plan; the agent starts nothing outside it.
143
154
  - **Never read file contents outside confirmed directories** — folder names are discoverable; file contents require explicit user selection.
144
155
  - **Never write a credential into the E2E run instructions** — plaintext notes are not a secret store, and this is the file a user pastes when asking why their stack won't start. Record the env-var or secret name, never its value.
145
- - **Never leave orphan processes untracked** — every background PID goes into the tracking file.
156
+ - **Never leave orphan processes untracked** — every background PID goes into its checkout's tracking file.
146
157
  - **Never kill a process the user started independently** — `external: true` survives cleanup.
158
+ - **Never kill or test against another checkout's service** — a listener tracked under a different checkout belongs to a peer session; see [check-running](./steps/check-running.md).
159
+ - **Never start code that is not on the latest base** — no replay, preference, or approval skips [rebase-check](./steps/rebase-check.md) or [resolve-sources](./steps/resolve-sources.md).
147
160
  - **Never assume start commands** — verify via indicator file; confirm with user.
148
161
  - **Bail early on non-viable services** — don't start what can't run locally.
149
- - **Idempotent** — already-tracked alive services are kept; [smoke-test](./steps/smoke-test.md) still runs against them.
162
+ - **Idempotent** — a tracked, alive service still serving its checkout's current HEAD is kept; [smoke-test](./steps/smoke-test.md) still runs against it.
150
163
  - **Port-listening is never enough** — smoke-test (HTTP + body sniff + log tail) is mandatory before the final report.
151
164
  - **Clean Restart is the recommended fix** — first option in the smoke-test diagnose-and-fix loop; lint/build/missing-deps issues need nuke-and-reinstall.
152
165
  - **Fresh install is automatic** — [fresh-install](./steps/fresh-install.md) notifies, doesn't ask.
@@ -13,29 +13,44 @@ The resolved host fixes the **expected** dev-server port for the detection below
13
13
 
14
14
  ## Detect listening services
15
15
 
16
- Run port detection and (when an app declares a backend URL) backend-health probe per [`../../_shared/dev-server-readiness.md`](../../_shared/dev-server-readiness.md). Cross-reference hits against selected service directories.
16
+ Run port detection and (when an app declares a backend URL) backend-health probe per [`../../_shared/dev-server-readiness.md`](../../_shared/dev-server-readiness.md).
17
17
 
18
- > "**backend-api** is already listening on port 3001 (PID 54321) — looks good."
18
+ ## Prove what each listener serves
19
19
 
20
- If **all** required services are running, skip straight to [smoke-test](./smoke-test.md) — don't trust port-listening alone.
20
+ A port that answers proves nothing about which code answers it — a peer session's dev server, or last week's, answers just as well. Judge every listener on a service's port against the tracking files ([PID Tracking](../SKILL.md#pid-tracking)) and the service's run directory and commit from [resolve-sources](./resolve-sources.md):
21
21
 
22
- If some are running, acknowledge and continue to [start-commands](./start-commands.md) only for the missing ones. **Exception:** when this stage is entered via the [reuse-plan](./reuse-plan.md) short-circuit, the missing entries already have their `command` populated in `/tmp/muggle-test-prepare.json` from the reused plan — skip `start-commands` and go straight to [env-file](./env-file.md). For already-running services:
23
- - Option 1: "It's fine, keep it"
24
- - Option 2: "Restart it"
22
+ | Listener | Verdict |
23
+ | :------- | :------ |
24
+ | A tracking entry with this port, a live PID, `dir` = the run directory and `headSha` = the commit it must serve | **Proven** — keep it. A base-checkout service a peer started is proven the same way, and shared |
25
+ | The plan marks the service `external: true` | **Vouched** — the user confirmed in Decide that they run it from this checkout; keep it, never kill it |
26
+ | Tracked under the run directory's checkout at an older `headSha` | **Stale** — restart it per [start-services](./start-services.md) |
27
+ | Tracked under a different checkout, PID alive | **A peer's** — never test against it, never kill it; [Port already held](#port-already-held) |
28
+ | Untracked | **Unknown code** — when the plan approves a restart for this service, treat it as stale: Clean Restart it through [smoke-test](./smoke-test.md)'s loop (kill → [fresh-install](./fresh-install.md) → [start-services](./start-services.md) → re-test). Otherwise [Port already held](#port-already-held) |
25
29
 
26
- Mark kept services as `external: true` in the tracking file so cleanup leaves them alone.
30
+ An approved restart settles whose port it is. When the restart cannot free or claim the port — the old process survives the kill, or the port keeps answering with code this run did not start — the service is broken, not contested: it stays in the smoke-test loop and ends `DEGRADED` with that diagnosis, never `needs-input`. `DEGRADED` already stops the caller from testing, so nothing foreign is ever reported `READY`. [Port already held](#port-already-held) is only for a peer's service, or for unknown code the plan gives no restart approval for.
31
+
32
+ > "**backend-api** on port 3001 (PID 54321) serves `api/.claude/worktrees/base-main` @ `a1b2c3d` — proven."
33
+
34
+ If **all** required services are proven or vouched, skip straight to [smoke-test](./smoke-test.md) — don't trust port-listening alone.
35
+
36
+ Otherwise continue to [start-commands](./start-commands.md) only for the services still missing. **Exception:** when this stage is entered via the [reuse-plan](./reuse-plan.md) short-circuit, the missing entries already carry their `command` from the reused plan — skip `start-commands` and go straight to [env-file](./env-file.md).
27
37
 
28
38
  ## Port already held
29
39
 
30
- When the user wants a port held by a process they did **not** select (typically a stale dev server from a sibling worktree):
40
+ When a port the run needs is held by a process this run may not touch — a peer's service, or unknown code with no restart approved:
41
+
42
+ The held process is likely something the user — or a parallel session — is still using. Don't auto-decide. In the agent, return `needs-input:` naming the port, the PID, and the checkout its tracking entry names (or "untracked"); the skill asks:
31
43
 
32
44
  The held process is likely something the user is still using — a current test or dev server they value more than this prepare run. Don't auto-decide; leave the kill-vs-pause call to them.
33
45
 
34
- > "Port 3999 is held by PID 87421 (you didn't select this process — it may be a test or dev server you're still using). How do you want to proceed?"
46
+ > "Port 3999 is held by PID 87421, serving `app/.claude/worktrees/feat-y` — not this change's code. How do you want to proceed?"
35
47
 
36
48
  - Option 1: "Use the next available port" (recommended — non-destructive, leaves the existing process running)
37
- - Option 2: "Force-kill PID 87421 and claim port 3999" (kill-switch — only if you don't need that process)
49
+ - Option 2: "Force-kill PID 87421 and claim port 3999" (kill-switch — only if nobody needs that process)
38
50
  - Option 3: "Pause — leave it running, I'll finish up and re-run prepare later"
51
+ - Option 4: "It's mine — I started it from `<run directory>`" (untracked listeners only) → mark the service `external: true` in the plan and record the listener in the run directory's tracking file at its current HEAD
52
+
53
+ Testing against a listener nobody can tie to this change's checkout is never an option: its results describe someone else's code.
39
54
 
40
55
  **Option 1**: probe `3999 + N` for `N = 1, 2, …` until nothing listens. Record the new port and any env file edit (`PORT=` in `.env.local` etc.). Dev server may need restart to pick up.
41
56
 
@@ -24,7 +24,7 @@ One file per stack:
24
24
  ~/.muggle-ai/e2e-instructions/<key>.md
25
25
  ```
26
26
 
27
- `<key>` is the absolute path of the working directory's parent — the same stack identity the global prepare plan keys its entries on — reduced to a filename-safe token by replacing every path separator, and any drive-letter colon, with `-`. Derive it from the resolved absolute path rather than assuming a separator character; they differ per platform.
27
+ `<key>` is the stack key from [reuse-plan](./reuse-plan.md) — the same stack identity the global prepare plan keys its entries on — reduced to a filename-safe token by replacing every path separator, and any drive-letter colon, with `-`. A file saved under an older key is adopted and renamed the same way the plan entry is. Derive it from the resolved absolute path rather than assuming a separator character; they differ per platform.
28
28
 
29
29
  Missing → no saved instructions; run the capture below.
30
30
 
@@ -2,11 +2,14 @@
2
2
 
3
3
  The env file is **per-repo** — don't hardcode `.env.local`. Detect by scanning `package.json` `scripts/*` for `.env*` literals and known port vars (`PORT=`, `VITE_PORT=`); check framework config (`next.config.*`, `vite.config.*`).
4
4
 
5
- When a dependency on an env file exists:
5
+ When a dependency on an env file exists, for each service's run directory ([resolve-sources](./resolve-sources.md)):
6
6
 
7
- 1. Check `<cwd>/<envfile>` exists — if yes, no-op.
8
- 2. If absent, `git worktree list --porcelain` and check each sibling for the same filename.
9
- 3. If found:
7
+ 1. Check `<run-dir>/<envfile>` exists — if yes, no-op.
8
+ 2. If absent and the repo's main working tree has it at the same sub-directory, copy it — notify, don't ask: it is the user's own config for this repo, and a fresh worktree or base checkout never carries one.
9
+
10
+ > "Copied `<envfile>` into `<run-dir>` from the main working tree."
11
+
12
+ 3. Otherwise `git worktree list --porcelain` and check each sibling for the same filename. If found:
10
13
 
11
14
  > "`<envfile>` is missing in this worktree but exists at `<sibling>/<envfile>`. Copy it before starting services?"
12
15
 
@@ -15,4 +18,4 @@ When a dependency on an env file exists:
15
18
 
16
19
  4. If not found anywhere, report and ask.
17
20
 
18
- Skip silently when no env file is referenced.
21
+ Never overwrite an env file that exists. Skip silently when no env file is referenced.
@@ -3,15 +3,17 @@
3
3
  Only after every service passes [smoke-test](./smoke-test.md) or is skipped.
4
4
 
5
5
  ```
6
- Service PID Port Status Smoke Test
7
- ─────────────────────────────────────────────────────────────────
8
- backend-api 12345 3001 Running ✓
9
- auth-service 12346 8080 Running ✓
10
- frontend 12347 3000 Running ✓
11
- ─────────────────────────────────────────────────────────────────
6
+ Service PID Port Source Commit Smoke Test
7
+ ──────────────────────────────────────────────────────────────────────────────────────────────────────
8
+ backend-api 12345 3001 ~/Github/api/.claude/worktrees/base-main a1b2c3d ✓
9
+ auth-service 12346 8080 ~/Github/auth/.claude/worktrees/base-main 4d5e6f7 (2 behind) ✓
10
+ frontend 12347 3000 ~/Github/app/.claude/worktrees/feat-x 9f8e7d6 ✓
11
+ ──────────────────────────────────────────────────────────────────────────────────────────────────────
12
12
  All services verified. Ready for E2E.
13
13
  ```
14
14
 
15
+ `Source` is the run directory's checkout and `Commit` the HEAD it serves — what the caller checks to confirm its own change is the code under test. A base checkout that could not be refreshed this run (a peer's run held the lock) shows how far it trails `origin/<default>`.
16
+
15
17
  Surface skipped services so the caller knows the gap:
16
18
 
17
19
  ```
@@ -21,7 +23,7 @@ Skipped: payment-gateway — HTTP 500 on /
21
23
  If you launched the services:
22
24
 
23
25
  ```
24
- Logs: /tmp/muggle-prepare-*.log
26
+ Logs: ~/.muggle-ai/prepare/logs/<source-key>/
25
27
  Cleanup: say "stop services" or re-invoke this skill.
26
28
  ```
27
29
 
@@ -31,19 +33,21 @@ Only on a learning run, and only once the user has accepted the gate in [confirm
31
33
 
32
34
  A replay run writes nothing here; it already has the recipe.
33
35
 
34
- Build the JSON from the in-memory tracking file, dropping runtime fields:
36
+ Build the JSON from the resolved plan, keeping only the durable fields:
35
37
 
36
- ```bash
37
- jq '{
38
- version: 1,
39
- updated: now | todate,
40
- testing_scope: .testing_scope,
41
- excluded_services: .excluded_services,
42
- services: [.services[] | {name, dir, command, port}]
43
- }' /tmp/muggle-test-prepare.json
38
+ ```json
39
+ {
40
+ "version": 1,
41
+ "updated": "<now, ISO-8601>",
42
+ "testing_scope": "<testingScope>",
43
+ "excluded_services": [{ "name": "…", "reason": "…" }],
44
+ "services": [{ "name": "…", "dir": "…", "command": "…", "port": 3000 }]
45
+ }
44
46
  ```
45
47
 
46
- Upsert it under the stack's key — the absolute path of the working directory's parent — in `~/.muggle-ai/prepare-plans.json`, creating the file as `{}` if missing. The plan is machine-local, user-level data: it never goes inside the user's project, and resolving it requires no version-control tool.
48
+ Each service's `dir` names its **repo**, never a checkout: the repo's main working-tree root plus the service's sub-directory — never a linked worktree or base-checkout path, which is a per-run choice [resolve-sources](./resolve-sources.md) makes again every time.
49
+
50
+ Upsert it under the stack key ([reuse-plan](./reuse-plan.md)) in `~/.muggle-ai/prepare-plans.json`, creating the file as `{}` if missing. The plan is machine-local, user-level data: it never goes inside the user's project.
47
51
 
48
52
  Then print, once:
49
53
 
@@ -52,7 +56,7 @@ Then print, once:
52
56
  (Disable with `/muggle-preferences reusePreparePlan`.)
53
57
  ```
54
58
 
55
- If this run short-circuited via [reuse-plan](./reuse-plan.md), don't rewrite — but **do** refresh `updated` and any `command` that was re-derived during validation. Skip the announcement on the refresh path.
59
+ If this run short-circuited via [reuse-plan](./reuse-plan.md), don't rewrite — but **do** refresh `updated`, any `command` re-derived during validation, any legacy `dir` normalized by [resolve-sources](./resolve-sources.md#legacy-plan-entries), and an adopted entry's key. Skip the announcement on the refresh path.
56
60
 
57
61
  ## Save the E2E run instructions
58
62
 
@@ -1,3 +1,15 @@
1
1
  # Rebase check
2
2
 
3
- Gated by `autoRebase`. Fire per [`../../_shared/sync-branch-with-base.md`](../../_shared/sync-branch-with-base.md) when `behind > 0`. Otherwise skip silently.
3
+ Runs on every invocation — learning runs and replays alike — before anything is checked or started: a saved recipe reuses start commands, never code.
4
+
5
+ Check each **checkout under test** — the caller's own checkout, plus every `directoryOverrides` checkout — and sync it per [`../../_shared/sync-branch-with-base.md`](../../_shared/sync-branch-with-base.md), which owns the verdicts and the `autoRebase` gate. Use the caller's `base` when it passed one:
6
+
7
+ ```bash
8
+ muggle checkout-freshness --cwd "<checkout>" --base "<base>" --json
9
+ ```
10
+
11
+ - `FRESH` / `NOT_APPLICABLE` → continue.
12
+ - `BEHIND_BASE` → rebase per the gate. Declined or `never` → stop the run before anything starts and report the checkout and `behindBy`.
13
+ - `FOREIGN_BASE` → stop, naming the inherited commits.
14
+
15
+ A stop on a replay is a [hard block](./confirm-recipe.md#hard-block): resolve it with the user. Every other repo's services run from a base checkout, which [resolve-sources](./resolve-sources.md) refreshes instead of syncing.
@@ -4,14 +4,14 @@ One decision, made before anything else: does a prepare recipe already exist for
4
4
 
5
5
  Resolve the recipe location per [confirm-recipe](./confirm-recipe.md).
6
6
 
7
- - **Recipe exists** → **replay run**. Skip straight to the execute phase and run it. No scan, no interview, no questions. The whole point of having learned is not to ask again.
7
+ - **Recipe exists** → **replay run**. Run [rebase-check](./rebase-check.md) and [resolve-sources](./resolve-sources.md), then go straight to the execute phase. No scan, no interview, no questions. The whole point of having learned is not to ask again.
8
8
  - **No recipe** → **learning run**. Run the Decide stages in order, then the single gate at the end.
9
9
 
10
10
  A recipe the user declined to save is the same as no recipe: the next run learns again. Declining is not a permanent no, it just means nothing was written.
11
11
 
12
12
  ## What a replay is allowed to do
13
13
 
14
- Execute the recorded steps, in the recorded order, using the recorded commands. When a step fails, consult the recipe's recorded resolutions **first** — a problem solved before is solved the same way again, without asking.
14
+ Execute the recorded steps, in the recorded order, using the recorded commands — from the checkouts [resolve-sources](./resolve-sources.md) picked this run, never the directories the recipe was learned in. When a step fails, consult the recipe's recorded resolutions **first** — a problem solved before is solved the same way again, without asking.
15
15
 
16
16
  Only a [hard block](./confirm-recipe.md#hard-block) permits a replay to deviate or prompt.
17
17