make-coord-episode14-demo.sh bash
119 lines 3.9 KB
Raw
sha256:5472be4fece32b606c308fad9d57295ce327955fb2b87b8beec6ea1626050473 Add published YouTube URL to Episode 00 Sonnet 5 1 hour ago
1 #!/usr/bin/env bash
2 # Builds coord-episode14/ (from-import) and coord-episode14-bare/ (bare-import
3 # contrast) — disposable repos demonstrating muse coord for Episode 14
4 # ("Agent Coordination"). Re-run to regenerate; never hand-edit the repo
5 # directories directly.
6 set -euo pipefail
7
8 HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9 REPO="$HERE/coord-episode14"
10 BARE_REPO="$HERE/coord-episode14-bare"
11
12 rm -rf "$REPO" "$BARE_REPO"
13
14 echo "=== Part 1: shard on a realistic (from-import) codebase ==="
15 mkdir -p "$REPO"
16 cd "$REPO"
17 muse init --json | python3 -m json.tool
18 cat > app.py <<'EOF'
19 from auth import login
20 from billing import charge
21
22 def handle_request(username, password, amount):
23 if login(username, password):
24 return charge(username, amount)
25 return None
26 EOF
27 cat > auth.py <<'EOF'
28 from db import query
29
30 def login(username, password):
31 row = query(f"SELECT * FROM users WHERE username='{username}'")
32 return row is not None
33 EOF
34 cat > billing.py <<'EOF'
35 from db import query
36
37 def charge(username, amount):
38 query(f"UPDATE accounts SET balance = balance - {amount} WHERE username='{username}'")
39 return True
40 EOF
41 cat > db.py <<'EOF'
42 def query(sql):
43 return None
44 EOF
45 muse code add .
46 muse commit -m "Initial: app, auth, billing, db (from-import style)" \
47 --agent-id claude-code --model-id claude-sonnet-5 --sign
48 echo "--- real call graph exists (impact) ---"
49 muse code impact "auth.py::login" --json | python3 -m json.tool
50 echo "--- shard claims zero coupling (BUG) ---"
51 muse coord shard --agents 2 --json | python3 -m json.tool
52
53 echo
54 echo "=== Part 2: same coupling, bare-import style — the honest contrast ==="
55 mkdir -p "$BARE_REPO"
56 cd "$BARE_REPO"
57 muse init --json | python3 -m json.tool
58 cat > app.py <<'EOF'
59 import auth
60 import billing
61
62 def handle_request(username, password, amount):
63 if auth.login(username, password):
64 return billing.charge(username, amount)
65 return None
66 EOF
67 cat > auth.py <<'EOF'
68 import db
69
70 def login(username, password):
71 return db.query("SELECT 1") is not None
72 EOF
73 cat > billing.py <<'EOF'
74 import db
75
76 def charge(username, amount):
77 db.query("UPDATE accounts SET balance = balance - 1")
78 return True
79 EOF
80 cat > db.py <<'EOF'
81 def query(sql):
82 return None
83 EOF
84 muse code add .
85 muse commit -m "Initial: bare-import style" \
86 --agent-id claude-code --model-id claude-sonnet-5 --sign
87 echo "--- shard correctly refuses to split coupled code ---"
88 muse coord shard --agents 2 --json | python3 -m json.tool
89
90 echo
91 echo "=== Part 3: reservations — real conflict detection ==="
92 muse coord reserve "app.py::handle_request" --run-id agent-1 --op modify --json | python3 -m json.tool
93 muse coord reserve "app.py::handle_request" --run-id agent-2 --op modify --json | python3 -m json.tool
94 echo "--- forecast: predicted conflict, confidence 1.0 ---"
95 muse coord forecast --json | python3 -m json.tool
96
97 echo
98 echo "=== Part 4: the task queue — atomic claims across two agents ==="
99 muse coord enqueue "Refactor billing.charge to support partial refunds" --run-id orch --json | python3 -m json.tool
100 muse coord enqueue "Add rate limiting to auth.login" --run-id orch --json | python3 -m json.tool
101 echo "--- agent-1 claims ---"
102 muse coord claim --run-id agent-1 --json | python3 -m json.tool
103 echo "--- agent-2 claims (gets the OTHER task, not a collision) ---"
104 muse coord claim --run-id agent-2 --json | python3 -m json.tool
105 echo "--- a third agent finds the queue empty ---"
106 muse coord claim --run-id agent-3 --json | python3 -m json.tool || true
107
108 echo
109 echo "=== Part 5: reconcile — real merge-order recommendation across branches ==="
110 muse switch main
111 muse checkout -b feat/agent-a
112 muse coord reserve "app.py::handle_request" --run-id agent-1 --op modify --json > /dev/null
113 muse switch main
114 muse checkout -b feat/agent-b
115 muse coord reserve "app.py::handle_request" --run-id agent-2 --op modify --json > /dev/null
116 muse coord reconcile --json | python3 -m json.tool
117
118 echo
119 echo "Demo repos built at $REPO and $BARE_REPO"
File History 1 commit
sha256:5472be4fece32b606c308fad9d57295ce327955fb2b87b8beec6ea1626050473 Add published YouTube URL to Episode 00 Sonnet 5 1 hour ago