-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathopencode-wrapper.sh
More file actions
executable file
·85 lines (73 loc) · 2.23 KB
/
Copy pathopencode-wrapper.sh
File metadata and controls
executable file
·85 lines (73 loc) · 2.23 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
#!/bin/bash
# OpenCode wrapper with StackMemory integration
# Usage: Add alias to ~/.zshrc: alias opencode-sm='~/Dev/stackmemory/scripts/opencode-wrapper.sh'
# Check for auto-sync flag
AUTO_SYNC=false
SYNC_INTERVAL=5
for arg in "$@"; do
case $arg in
--auto-sync)
AUTO_SYNC=true
shift
;;
--sync-interval=*)
SYNC_INTERVAL="${arg#*=}"
shift
;;
esac
done
# Auto-initialize StackMemory if in git repo without it
if [ -d ".git" ] && [ ! -d ".stackmemory" ]; then
echo "📦 Initializing StackMemory for this project..."
stackmemory init --silent 2>/dev/null || true
fi
# Load existing context if available
if [ -d ".stackmemory" ]; then
echo "🧠 Loading StackMemory context..."
stackmemory status --brief 2>/dev/null || true
fi
# Start Linear auto-sync in background if requested
SYNC_PID=""
if [ "$AUTO_SYNC" = true ] && [ -n "$LINEAR_API_KEY" ]; then
echo "🔄 Starting Linear auto-sync (${SYNC_INTERVAL}min intervals)..."
(
while true; do
sleep $((SYNC_INTERVAL * 60))
if [ -d ".stackmemory" ]; then
stackmemory linear sync --quiet 2>/dev/null || true
fi
done
) &
SYNC_PID=$!
fi
cleanup() {
echo ""
echo "📝 Saving StackMemory context..."
# Kill auto-sync if running
if [ -n "$SYNC_PID" ] && kill -0 $SYNC_PID 2>/dev/null; then
echo "🛑 Stopping auto-sync..."
kill $SYNC_PID 2>/dev/null || true
fi
# Check if in a git repo with stackmemory
if [ -d ".stackmemory" ]; then
# Save current context
stackmemory status 2>/dev/null
# If Linear API key is set, final sync
if [ -n "$LINEAR_API_KEY" ]; then
echo "🔄 Final Linear sync..."
stackmemory linear sync 2>/dev/null
fi
echo "✅ StackMemory context saved"
fi
}
# Set trap for exit signals
trap cleanup EXIT INT TERM
# Run OpenCode
if command -v opencode &> /dev/null; then
opencode "$@"
else
echo "❌ OpenCode not found. Please install it first."
echo " Run: curl -fsSL https://opencode.ai/install | bash"
echo " Or: npm install -g opencode-ai"
exit 1
fi