1 ---
2 name: post_merge_setup
3 description: Maintain the post-merge setup script that runs automatically after task merges.
4 ---
5
6 # Post-Merge Setup
7
8 After a task is merged, two things run automatically:
9
10 1. Setup script — installs dependencies, runs migrations, rebuilds.
11 2. Workflow reconciliation — stops workflows removed from `.replit` and restarts already running workflows.
12
13 If either step fails, the agent will be alerted about the issue, and should fix it immediately.
14
15 ## What Runs Automatically
16
17 The system runs the configured post-merge script from the project root with bash.
18 Stdin is closed (`/dev/null`), so commands that prompt for input will get EOF and fail immediately. The full Nix environment is available on PATH.
19
20 If the script does not exist, setup fails and you are asked to create it.
21
22 The script has a configurable timeout. If the script takes longer, it is killed and setup fails with a timeout error.
23
24 After the script, workflow reconciliation syncs running workflows with the current `.replit` config.
25
26 ## Available Commands
27
28 ### Get the post-merge config
29
30 ```javascript
31 const config = await getPostMergeConfig();
32 console.log(config);
33 // { scriptPath: "...", timeoutMs: ... }
34 ```
35
36 Returns the configured script path and timeout from `.replit`. If not yet configured, both fields will be `null`.
37
38 ### Set post-merge config
39
40 ```javascript
41 await setPostMergeConfig({ scriptPath: "scripts/post-merge.sh", timeoutMs: 180000 });
42 ```
43
44 Sets the post-merge script path and/or timeout. Both parameters are optional — only provided values are updated. Note: `scriptPath` must be set (either already configured or provided in the same call) before setting `timeoutMs` alone, because `.replit` requires `path` in the `[postMerge]` section. Use `timeoutMs` when:
45
46 - The script timed out — if the script naturally takes a long time (large `npm install`, slow migrations), increase the timeout so it succeeds on the next merge. Estimate a reasonable value from the script's expected runtime and add a buffer (e.g. if `npm install` takes 3s, set timeout to 5000 ms).
47 - The script hangs — if the script hangs due to a bug (e.g. waiting for input), fix the script first, then consider lowering the timeout to catch future hangs early.
48
49 ### Run post-merge setup
50
51 ```javascript
52 const result = await runPostMergeSetup();
53 console.log(result);
54 ```
55
56 Runs the post-merge script and workflow reconciliation. Returns `{ success, setupError, reconciliationError, scriptPath, stdoutPath, stderrPath, durationMs, timeoutMs }`.
57
58 - `setupError` / `reconciliationError`: what failed
59 - `scriptPath`: path to the post-merge script that was executed
60 - `stdoutPath` / `stderrPath`: full log file paths
61 - `durationMs` / `timeoutMs`: how long it ran and the configured timeout
62
63 The tail of the stdout/stderr log files (last 10 lines with line numbers) is automatically opened into your context after the call.
64
65 ## Fixing Failures
66
67 When setup fails:
68
69 1. **Check the log files** opened into your context after the call (last 10 lines of stdout/stderr with line numbers). The `scriptPath` in the result tells you which script was executed.
70 2. **Fix the script** — create it if missing, update it if broken.
71 3. **If it timed out**, increase the timeout with `setPostMergeConfig({ timeoutMs: ... })` based on how long the script actually needs.
72 4. **Retry** with `runPostMergeSetup()` to confirm the fix works.
73
74 If workflow reconciliation fails, use the workflows skill to check and restart affected workflows.
75
76 Common failure causes:
77
78 - Missing script -> use the `scriptPath` from the result (or call `getPostMergeConfig()`) to find the expected path, then create the script there.
79 - Script timed out -> increase timeout with `setPostMergeConfig({ timeoutMs: ... })`, or optimize the script.
80 - A command prompts for input (stdin is closed, so it gets EOF and fails) -> use non-interactive flags (`--yes`, `--force`, `-y`, etc.).
81 - A dependency or migration command fails -> fix the command or the underlying config.
82
83 ## Writing the Post-Merge Script
84
85 Use the `scriptPath` from the last `runPostMergeSetup()` result if available. Otherwise, call `getPostMergeConfig()` to find the script location.
86
87 Example:
88
89 ```bash
90 #!/bin/bash
91 set -e
92
93 pnpm install
94 pnpm --filter @workspace/db run push-force
95 ```
96
97 Guidelines:
98
99 - Idempotent. Safe to run multiple times.
100 - Non-interactive. Stdin is closed. Use `--yes` / `--force` flags.
101 - Fail fast. Use `set -e`.
102 - Keep it fast. Runs while the user waits. If it takes more than 2 minutes, consider optimizing or increasing the timeout.