run.sh RawHistoryFolder
1#!/usr/bin/env bash
2set -euo pipefail
3cd "$(dirname "$0")/../.."
4
5TAPE="${1:-demo.tape}"
6install -d -m 0777 scripts/demo/out
7
8CLAUDE_TMP=$(mktemp -d)
9# claude writes files into the temp HOME as the container's demo user, which
10# rootless docker maps to a subuid the host cannot delete directly. Clean up
11# through the container first, where the creating uid can unlink its own
12# files, then remove the (now-empty) temp dir from the host. This never
13# suppresses a leftover: if anything still remains, it's reported so a
14# credentials-bearing directory doesn't silently linger in /tmp.
15cleanup() {
16 # Every step here is best-effort: under `set -e`, an unguarded failure in an
17 # EXIT trap would abort the trap early and replace the script's real exit
18 # status with the failing cleanup command's. Guard each step with `|| true`
19 # so cleanup always runs to completion and never masks the vhs run's result;
20 # the final check below is what surfaces an unrecovered leftover.
21 rm -rf "$CLAUDE_TMP" 2>/dev/null || true
22 if [ -d "$CLAUDE_TMP" ]; then
23 docker run --rm -v "$CLAUDE_TMP:/cleanup" --entrypoint sh vev-demo \
24 -c 'rm -rf /cleanup/.claude /cleanup/.claude.json' 2>/dev/null || true
25 rmdir "$CLAUDE_TMP" 2>/dev/null || true
26 fi
27 if [ -d "$CLAUDE_TMP" ]; then
28 echo "warning: could not remove claude temp home, left at $CLAUDE_TMP" >&2
29 fi
30 return 0
31}
32trap cleanup EXIT
33mkdir -p "$CLAUDE_TMP/.claude"
34cp "$HOME/.claude/.credentials.json" "$CLAUDE_TMP/.claude/"
35cp scripts/demo/claude-settings.json "$CLAUDE_TMP/.claude/settings.json"
36printf '{"hasCompletedOnboarding": true, "theme": "dark", "projects": {"/home/demo": {"hasTrustDialogAccepted": true, "hasCompletedProjectOnboarding": true, "projectOnboardingSeenCount": 1}}}\n' > "$CLAUDE_TMP/.claude.json"
37
38# Rootless docker maps host-owned files (uid 1000) to container root, but the
39# container runs as demo (uid 1000 -> a subuid), so demo cannot read the
40# credentials or write its config dir. Open up the throwaway home's contents so
41# claude can authenticate and write transcripts, then restore the mktemp
42# parent to 0700: bind mounts hand the container the inner paths directly, but
43# other host users would have to traverse the parent, which now blocks them.
44chmod -R a+rwX "$CLAUDE_TMP"
45chmod 0700 "$CLAUDE_TMP"
46
47docker run --rm --hostname vev-demo \
48 -v "$PWD/scripts/demo:/tape:ro" \
49 -v "$PWD/scripts/demo/out:/home/demo/out" \
50 -v "$CLAUDE_TMP/.claude:/home/demo/.claude" \
51 -v "$CLAUDE_TMP/.claude.json:/home/demo/.claude.json" \
52 vev-demo "/tape/$TAPE"