forked from 1jehuang/jcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecord_demo.sh
More file actions
executable file
·126 lines (106 loc) · 3.94 KB
/
record_demo.sh
File metadata and controls
executable file
·126 lines (106 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
# jcode demo recording orchestrator
# Usage: ./scripts/record_demo.sh <demo_name> <prompt>
#
# This script:
# 1. Opens a fresh jcode in a new kitty window
# 2. Starts wf-recorder on that window
# 3. Sends the prompt to jcode
# 4. Waits for completion, then stops recording
set -euo pipefail
repo_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
DEMO_NAME="${1:?Usage: record_demo.sh <name> <prompt>}"
PROMPT="${2:?Usage: record_demo.sh <name> <prompt>}"
DEMO_DIR="/tmp/jcode-demo/$DEMO_NAME"
OUTPUT_DIR="$repo_root/assets/demos"
SOCK=$(ls /tmp/kitty.sock* 2>/dev/null | head -1)
mkdir -p "$DEMO_DIR" "$OUTPUT_DIR"
echo "=== jcode Demo Recorder ==="
echo "Demo: $DEMO_NAME"
echo "Prompt: $PROMPT"
echo "Working dir: $DEMO_DIR"
echo ""
# Step 1: Launch jcode in a new kitty OS window
echo "[1/5] Launching jcode..."
kitten @ --to unix:$SOCK launch --type=os-window \
--cwd "$DEMO_DIR" \
--title "jcode-demo-$DEMO_NAME" \
"$repo_root/target/release/jcode"
sleep 3 # Let jcode fully start
# Step 2: Find the window
DEMO_WIN_ID=$(niri msg windows 2>/dev/null | grep -B5 "jcode-demo-$DEMO_NAME" | grep "Window ID" | awk '{print $3}' | tr -d ':')
if [ -z "$DEMO_WIN_ID" ]; then
echo "ERROR: Could not find demo window"
exit 1
fi
echo "[2/5] Found window ID: $DEMO_WIN_ID"
# Focus the window
niri msg action focus-window --id "$DEMO_WIN_ID"
sleep 0.5
# Step 3: Start recording
echo "[3/5] Starting recording..."
RECORDING_FILE="$OUTPUT_DIR/${DEMO_NAME}.mp4"
wf-recorder -f "$RECORDING_FILE" &
RECORDER_PID=$!
sleep 1
# Step 4: Type the prompt into jcode
echo "[4/5] Sending prompt..."
# Find the kitty window id
KITTY_WIN_ID=$(kitten @ --to unix:$SOCK ls 2>/dev/null | python3 -c "
import json, sys
data = json.load(sys.stdin)
for os_win in data:
for tab in os_win.get('tabs', []):
for win in tab.get('windows', []):
if 'jcode-demo-$DEMO_NAME' in win.get('title', ''):
print(win['id'])
sys.exit(0)
")
if [ -n "$KITTY_WIN_ID" ]; then
# Type the prompt character by character with small delay for visual effect
kitten @ --to unix:$SOCK send-text --match "id:$KITTY_WIN_ID" "$PROMPT"
sleep 0.5
# Press Enter
kitten @ --to unix:$SOCK send-text --match "id:$KITTY_WIN_ID" $'\r'
else
echo "WARNING: Could not find kitty window, trying by title match..."
kitten @ --to unix:$SOCK send-text --match "title:jcode-demo-$DEMO_NAME" "$PROMPT"
sleep 0.5
kitten @ --to unix:$SOCK send-text --match "title:jcode-demo-$DEMO_NAME" $'\r'
fi
echo "Prompt sent. Waiting for completion..."
echo "(Press Ctrl+C to stop recording early, or wait for auto-detection)"
# Step 5: Wait and then stop recording
# Poll for completion - check if jcode is still processing
# Simple approach: wait for a fixed time or manual Ctrl+C
trap 'echo "Stopping..."; kill $RECORDER_PID 2>/dev/null; wait $RECORDER_PID 2>/dev/null; echo "Recording saved: $RECORDING_FILE"' INT
# Wait for the agent to finish (poll the debug socket)
MAX_WAIT=180 # 3 minutes max
ELAPSED=0
while [ $ELAPSED -lt $MAX_WAIT ]; do
sleep 5
ELAPSED=$((ELAPSED + 5))
# Check if the kitty window title indicates idle (no streaming)
CURRENT_TITLE=$(kitten @ --to unix:$SOCK ls 2>/dev/null | python3 -c "
import json, sys
data = json.load(sys.stdin)
for os_win in data:
for tab in os_win.get('tabs', []):
for win in tab.get('windows', []):
if win['id'] == $KITTY_WIN_ID:
print(win.get('title', ''))
sys.exit(0)
" 2>/dev/null || echo "unknown")
echo " [${ELAPSED}s] Window: $CURRENT_TITLE"
done
# Add a small pause at the end so viewer can see the result
sleep 3
# Stop recording
kill $RECORDER_PID 2>/dev/null
wait $RECORDER_PID 2>/dev/null
echo ""
echo "[5/5] Recording saved: $RECORDING_FILE"
FILE_SIZE=$(du -h "$RECORDING_FILE" | cut -f1)
echo "Size: $FILE_SIZE"
echo ""
echo "To convert to GIF: ffmpeg -i $RECORDING_FILE -vf 'fps=15,scale=800:-1' ${RECORDING_FILE%.mp4}.gif"