#!/usr/bin/env bash # Builds shelf-episode15/ (working handoff) and shelf-episode15-bug/ (the # staged+unstaged data-loss repro) for Episode 15 ("Shelves"). Re-run to # regenerate; never hand-edit the repo directories directly. set -euo pipefail HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO="$HERE/shelf-episode15" BUG_REPO="$HERE/shelf-episode15-bug" rm -rf "$REPO" "$BUG_REPO" echo "=== Part 1: a real handoff between two agents ===" mkdir -p "$REPO" cd "$REPO" muse init --json | python3 -m json.tool cat > pipeline.py <<'EOF' def extract(source): return source def transform(data): return data def load(data, target): return True EOF muse code add . muse commit -m "Initial pipeline scaffold" --agent-id claude-code --model-id claude-sonnet-5 --sign echo "--- agent-1 gets interrupted mid-task ---" cat > pipeline.py <<'EOF' def extract(source): return source def transform(data): # TODO: normalize whitespace, dedupe, then... cleaned = data.strip() return cleaned def load(data, target): return True EOF muse shelf save --by claude-code --intent-type interrupt \ -m "mid-refactor of transform(), was about to add dedupe logic" --resumable echo "--- working tree is clean; the work is safely shelved, not lost ---" muse status --json | python3 -c "import json,sys; print('clean:', json.load(sys.stdin)['clean'])" echo "--- agent-2 discovers resumable work with zero shared memory ---" muse shelf list --resumable --json | python3 -m json.tool echo "--- agent-2 reads it, then pops it to continue ---" muse shelf read main/000 --json | python3 -m json.tool muse shelf pop main/000 cat pipeline.py echo echo "=== Part 2: already-current detection (real accounting, not a silent no-op) ===" muse code add pipeline.py muse commit -m "Add dedupe TODO marker" --agent-id claude-code --model-id claude-sonnet-5 --sign cat > utils.py <<'EOF' def normalize(s): return s.lower() EOF cat > pipeline.py <<'EOF' def extract(source): return source def transform(data): cleaned = data.strip() deduped = list(dict.fromkeys(cleaned.split())) return " ".join(deduped) def load(data, target): return True EOF muse code add pipeline.py utils.py muse shelf save --by claude-code --intent-type handoff -m "dedupe logic done, needs review" --resumable echo "--- someone else independently commits the exact same utils.py content ---" cat > utils.py <<'EOF' def normalize(s): return s.lower() EOF muse code add utils.py muse commit -m "Add normalize() helper (independently, same content)" --agent-id claude-code --model-id claude-sonnet-5 --sign echo "--- apply: utils.py is already_current, pipeline.py is genuinely restored ---" muse shelf apply main/000 --json | python3 -m json.tool echo echo "=== Part 3: the honest part -- data loss when staged + unstaged changes mix ===" mkdir -p "$BUG_REPO" cd "$BUG_REPO" muse init --json | python3 -m json.tool echo "line A" > file_a.txt echo "line B" > file_b.txt muse code add . muse commit -m "Initial" --agent-id claude-code --model-id claude-sonnet-5 --sign echo "--- file_a.txt gets a real, unstaged edit ---" echo "line A -- EDITED, UNSTAGED" > file_a.txt echo "--- file_b.txt gets a real, staged edit (unrelated) ---" echo "line B -- EDITED, STAGED" > file_b.txt muse code add file_b.txt echo "--- shelf save claims success ---" muse shelf save --by claude-code --intent-type checkpoint -m "repro" --json | python3 -m json.tool echo "--- but the shelf only contains file_b.txt ---" muse shelf read main/000 --json | python3 -c "import json,sys; print('shelved files:', json.load(sys.stdin)['files'])" echo "--- and file_a.txt's real edit is gone from disk ---" cat file_a.txt echo echo "Demo repos built at $REPO and $BUG_REPO"