-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathsimulate-context.sh
More file actions
executable file
·125 lines (107 loc) · 4.12 KB
/
Copy pathsimulate-context.sh
File metadata and controls
executable file
·125 lines (107 loc) · 4.12 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
#!/bin/bash
# simulate-context.sh - Simulate progressive context usage
# Increments GLM context by 10% until auto-compact triggers
set -euo pipefail
# Configuration
PROJECT_STATE="${HOME}/.claude/hooks/project-state.sh"
STATE_DIR=$("$PROJECT_STATE" get-dir 2>/dev/null)
CONTEXT_FILE="${STATE_DIR}/glm-context.json"
CONTEXT_WINDOW=128000
# Colors
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " 📊 Context Simulation Script"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo " State Dir: ${STATE_DIR}"
echo " Context File: ${CONTEXT_FILE}"
echo " Context Window: ${CONTEXT_WINDOW} tokens"
echo ""
# Get current percentage
get_current_percentage() {
if [[ -f "$CONTEXT_FILE" ]]; then
jq -r '.percentage // 0' "$CONTEXT_FILE" 2>/dev/null || echo 0
else
echo 0
fi
}
# Update context file
update_context() {
local tokens=$1
local percentage=$2
cat > "$CONTEXT_FILE" <<EOF
{
"total_tokens": $tokens,
"context_window": $CONTEXT_WINDOW,
"percentage": $percentage,
"last_updated": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")",
"session_start": "$(date -u +"%Y-%m-%dT%H:%M:%SZ")",
"message_count": 1
}
EOF
}
# Get color for percentage
get_color() {
local pct=$1
if [[ $pct -ge 85 ]]; then
echo -e "${RED}"
elif [[ $pct -ge 75 ]]; then
echo -e "${YELLOW}"
elif [[ $pct -ge 50 ]]; then
echo -e "${GREEN}"
else
echo -e "${CYAN}"
fi
}
# Main simulation loop
echo "Starting simulation..."
echo ""
current_pct=$(get_current_percentage)
echo "Current: ${current_pct}%"
echo ""
# Simulate from 10% to 100% in 10% increments
for target_pct in {10..100..10}; do
# Calculate tokens for this percentage
tokens=$((CONTEXT_WINDOW * target_pct / 100))
# Update context file
update_context $tokens $target_pct
# Get display color
color=$(get_color $target_pct)
reset='\033[0m'
# Display progress
echo -e "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo -e " 🎯 Target: ${color}${target_pct}%${reset} | Tokens: ${tokens} / ${CONTEXT_WINDOW}"
echo -e "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Show warnings based on thresholds
if [[ $target_pct -ge 85 ]]; then
echo -e " ${RED}⚠️ CRITICAL: Context at ${target_pct}%!${reset}"
echo -e " ${RED}🚨 Auto-compact should be triggered!${reset}"
elif [[ $target_pct -ge 75 ]]; then
echo -e " ${YELLOW}⚠️ WARNING: Context at ${target_pct}%${reset}"
echo -e " ${YELLOW}📝 Consider compacting soon${reset}"
elif [[ $target_pct -ge 50 ]]; then
echo -e " ${GREEN}✅ Context at ${target_pct}% - Normal${reset}"
else
echo -e " ${CYAN}✅ Context at ${target_pct}% - Low${reset}"
fi
echo ""
echo " Context file updated:"
jq -c '.' "$CONTEXT_FILE" 2>/dev/null || echo " (file not readable)"
echo ""
read -p " Press Enter to continue to next increment (10%)..." || true
echo ""
done
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${reset}"
echo -e " ✅ Simulation complete!"
echo -e "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo " Final context: $(jq -r '.percentage' "$CONTEXT_FILE")%"
echo ""
echo " Note: The statusline should show these changes in real-time."
echo " At 75%, you should see a YELLOW warning."
echo " At 85%, you should see a RED critical warning."
echo ""