Business operating system for Claude Code — 57 skills, 21 agents, smart daemon. Unified inbox (WhatsApp/Email/Slack/Telegram), autonomous PR merge, full-AWS monitoring, revenue (Stripe+RevenueCat), e-commerce (Shopify), marketing (Klaviyo/Meta/GA4), voice (Bland/ElevenLabs), APM (Datadog/NewRelic/OTEL), YOLO mode.
Shell agent-teamsai-agentai-automationanthropicautonomous-agentawsbusiness-operationsclaudeclaude-codeclaude-code-plugindevopsecommerceinbox-zeroklaviyomarketingmcpmorning-briefingpr-automationshopifyterminal
Harden ops-merge Phase 0 salvage against stale worktree overwrites (#823)
Copilot19508b006c3e
diff --git a/claude-ops/skills/ops-merge/SKILL.md b/claude-ops/skills/ops-merge/SKILL.mdindex 6b240396..648fa009 100644--- a/claude-ops/skills/ops-merge/SKILL.md+++ b/claude-ops/skills/ops-merge/SKILL.md@@ -159,20 +159,30 @@ If the work lives only on a local branch (no worktree), create one:For each finding:1. cd into the worktree.2. Inspect state: `git status`, `git log <integration>..HEAD --oneline`, `git diff --stat`.- 3. Read recent commit messages + any TODOs/HEREs in the diff. Decide whether the work is:+ 3. **Stale-copy guard (mandatory, per candidate file before commit):**+ - Set `BASE=$(git merge-base HEAD origin/<integration_branch>)`.+ - List files you plan to salvage from the worktree.+ - For each file `<f>`:+ - If `git diff --quiet "$BASE..origin/<integration_branch>" -- "<f>"` is **false** (integration changed `<f>` since base), treat `<f>` as high risk.+ - For high-risk files, inspect both sides before staging:+ - `git diff "$BASE..origin/<integration_branch>" -- "<f>"`+ - `git diff "$BASE..HEAD" -- "<f>"`+ - Only stage hunks that are genuinely new work from the salvage branch. Do **not** stage a wholesale file replacement that drops integration-side hunks.+ - If you cannot prove the salvage branch is newer for `<f>`, mark the finding `aborted_for_review` (do not commit the file).+ 4. Read recent commit messages + any TODOs/HEREs in the diff. Decide whether the work is:(a) complete and just needs commit/push/PR — proceed(b) incomplete but obvious next step — finish it(c) ambiguous or risky → ABORT this finding and return it for human review.- 4. If finishing work: make the smallest correct commit. Quality gate locally+ 5. If finishing work: make the smallest correct commit. Quality gate locally(per-repo: type-check + lint + relevant tests).- 5. Commit with a clear message. NEVER use --no-verify unless a hook is genuinely+ 6. Commit with a clear message. NEVER use --no-verify unless a hook is genuinelybroken and unrelated to your change.- 6. Push: `git push -u origin <branch>` (or `--force-with-lease` if branch already remote).- 7. Open PR (only if has_open_pr=false in the brief):+ 7. Push: `git push -u origin <branch>` (or `--force-with-lease` if branch already remote).+ 8. Open PR (only if has_open_pr=false in the brief):gh pr create --repo <repo> --base <integration_branch> --head <branch> \--title "<derived from commit messages>" \--body "Salvaged by /ops:merge Phase 0. <commit summary>"- 8. Return structured JSON:+ 9. Return structured JSON:{"repo": "...","branch": "...",@@ -513,6 +523,7 @@ During this command's execution, invoke the following superpower skills at the s- **NEVER auto-delete a local branch, worktree, or stash** — even if classified `branch-already-merged`. Always surface to the user via `AskUserQuestion`.- **NEVER `git stash drop` or `git checkout -- <file>` or `git clean`** in any checkout — uncommitted work is the user's, not the agent's, until they confirm.- **NEVER auto-commit ambiguous changes.** If a salvager can't tell whether work is complete, it MUST return `aborted_for_review` and let the user decide.+- **NEVER commit stale snapshots over integration branch progress.** If integration branch and salvage branch both changed a file since merge-base, stage only provably new hunks (or abort for review).- **NEVER share the main checkout between salvager subagents.** Per CLAUDE.md worktree isolation: each agent gets its own `.worktrees/salvage-<branch>` dir. Sharing the main checkout causes branch-switch collisions.- **NEVER force-push a branch the salvager didn't originate work on** — salvagers may only push with `--force-with-lease` to branches whose tip they fetched at start of work.- **NEVER salvage main/master/dev** — those are integration branches; loose work on them surfaces to the user, never auto-pushed.diff --git a/claude-ops/tests/test-ops-merge-salvage-safety.sh b/claude-ops/tests/test-ops-merge-salvage-safety.shnew file mode 100755index 00000000..12ee5f2b--- /dev/null+++ b/claude-ops/tests/test-ops-merge-salvage-safety.sh@@ -0,0 +1,34 @@+#!/usr/bin/env bash+# test-ops-merge-salvage-safety.sh — Guardrails for Phase 0 stale-copy prevention.+set -euo pipefail++ROOT="$(cd "$(dirname "$0")/.." && pwd)"+SKILL="$ROOT/skills/ops-merge/SKILL.md"+PASS=0+FAIL=0++pass() { echo " PASS: $1"; PASS=$((PASS + 1)); }+fail() { echo " FAIL: $1"; FAIL=$((FAIL + 1)); }++assert_contains() {+ local label="$1" pattern="$2"+ if grep -Fq "$pattern" "$SKILL"; then+ pass "$label"+ else+ fail "$label"+ fi+}++echo "== ops-merge salvage stale-copy safety =="+assert_contains "documents stale-copy guard step" "Stale-copy guard (mandatory, per candidate file before commit)"+assert_contains "uses merge-base against integration branch" 'BASE=$(git merge-base HEAD origin/<integration_branch>)'+assert_contains "checks integration-side file movement" 'git diff --quiet "$BASE..origin/<integration_branch>" -- "<f>"'+assert_contains "requires hunk-level staging" "Only stage hunks that are genuinely new work from the salvage branch"+assert_contains "aborts when freshness is unprovable" 'If you cannot prove the salvage branch is newer for `<f>`, mark the finding `aborted_for_review`'+assert_contains "safety rails forbid stale snapshot commits" "NEVER commit stale snapshots over integration branch progress"++echo "---"+echo "Results: $PASS passed, $FAIL failed"+if (( FAIL > 0 )); then+ exit 1+fi