-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatusline.sh
More file actions
executable file
·247 lines (214 loc) · 7.11 KB
/
statusline.sh
File metadata and controls
executable file
·247 lines (214 loc) · 7.11 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/bin/bash
# Status line for vector memory — multi-line, clear labels, visual indicators
# ── Line 0: PS1-style shell prompt header ──
PS1_LINE=$(printf "\033[01;32m%s@%s\033[00m:\033[01;34m%s\033[00m" "$(whoami)" "$(hostname -s)" "$(pwd)")
DB_PATH="$HOME/.claude/cortex-db"
ACTIVITY_FILE="$HOME/.claude/.cortex_activity"
OPS_LOG="$HOME/.claude/.cortex_ops_log.jsonl"
SESSIONS_LOG="$HOME/.claude/.cortex_sessions.jsonl"
CACHE_FILE="$HOME/.claude/.cortex_statusline_cache"
CACHE_TTL=15 # seconds
# Use cached output if fresh enough
if [ -f "$CACHE_FILE" ]; then
CACHE_AGE=$(( $(date +%s) - $(stat -c %Y "$CACHE_FILE" 2>/dev/null || echo 0) ))
if [ "$CACHE_AGE" -lt "$CACHE_TTL" ]; then
cat "$CACHE_FILE"
exit 0
fi
fi
# ── Line 1: Memory stats ──
MEMORY_LINE=$(/usr/bin/python3 -W ignore - "$DB_PATH" 2>/dev/null <<'PYEOF'
import os, sys
sys.path.insert(0, os.path.expanduser("~/.claude/skills/cortex/lib"))
from chroma_client import get_client, get_collection
try:
col = get_collection()
c = col.count()
if c == 0:
print("empty")
else:
data = col.get()
types = {}
projects = set()
for m in data["metadatas"]:
t = m.get("type", "?")
if t == "agent_eval":
continue
types[t] = types.get(t, 0) + 1
p = m.get("project", "")
if p and p != "global":
projects.add(p)
# Build readable breakdown
type_names = {
"project": "project",
"feedback": "feedback",
"preferences": "prefs",
"reference": "reference",
"user": "user",
"general": "general"
}
parts = []
for t in ["project", "feedback", "preferences", "reference", "user", "general"]:
if t in types:
parts.append(f"{types[t]} {type_names.get(t, t)}")
breakdown = ", ".join(parts)
proj_count = len(projects)
proj_text = f" across {proj_count} project{'s' if proj_count != 1 else ''}" if proj_count > 0 else ""
print(f"{c} memories ({breakdown}){proj_text}")
except Exception:
print("offline")
PYEOF
)
# ── Line 2: Agent fleet ──
FLEET_LINE=$(/usr/bin/python3 -W ignore -c "
import os, sys, glob, json
user_dir = os.path.expanduser('~/.claude/agents')
proj_dir = '.claude/agents'
user_count = len(glob.glob(os.path.join(user_dir, '*.md'))) if os.path.isdir(user_dir) else 0
proj_count = len(glob.glob(os.path.join(proj_dir, '*.md'))) if os.path.isdir(proj_dir) else 0
total = user_count + proj_count
if total == 0:
exit(0)
parts = []
if proj_count:
parts.append(f'{proj_count} project')
if user_count:
parts.append(f'{user_count} global')
# Usage stats from ledger
usage_total = 0
usage_today = 0
today = __import__('time').strftime('%Y-%m-%d')
ledger = os.path.expanduser('~/.claude/agent-usage.jsonl')
if os.path.exists(ledger):
try:
with open(ledger) as f:
for line in f:
usage_total += 1
try:
e = json.loads(line.strip())
if e.get('timestamp', '').startswith(today):
usage_today += 1
except: pass
except: pass
# Eval scores
avg_score = ''
try:
sys.path.insert(0, os.path.expanduser('~/.claude/skills/cortex/lib'))
from chroma_client import get_client, get_collection
col = get_collection()
data = col.get(where={'type': 'agent_eval'})
latest = {}
for i in range(len(data['ids'])):
m = data['metadatas'][i]
name = m.get('agent_name', '?')
ts = m.get('timestamp', '')
if name not in latest or ts > latest[name]['ts']:
latest[name] = {'ts': ts, 'score': m.get('score', '0')}
if latest:
scores = [int(v['score']) for v in latest.values() if v['score'].isdigit()]
if scores:
avg = sum(scores) / len(scores)
avg_score = f' | health {avg:.1f}/5'
except: pass
scope_text = ' + '.join(parts)
usage_text = ''
if usage_today > 0:
usage_text = f' | {usage_today} spawns today'
elif usage_total > 0:
usage_text = f' | {usage_total} total spawns'
print(f'{total} agents ({scope_text}){usage_text}{avg_score}')
" 2>/dev/null)
# ── Line 3: Auto-discovered skills ──
SKILLS_LINE=$(/usr/bin/python3 -W ignore -c "
import os, glob
proj_dir = '.claude/commands'
global_dir = os.path.expanduser('~/.claude/commands')
proj_count = len(glob.glob(os.path.join(proj_dir, '*.md'))) if os.path.isdir(proj_dir) else 0
global_count = len(glob.glob(os.path.join(global_dir, '*.md'))) if os.path.isdir(global_dir) else 0
total = proj_count + global_count
if total == 0:
exit(0)
parts = []
if proj_count:
parts.append(f'{proj_count} project')
if global_count:
parts.append(f'{global_count} global')
print(f'{total} skills ({\" + \".join(parts)})')
" 2>/dev/null)
# ── Line 5: Health & config ──
HEALTH_LINE=$(/usr/bin/python3 -W ignore -c "
import json, os, subprocess
config_file = os.path.expanduser('~/.claude/.cortex_config')
try:
with open(config_file) as f:
cfg = json.load(f)
except:
cfg = {}
# Defaults
defaults = {
'auto_learn': True,
'auto_skills': True,
'auto_agents': True,
}
# ChromaDB status
db_ok = False
try:
import urllib.request
r = urllib.request.urlopen('http://localhost:8100/api/v2/heartbeat', timeout=1)
db_ok = r.status == 200
except:
pass
# Build toggle display
toggles = []
for key in ['auto_learn', 'auto_skills', 'auto_agents']:
val = cfg.get(key, defaults[key])
short = key.replace('auto_', '')
symbol = '\u2713' if val else '\u2717'
toggles.append(f'{short}:{symbol}')
db_status = 'chromadb:\u2713' if db_ok else 'chromadb:\u2717'
print(f'{db_status} | {\" \".join(toggles)}')
" 2>/dev/null)
# ── Line 4: Today's operations ──
OPS_LINE=""
if [ -f "$OPS_LOG" ]; then
TODAY=$(date +%Y-%m-%d)
OPS_TODAY=$(grep -c "\"$TODAY" "$OPS_LOG" 2>/dev/null || echo 0)
if [ "$OPS_TODAY" -gt 0 ]; then
OPS_LINE="$OPS_TODAY ops today"
fi
fi
# ── Line 4: Recent activity (last 30 seconds) ──
ACTIVITY=""
if [ -f "$ACTIVITY_FILE" ]; then
LAST_MOD=$(stat -c %Y "$ACTIVITY_FILE" 2>/dev/null || stat -f %m "$ACTIVITY_FILE" 2>/dev/null || echo 0)
NOW=$(date +%s)
AGE=$(( NOW - LAST_MOD ))
if [ "$AGE" -le 30 ]; then
ACTIVITY=$(cat "$ACTIVITY_FILE" 2>/dev/null)
fi
fi
# ── Assemble output ──
OUTPUT="${PS1_LINE}\n\U0001f9e0 ${MEMORY_LINE}"
if [ -n "$FLEET_LINE" ]; then
OUTPUT="${OUTPUT}\n\U0001f916 ${FLEET_LINE}"
fi
if [ -n "$SKILLS_LINE" ]; then
OUTPUT="${OUTPUT}\n\U0001f4da ${SKILLS_LINE}"
fi
if [ -n "$HEALTH_LINE" ]; then
OUTPUT="${OUTPUT}\n\U00002699 ${HEALTH_LINE}"
fi
# Combine ops + activity on one line if both exist
EXTRA=""
if [ -n "$OPS_LINE" ] && [ -n "$ACTIVITY" ]; then
EXTRA="\U000026a1 ${OPS_LINE} | ${ACTIVITY}"
elif [ -n "$OPS_LINE" ]; then
EXTRA="\U000026a1 ${OPS_LINE}"
elif [ -n "$ACTIVITY" ]; then
EXTRA="\U000026a1 ${ACTIVITY}"
fi
if [ -n "$EXTRA" ]; then
OUTPUT="${OUTPUT}\n${EXTRA}"
fi
# Cache output and display
echo -e "$OUTPUT" | tee "$CACHE_FILE"