make-shelf-episode15-demo.sh bash
117 lines 3.7 KB
Raw
sha256:1d5e65b757b4fcf4653bdcaf9ba2d64df62222a1503dfc0c15a9db45f09feade Add Episode 15 script (Shelves) and shelf demo builder Sonnet 5 patch 18 hours ago
1 #!/usr/bin/env bash
2 # Builds shelf-episode15/ (working handoff) and shelf-episode15-bug/ (the
3 # staged+unstaged data-loss repro) for Episode 15 ("Shelves"). Re-run to
4 # regenerate; never hand-edit the repo directories directly.
5 set -euo pipefail
6
7 HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8 REPO="$HERE/shelf-episode15"
9 BUG_REPO="$HERE/shelf-episode15-bug"
10
11 rm -rf "$REPO" "$BUG_REPO"
12
13 echo "=== Part 1: a real handoff between two agents ==="
14 mkdir -p "$REPO"
15 cd "$REPO"
16 muse init --json | python3 -m json.tool
17 cat > pipeline.py <<'EOF'
18 def extract(source):
19 return source
20
21 def transform(data):
22 return data
23
24 def load(data, target):
25 return True
26 EOF
27 muse code add .
28 muse commit -m "Initial pipeline scaffold" --agent-id claude-code --model-id claude-sonnet-5 --sign
29
30 echo "--- agent-1 gets interrupted mid-task ---"
31 cat > pipeline.py <<'EOF'
32 def extract(source):
33 return source
34
35 def transform(data):
36 # TODO: normalize whitespace, dedupe, then...
37 cleaned = data.strip()
38 return cleaned
39
40 def load(data, target):
41 return True
42 EOF
43 muse shelf save --by claude-code --intent-type interrupt \
44 -m "mid-refactor of transform(), was about to add dedupe logic" --resumable
45
46 echo "--- working tree is clean; the work is safely shelved, not lost ---"
47 muse status --json | python3 -c "import json,sys; print('clean:', json.load(sys.stdin)['clean'])"
48
49 echo "--- agent-2 discovers resumable work with zero shared memory ---"
50 muse shelf list --resumable --json | python3 -m json.tool
51
52 echo "--- agent-2 reads it, then pops it to continue ---"
53 muse shelf read main/000 --json | python3 -m json.tool
54 muse shelf pop main/000
55 cat pipeline.py
56
57 echo
58 echo "=== Part 2: already-current detection (real accounting, not a silent no-op) ==="
59 muse code add pipeline.py
60 muse commit -m "Add dedupe TODO marker" --agent-id claude-code --model-id claude-sonnet-5 --sign
61 cat > utils.py <<'EOF'
62 def normalize(s):
63 return s.lower()
64 EOF
65 cat > pipeline.py <<'EOF'
66 def extract(source):
67 return source
68
69 def transform(data):
70 cleaned = data.strip()
71 deduped = list(dict.fromkeys(cleaned.split()))
72 return " ".join(deduped)
73
74 def load(data, target):
75 return True
76 EOF
77 muse code add pipeline.py utils.py
78 muse shelf save --by claude-code --intent-type handoff -m "dedupe logic done, needs review" --resumable
79
80 echo "--- someone else independently commits the exact same utils.py content ---"
81 cat > utils.py <<'EOF'
82 def normalize(s):
83 return s.lower()
84 EOF
85 muse code add utils.py
86 muse commit -m "Add normalize() helper (independently, same content)" --agent-id claude-code --model-id claude-sonnet-5 --sign
87
88 echo "--- apply: utils.py is already_current, pipeline.py is genuinely restored ---"
89 muse shelf apply main/000 --json | python3 -m json.tool
90
91 echo
92 echo "=== Part 3: the honest part -- data loss when staged + unstaged changes mix ==="
93 mkdir -p "$BUG_REPO"
94 cd "$BUG_REPO"
95 muse init --json | python3 -m json.tool
96 echo "line A" > file_a.txt
97 echo "line B" > file_b.txt
98 muse code add .
99 muse commit -m "Initial" --agent-id claude-code --model-id claude-sonnet-5 --sign
100
101 echo "--- file_a.txt gets a real, unstaged edit ---"
102 echo "line A -- EDITED, UNSTAGED" > file_a.txt
103 echo "--- file_b.txt gets a real, staged edit (unrelated) ---"
104 echo "line B -- EDITED, STAGED" > file_b.txt
105 muse code add file_b.txt
106
107 echo "--- shelf save claims success ---"
108 muse shelf save --by claude-code --intent-type checkpoint -m "repro" --json | python3 -m json.tool
109
110 echo "--- but the shelf only contains file_b.txt ---"
111 muse shelf read main/000 --json | python3 -c "import json,sys; print('shelved files:', json.load(sys.stdin)['files'])"
112
113 echo "--- and file_a.txt's real edit is gone from disk ---"
114 cat file_a.txt
115
116 echo
117 echo "Demo repos built at $REPO and $BUG_REPO"
File History 1 commit
sha256:1d5e65b757b4fcf4653bdcaf9ba2d64df62222a1503dfc0c15a9db45f09feade Add Episode 15 script (Shelves) and shelf demo builder Sonnet 5 patch 18 hours ago