make-wire-episode17-demo.sh
bash
sha256:cb114a4ce48bc4c9f865774769ec9b6a3bb7ccb6a6f8792bbf5ae6f28b0a6f88
Add Episode 17 script (The Wire Protocol) and wire demo driver
Sonnet 5
patch
22 hours ago
| 1 | #!/usr/bin/env bash |
| 2 | # Builds wire-episode17/ and drives a real push/clone against the local |
| 3 | # MuseHub hub for Episode 17 ("The Wire Protocol"). Requires the local |
| 4 | # MuseHub dev stack running. Re-run to regenerate; never hand-edit the |
| 5 | # repo directory directly. |
| 6 | set -euo pipefail |
| 7 | |
| 8 | HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 9 | REPO="$HERE/wire-episode17" |
| 10 | CLONE_DIR="$HERE/wire-episode17-clone" |
| 11 | |
| 12 | rm -rf "$REPO" "$CLONE_DIR" |
| 13 | mkdir -p "$REPO" |
| 14 | cd "$REPO" |
| 15 | |
| 16 | muse init --json | python3 -m json.tool |
| 17 | echo "hello wire protocol" > README.md |
| 18 | muse code add . |
| 19 | muse commit -m "Initial commit for wire protocol demo" \ |
| 20 | --agent-id claude-code --model-id claude-sonnet-5 --sign |
| 21 | |
| 22 | echo |
| 23 | echo "=== Part 1: build a real wire mpack, parse it by hand ===" |
| 24 | COMMIT=$(muse rev-parse HEAD --json | python3 -c "import json,sys; print(json.load(sys.stdin)['commit_id'])") |
| 25 | python3 - "$COMMIT" <<'PY' |
| 26 | import sys, struct, hashlib, pathlib |
| 27 | sys.path.insert(0, str(pathlib.Path.home() / "ecosystem" / "muse")) |
| 28 | from muse.core.mpack import build_mpack, build_wire_mpack |
| 29 | |
| 30 | commit_id = sys.argv[1] |
| 31 | root = pathlib.Path(".") |
| 32 | mpack = build_mpack(root, [commit_id], have=set()) |
| 33 | wire = build_wire_mpack(mpack, meta={"repo_id": "demo", "branch": "main", "head_commit_id": commit_id}) |
| 34 | pathlib.Path("wire.mpack").write_bytes(wire) |
| 35 | |
| 36 | print("total wire size:", len(wire), "bytes") |
| 37 | print("header (hex):", wire[:6].hex(' ')) |
| 38 | version, section_count = struct.unpack_from("<BB", wire, 4) |
| 39 | print(f"magic={wire[:4]!r} version={version} section_count={section_count}") |
| 40 | |
| 41 | names = {1: "BLOBS", 2: "COMMITS", 3: "SNAPSHOTS", 4: "TAGS", 5: "META"} |
| 42 | cursor = 6 |
| 43 | for i in range(section_count): |
| 44 | sec_type = wire[cursor] |
| 45 | sec_offset, sec_length = struct.unpack_from("<QQ", wire, cursor + 1) |
| 46 | print(f" [{i}] type={sec_type} ({names.get(sec_type)}) offset={sec_offset} length={sec_length}") |
| 47 | cursor += 17 |
| 48 | |
| 49 | footer = wire[-32:] |
| 50 | computed = hashlib.sha256(wire[:-32]).digest() |
| 51 | print("footer match:", footer == computed) |
| 52 | PY |
| 53 | |
| 54 | echo |
| 55 | echo "=== Part 2: tamper with one byte, confirm the footer catches it ===" |
| 56 | python3 - <<'PY' |
| 57 | import sys, pathlib |
| 58 | sys.path.insert(0, str(pathlib.Path.home() / "ecosystem" / "muse")) |
| 59 | from muse.core.mpack import parse_wire_mpack |
| 60 | |
| 61 | data = bytearray(pathlib.Path("wire.mpack").read_bytes()) |
| 62 | data[200] ^= 0xFF |
| 63 | try: |
| 64 | parse_wire_mpack(bytes(data)) |
| 65 | print("NO ERROR RAISED -- would be a bug") |
| 66 | except Exception as e: |
| 67 | print(f"Correctly rejected: {type(e).__name__}: {e}") |
| 68 | PY |
| 69 | rm -f wire.mpack |
| 70 | |
| 71 | echo |
| 72 | echo "=== Part 3: a real push over the wire (verbose transcript) ===" |
| 73 | muse -C ~/ecosystem/musehub hub repo delete gabriel/wire-episode17 --yes --json > /dev/null 2>&1 || true |
| 74 | muse -C ~/ecosystem/musehub hub repo create --name wire-episode17 --visibility public --json | python3 -m json.tool | head -6 |
| 75 | muse remote add local https://localhost:1337/gabriel/wire-episode17 --json > /dev/null 2>&1 || \ |
| 76 | muse remote set-url local https://localhost:1337/gabriel/wire-episode17 --json > /dev/null |
| 77 | muse push local main --force --json |
| 78 | |
| 79 | echo |
| 80 | echo "=== Part 4: a second, incremental commit -- only new blobs travel ===" |
| 81 | echo "second line" >> README.md |
| 82 | muse code add README.md |
| 83 | muse commit -m "Second commit, shares two objects with the first" \ |
| 84 | --agent-id claude-code --model-id claude-sonnet-5 --sign |
| 85 | muse push local main --json |
| 86 | |
| 87 | echo |
| 88 | echo "=== Part 5: clone -- the asymmetric, simpler fetch path ===" |
| 89 | mkdir -p "$CLONE_DIR" |
| 90 | cd "$CLONE_DIR" |
| 91 | muse clone https://localhost:1337/gabriel/wire-episode17 --json | tail -20 |
| 92 | |
| 93 | echo |
| 94 | echo "Demo built at $REPO and $CLONE_DIR" |
File History
1 commit
sha256:cb114a4ce48bc4c9f865774769ec9b6a3bb7ccb6a6f8792bbf5ae6f28b0a6f88
Add Episode 17 script (The Wire Protocol) and wire demo driver
Sonnet 5
patch
22 hours ago