-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcodex-wrapper.sh
More file actions
88 lines (75 loc) · 2.24 KB
/
codex-wrapper.sh
File metadata and controls
88 lines (75 loc) · 2.24 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
#!/bin/bash
# Codex CLI wrapper with StackMemory integration
# Usage: Add alias to your shell: alias codex-sm='~/Dev/stackmemory/scripts/codex-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
# shellcheck disable=SC2064
trap cleanup EXIT INT TERM
# Run Codex CLI
if command -v codex &> /dev/null; then
codex "$@"
elif command -v codex-cli &> /dev/null; then
codex-cli "$@"
else
echo "❌ Codex CLI not found. Please install it first."
echo " See: https://github.com/openai/codex-cli"
exit 1
fi