skill-statusline 2.1.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +929 -929
- package/bin/cli.js.bak +837 -0
- package/bin/statusline.sh +139 -121
- package/lib/core.sh +408 -382
- package/lib/helpers.sh +119 -81
- package/package.json +52 -52
package/lib/core.sh
CHANGED
|
@@ -1,382 +1,408 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# skill-statusline v2.0 — Core engine
|
|
3
|
-
# Reads Claude Code JSON from stdin, computes all fields, renders via layout
|
|
4
|
-
|
|
5
|
-
STATUSLINE_DIR="${HOME}/.claude/statusline"
|
|
6
|
-
CONFIG_FILE="${HOME}/.claude/statusline-config.json"
|
|
7
|
-
|
|
8
|
-
# ── 0.
|
|
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
|
-
[ -n "$
|
|
59
|
-
fi
|
|
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
|
-
[ -z "$
|
|
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
|
-
if
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
else
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
elif [ "$SL_CTX_PCT" -
|
|
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
|
-
[ -z "$
|
|
237
|
-
[ -z "$
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
[ -
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
#
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
#
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# skill-statusline v2.0 — Core engine
|
|
3
|
+
# Reads Claude Code JSON from stdin, computes all fields, renders via layout
|
|
4
|
+
|
|
5
|
+
STATUSLINE_DIR="${HOME}/.claude/statusline"
|
|
6
|
+
CONFIG_FILE="${HOME}/.claude/statusline-config.json"
|
|
7
|
+
|
|
8
|
+
# ── 0. Global safety: kill entire script if it takes too long ──
|
|
9
|
+
# Claude Code calls this on every refresh; a hang here freezes the terminal
|
|
10
|
+
_sl_cleanup() { exit 0; }
|
|
11
|
+
trap '_sl_cleanup' ALRM 2>/dev/null
|
|
12
|
+
( sleep 3 && kill -ALRM $$ 2>/dev/null ) &
|
|
13
|
+
_SL_WATCHDOG_PID=$!
|
|
14
|
+
|
|
15
|
+
# ── 0b. Read stdin JSON (with timeout) ──
|
|
16
|
+
# If stdin isn't piped properly, `cat` hangs forever — use read with timeout
|
|
17
|
+
input=""
|
|
18
|
+
if [ -t 0 ]; then
|
|
19
|
+
# stdin is a terminal (not piped) — no data to read, output nothing
|
|
20
|
+
kill "$_SL_WATCHDOG_PID" 2>/dev/null; wait "$_SL_WATCHDOG_PID" 2>/dev/null
|
|
21
|
+
exit 0
|
|
22
|
+
fi
|
|
23
|
+
# Read all of stdin but bail after 2 seconds
|
|
24
|
+
input=$(timeout 2 cat 2>/dev/null || cat 2>/dev/null)
|
|
25
|
+
if [ -z "$input" ]; then
|
|
26
|
+
kill "$_SL_WATCHDOG_PID" 2>/dev/null; wait "$_SL_WATCHDOG_PID" 2>/dev/null
|
|
27
|
+
exit 0
|
|
28
|
+
fi
|
|
29
|
+
|
|
30
|
+
# ── 1. Source modules ──
|
|
31
|
+
source "${STATUSLINE_DIR}/json-parser.sh"
|
|
32
|
+
source "${STATUSLINE_DIR}/helpers.sh"
|
|
33
|
+
|
|
34
|
+
# ── 2. Load config ──
|
|
35
|
+
active_theme="default"
|
|
36
|
+
active_layout="standard"
|
|
37
|
+
cfg_warn_threshold=85
|
|
38
|
+
cfg_bar_width=40
|
|
39
|
+
cfg_show_burn_rate="false"
|
|
40
|
+
cfg_show_vim="true"
|
|
41
|
+
cfg_show_agent="true"
|
|
42
|
+
|
|
43
|
+
if [ -f "$CONFIG_FILE" ]; then
|
|
44
|
+
_cfg=$(cat "$CONFIG_FILE" 2>/dev/null)
|
|
45
|
+
_t=$(echo "$_cfg" | grep -o '"theme"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 | sed 's/.*:.*"\(.*\)"/\1/')
|
|
46
|
+
_l=$(echo "$_cfg" | grep -o '"layout"[[:space:]]*:[[:space:]]*"[^"]*"' | head -1 | sed 's/.*:.*"\(.*\)"/\1/')
|
|
47
|
+
[ -n "$_t" ] && active_theme="$_t"
|
|
48
|
+
[ -n "$_l" ] && active_layout="$_l"
|
|
49
|
+
_w=$(echo "$_cfg" | grep -o '"compaction_warning_threshold"[[:space:]]*:[[:space:]]*[0-9]*' | head -1 | sed 's/.*:[[:space:]]*//')
|
|
50
|
+
_bw=$(echo "$_cfg" | grep -o '"bar_width"[[:space:]]*:[[:space:]]*[0-9]*' | head -1 | sed 's/.*:[[:space:]]*//')
|
|
51
|
+
_br=$(echo "$_cfg" | grep -o '"show_burn_rate"[[:space:]]*:[[:space:]]*true' | head -1)
|
|
52
|
+
_sv=$(echo "$_cfg" | grep -o '"show_vim_mode"[[:space:]]*:[[:space:]]*false' | head -1)
|
|
53
|
+
_sa=$(echo "$_cfg" | grep -o '"show_agent_name"[[:space:]]*:[[:space:]]*false' | head -1)
|
|
54
|
+
[ -n "$_w" ] && cfg_warn_threshold="$_w"
|
|
55
|
+
[ -n "$_bw" ] && cfg_bar_width="$_bw"
|
|
56
|
+
[ -n "$_br" ] && cfg_show_burn_rate="true"
|
|
57
|
+
[ -n "$_sv" ] && cfg_show_vim="false"
|
|
58
|
+
[ -n "$_sa" ] && cfg_show_agent="false"
|
|
59
|
+
fi
|
|
60
|
+
|
|
61
|
+
# Allow env override (for ccsl preview)
|
|
62
|
+
[ -n "$STATUSLINE_THEME_OVERRIDE" ] && active_theme="$STATUSLINE_THEME_OVERRIDE"
|
|
63
|
+
[ -n "$STATUSLINE_LAYOUT_OVERRIDE" ] && active_layout="$STATUSLINE_LAYOUT_OVERRIDE"
|
|
64
|
+
|
|
65
|
+
# ── 3. Source theme ──
|
|
66
|
+
theme_file="${STATUSLINE_DIR}/themes/${active_theme}.sh"
|
|
67
|
+
if [ -f "$theme_file" ]; then
|
|
68
|
+
source "$theme_file"
|
|
69
|
+
else
|
|
70
|
+
source "${STATUSLINE_DIR}/themes/default.sh"
|
|
71
|
+
fi
|
|
72
|
+
|
|
73
|
+
# ── 4. Terminal width detection (with timeout) ──
|
|
74
|
+
SL_TERM_WIDTH=${COLUMNS:-0}
|
|
75
|
+
if [ "$SL_TERM_WIDTH" -eq 0 ] 2>/dev/null; then
|
|
76
|
+
_tw=$(timeout 1 tput cols 2>/dev/null || echo "")
|
|
77
|
+
[ -n "$_tw" ] && [ "$_tw" -gt 0 ] && SL_TERM_WIDTH="$_tw"
|
|
78
|
+
fi
|
|
79
|
+
[ "$SL_TERM_WIDTH" -eq 0 ] && SL_TERM_WIDTH=80
|
|
80
|
+
|
|
81
|
+
# Auto-downgrade layout for narrow terminals
|
|
82
|
+
if [ "$SL_TERM_WIDTH" -lt 60 ]; then
|
|
83
|
+
active_layout="compact"
|
|
84
|
+
elif [ "$SL_TERM_WIDTH" -lt 80 ] && [ "$active_layout" = "full" ]; then
|
|
85
|
+
active_layout="standard"
|
|
86
|
+
fi
|
|
87
|
+
|
|
88
|
+
# Dynamic bar width
|
|
89
|
+
BAR_WIDTH="$cfg_bar_width"
|
|
90
|
+
if [ "$SL_TERM_WIDTH" -gt 100 ]; then
|
|
91
|
+
_dyn=$(( SL_TERM_WIDTH - 20 ))
|
|
92
|
+
[ "$_dyn" -gt 60 ] && _dyn=60
|
|
93
|
+
[ "$_dyn" -gt "$BAR_WIDTH" ] && BAR_WIDTH="$_dyn"
|
|
94
|
+
elif [ "$SL_TERM_WIDTH" -lt 70 ]; then
|
|
95
|
+
BAR_WIDTH=20
|
|
96
|
+
fi
|
|
97
|
+
|
|
98
|
+
# ── 5. Initialize cache ──
|
|
99
|
+
_sl_cache_init
|
|
100
|
+
|
|
101
|
+
# ── 6. Parse ALL JSON fields ──
|
|
102
|
+
|
|
103
|
+
# --- 6a. Directory ---
|
|
104
|
+
SL_CWD=$(json_nested_val "workspace" "current_dir")
|
|
105
|
+
[ -z "$SL_CWD" ] && SL_CWD=$(json_val "cwd")
|
|
106
|
+
if [ -z "$SL_CWD" ]; then
|
|
107
|
+
SL_DIR="~"
|
|
108
|
+
clean_cwd=""
|
|
109
|
+
else
|
|
110
|
+
clean_cwd=$(to_fwd "$SL_CWD")
|
|
111
|
+
SL_DIR=$(echo "$clean_cwd" | awk -F'/' '{if(NF>3) print $(NF-2)"/"$(NF-1)"/"$NF; else if(NF>2) print $(NF-1)"/"$NF; else print $0}')
|
|
112
|
+
[ -z "$SL_DIR" ] && SL_DIR="~"
|
|
113
|
+
fi
|
|
114
|
+
|
|
115
|
+
# --- 6b. Model ---
|
|
116
|
+
SL_MODEL_DISPLAY=$(json_nested_val "model" "display_name")
|
|
117
|
+
SL_MODEL_ID=$(json_nested_val "model" "id")
|
|
118
|
+
# Flat fallback
|
|
119
|
+
[ -z "$SL_MODEL_DISPLAY" ] && SL_MODEL_DISPLAY=$(json_val "display_name")
|
|
120
|
+
[ -z "$SL_MODEL_ID" ] && SL_MODEL_ID=$(json_val "id")
|
|
121
|
+
[ -z "$SL_MODEL_DISPLAY" ] && SL_MODEL_DISPLAY="unknown"
|
|
122
|
+
|
|
123
|
+
model_ver=""
|
|
124
|
+
if [ -n "$SL_MODEL_ID" ]; then
|
|
125
|
+
model_ver=$(echo "$SL_MODEL_ID" | sed -n 's/.*-\([0-9]*\)-\([0-9]*\)$/\1.\2/p')
|
|
126
|
+
fi
|
|
127
|
+
if [ -n "$model_ver" ] && ! echo "$SL_MODEL_DISPLAY" | grep -q '[0-9]'; then
|
|
128
|
+
SL_MODEL="${SL_MODEL_DISPLAY} ${model_ver}"
|
|
129
|
+
else
|
|
130
|
+
SL_MODEL="$SL_MODEL_DISPLAY"
|
|
131
|
+
fi
|
|
132
|
+
|
|
133
|
+
# --- 6c. Context — ACCURATE computation from current_usage ---
|
|
134
|
+
ctx_size=$(json_nested "context_window" "context_window_size")
|
|
135
|
+
cur_input=$(json_deep "context_window" "current_usage" "input_tokens")
|
|
136
|
+
cur_output=$(json_deep "context_window" "current_usage" "output_tokens")
|
|
137
|
+
cur_cache_create=$(json_deep "context_window" "current_usage" "cache_creation_input_tokens")
|
|
138
|
+
cur_cache_read=$(json_deep "context_window" "current_usage" "cache_read_input_tokens")
|
|
139
|
+
|
|
140
|
+
[ -z "$ctx_size" ] && ctx_size=200000
|
|
141
|
+
[ -z "$cur_input" ] && cur_input=0
|
|
142
|
+
[ -z "$cur_output" ] && cur_output=0
|
|
143
|
+
[ -z "$cur_cache_create" ] && cur_cache_create=0
|
|
144
|
+
[ -z "$cur_cache_read" ] && cur_cache_read=0
|
|
145
|
+
|
|
146
|
+
# Claude's formula: input + cache_creation + cache_read (output excluded from context %)
|
|
147
|
+
ctx_used=$(awk -v a="$cur_input" -v b="$cur_cache_create" -v c="$cur_cache_read" \
|
|
148
|
+
'BEGIN { printf "%d", a + b + c }')
|
|
149
|
+
|
|
150
|
+
# Self-calculated percentage
|
|
151
|
+
calc_pct=0
|
|
152
|
+
if [ "$cur_input" -gt 0 ] 2>/dev/null; then
|
|
153
|
+
calc_pct=$(awk -v used="$ctx_used" -v total="$ctx_size" \
|
|
154
|
+
'BEGIN { if (total > 0) printf "%d", (used * 100) / total; else print 0 }')
|
|
155
|
+
fi
|
|
156
|
+
|
|
157
|
+
# Reported percentage as fallback
|
|
158
|
+
reported_pct=$(json_nested "context_window" "used_percentage")
|
|
159
|
+
|
|
160
|
+
# Use self-calculated if we have current_usage data, else fallback
|
|
161
|
+
if [ "$cur_input" -gt 0 ] 2>/dev/null; then
|
|
162
|
+
SL_CTX_PCT="$calc_pct"
|
|
163
|
+
elif [ -n "$reported_pct" ] && [ "$reported_pct" != "null" ]; then
|
|
164
|
+
SL_CTX_PCT=$(echo "$reported_pct" | cut -d. -f1)
|
|
165
|
+
else
|
|
166
|
+
SL_CTX_PCT=0
|
|
167
|
+
fi
|
|
168
|
+
|
|
169
|
+
SL_CTX_REMAINING=$(( 100 - SL_CTX_PCT ))
|
|
170
|
+
[ "$SL_CTX_REMAINING" -lt 0 ] && SL_CTX_REMAINING=0
|
|
171
|
+
|
|
172
|
+
# Context color
|
|
173
|
+
if [ "$SL_CTX_PCT" -gt 90 ] 2>/dev/null; then
|
|
174
|
+
CTX_CLR="$CLR_CTX_CRIT"
|
|
175
|
+
elif [ "$SL_CTX_PCT" -gt 75 ] 2>/dev/null; then
|
|
176
|
+
CTX_CLR="$CLR_CTX_HIGH"
|
|
177
|
+
elif [ "$SL_CTX_PCT" -gt 40 ] 2>/dev/null; then
|
|
178
|
+
CTX_CLR="$CLR_CTX_MED"
|
|
179
|
+
else
|
|
180
|
+
CTX_CLR="$CLR_CTX_LOW"
|
|
181
|
+
fi
|
|
182
|
+
|
|
183
|
+
# Build context bar
|
|
184
|
+
filled=$(( SL_CTX_PCT * BAR_WIDTH / 100 ))
|
|
185
|
+
[ "$filled" -gt "$BAR_WIDTH" ] && filled=$BAR_WIDTH
|
|
186
|
+
empty=$(( BAR_WIDTH - filled ))
|
|
187
|
+
bar_filled=""; bar_empty=""
|
|
188
|
+
i=0; while [ $i -lt $filled ]; do bar_filled="${bar_filled}${BAR_FILLED}"; i=$((i+1)); done
|
|
189
|
+
i=0; while [ $i -lt $empty ]; do bar_empty="${bar_empty}${BAR_EMPTY}"; i=$((i+1)); done
|
|
190
|
+
SL_CTX_BAR="${CTX_CLR}${bar_filled}${CLR_RST}${CLR_BAR_EMPTY}${bar_empty}${CLR_RST} ${CTX_CLR}${SL_CTX_PCT}%${CLR_RST}"
|
|
191
|
+
|
|
192
|
+
# Compaction warning
|
|
193
|
+
SL_COMPACT_WARNING=""
|
|
194
|
+
if [ "$SL_CTX_PCT" -ge 95 ] 2>/dev/null; then
|
|
195
|
+
SL_COMPACT_WARNING=" ${CLR_CTX_CRIT}${CLR_BOLD}COMPACTING${CLR_RST}"
|
|
196
|
+
elif [ "$SL_CTX_PCT" -ge "$cfg_warn_threshold" ] 2>/dev/null; then
|
|
197
|
+
SL_COMPACT_WARNING=" ${CLR_CTX_HIGH}${SL_CTX_REMAINING}% left${CLR_RST}"
|
|
198
|
+
fi
|
|
199
|
+
|
|
200
|
+
# --- 6d. GitHub (with caching + timeouts) ---
|
|
201
|
+
SL_BRANCH="no-git"
|
|
202
|
+
SL_GIT_DIRTY=""
|
|
203
|
+
SL_GITHUB=""
|
|
204
|
+
gh_user=""
|
|
205
|
+
gh_repo=""
|
|
206
|
+
|
|
207
|
+
if [ -n "$clean_cwd" ]; then
|
|
208
|
+
SL_BRANCH=$(cache_get "git-branch" "timeout 2 git --no-optional-locks -C '$clean_cwd' symbolic-ref --short HEAD 2>/dev/null || timeout 2 git --no-optional-locks -C '$clean_cwd' rev-parse --short HEAD 2>/dev/null" 5)
|
|
209
|
+
[ -z "$SL_BRANCH" ] && SL_BRANCH="no-git"
|
|
210
|
+
|
|
211
|
+
if [ "$SL_BRANCH" != "no-git" ]; then
|
|
212
|
+
remote_url=$(cache_get "git-remote" "timeout 2 git --no-optional-locks -C '$clean_cwd' remote get-url origin" 10)
|
|
213
|
+
if [ -n "$remote_url" ]; then
|
|
214
|
+
gh_user=$(echo "$remote_url" | sed 's|.*github\.com[:/]\([^/]*\)/.*|\1|')
|
|
215
|
+
[ "$gh_user" = "$remote_url" ] && gh_user=""
|
|
216
|
+
gh_repo=$(echo "$remote_url" | sed 's|.*/\([^/]*\)\.git$|\1|; s|.*/\([^/]*\)$|\1|')
|
|
217
|
+
[ "$gh_repo" = "$remote_url" ] && gh_repo=""
|
|
218
|
+
fi
|
|
219
|
+
|
|
220
|
+
# Dirty check (shorter cache — changes more often)
|
|
221
|
+
_staged=$(cache_get "git-staged" "timeout 2 git --no-optional-locks -C '$clean_cwd' diff --cached --quiet 2>/dev/null && echo clean || echo dirty" 3)
|
|
222
|
+
_unstaged=$(cache_get "git-unstaged" "timeout 2 git --no-optional-locks -C '$clean_cwd' diff --quiet 2>/dev/null && echo clean || echo dirty" 3)
|
|
223
|
+
[ "$_staged" = "dirty" ] && SL_GIT_DIRTY="${CLR_GIT_STAGED}+${CLR_RST}"
|
|
224
|
+
[ "$_unstaged" = "dirty" ] && SL_GIT_DIRTY="${SL_GIT_DIRTY}${CLR_GIT_UNSTAGED}~${CLR_RST}"
|
|
225
|
+
fi
|
|
226
|
+
fi
|
|
227
|
+
|
|
228
|
+
if [ -n "$gh_repo" ]; then
|
|
229
|
+
SL_GITHUB="${gh_user}/${gh_repo}/${SL_BRANCH}"
|
|
230
|
+
else
|
|
231
|
+
SL_GITHUB="$SL_BRANCH"
|
|
232
|
+
fi
|
|
233
|
+
|
|
234
|
+
# --- 6e. Cost ---
|
|
235
|
+
cost_raw=$(json_nested "cost" "total_cost_usd")
|
|
236
|
+
[ -z "$cost_raw" ] && cost_raw=$(json_num "total_cost_usd")
|
|
237
|
+
if [ -z "$cost_raw" ] || [ "$cost_raw" = "0" ]; then
|
|
238
|
+
SL_COST='$0.00'
|
|
239
|
+
else
|
|
240
|
+
SL_COST=$(awk -v c="$cost_raw" 'BEGIN { if (c < 0.01) printf "$%.4f", c; else printf "$%.2f", c }')
|
|
241
|
+
fi
|
|
242
|
+
|
|
243
|
+
# --- 6f. Tokens (window vs cumulative) ---
|
|
244
|
+
# Current window tokens (what's actually loaded — accurate)
|
|
245
|
+
[ -z "$cur_input" ] && cur_input=0
|
|
246
|
+
[ -z "$cur_output" ] && cur_output=0
|
|
247
|
+
SL_TOKENS_WIN_IN=$(fmt_tok "$cur_input")
|
|
248
|
+
SL_TOKENS_WIN_OUT=$(fmt_tok "$cur_output")
|
|
249
|
+
|
|
250
|
+
# Cumulative session tokens (grows forever, for reference)
|
|
251
|
+
cum_input=$(json_nested "context_window" "total_input_tokens")
|
|
252
|
+
cum_output=$(json_nested "context_window" "total_output_tokens")
|
|
253
|
+
# Flat fallback
|
|
254
|
+
[ -z "$cum_input" ] && cum_input=$(json_num "total_input_tokens")
|
|
255
|
+
[ -z "$cum_output" ] && cum_output=$(json_num "total_output_tokens")
|
|
256
|
+
[ -z "$cum_input" ] && cum_input=0
|
|
257
|
+
[ -z "$cum_output" ] && cum_output=0
|
|
258
|
+
SL_TOKENS_CUM_IN=$(fmt_tok "$cum_input")
|
|
259
|
+
SL_TOKENS_CUM_OUT=$(fmt_tok "$cum_output")
|
|
260
|
+
|
|
261
|
+
# --- 6g. Skill detection (with caching — longer TTL to avoid I/O thrashing) ---
|
|
262
|
+
SL_SKILL="Idle"
|
|
263
|
+
|
|
264
|
+
_detect_skill() {
|
|
265
|
+
local cwd="$1"
|
|
266
|
+
local tpath="" search_path="$cwd" proj_hash proj_dir
|
|
267
|
+
|
|
268
|
+
while [ -n "$search_path" ] && [ "$search_path" != "/" ]; do
|
|
269
|
+
proj_hash=$(echo "$search_path" | sed 's|^/\([a-zA-Z]\)/|\U\1--|; s|^[A-Z]:/|&|; s|:/|--|; s|/|-|g')
|
|
270
|
+
proj_dir="$HOME/.claude/projects/${proj_hash}"
|
|
271
|
+
if [ -d "$proj_dir" ]; then
|
|
272
|
+
# Use ls with head to avoid sorting huge file lists
|
|
273
|
+
tpath=$(ls -t "$proj_dir"/*.jsonl 2>/dev/null | head -1)
|
|
274
|
+
[ -n "$tpath" ] && break
|
|
275
|
+
fi
|
|
276
|
+
search_path=$(echo "$search_path" | sed 's|/[^/]*$||')
|
|
277
|
+
done
|
|
278
|
+
|
|
279
|
+
if [ -n "$tpath" ] && [ -f "$tpath" ]; then
|
|
280
|
+
local last_tool
|
|
281
|
+
# Only read the last 50 lines — enough to find the most recent tool_use
|
|
282
|
+
last_tool=$(tail -50 "$tpath" 2>/dev/null | grep -o '"type":"tool_use","id":"[^"]*","name":"[^"]*"' | tail -1 | sed 's/.*"name":"\([^"]*\)".*/\1/')
|
|
283
|
+
|
|
284
|
+
if [ -n "$last_tool" ]; then
|
|
285
|
+
case "$last_tool" in
|
|
286
|
+
Task)
|
|
287
|
+
# Lightweight agent count — check last 50 lines only
|
|
288
|
+
local agent_count
|
|
289
|
+
agent_count=$(tail -50 "$tpath" 2>/dev/null | grep -c '"type":"tool_use","id":"[^"]*","name":"Task"')
|
|
290
|
+
if [ "$agent_count" -gt 1 ]; then
|
|
291
|
+
echo "${agent_count} Agents"
|
|
292
|
+
else
|
|
293
|
+
local agent_desc
|
|
294
|
+
agent_desc=$(tail -50 "$tpath" 2>/dev/null | grep -o '"description":"[^"]*"' | tail -1 | sed 's/"description":"//;s/"$//')
|
|
295
|
+
if [ -n "$agent_desc" ]; then
|
|
296
|
+
echo "Agent($(echo "$agent_desc" | cut -c1-20))"
|
|
297
|
+
else
|
|
298
|
+
echo "Agent"
|
|
299
|
+
fi
|
|
300
|
+
fi ;;
|
|
301
|
+
Read) echo "Read" ;;
|
|
302
|
+
Write) echo "Write" ;;
|
|
303
|
+
Edit) echo "Edit" ;;
|
|
304
|
+
MultiEdit) echo "Multi Edit" ;;
|
|
305
|
+
Glob) echo "Search(Files)" ;;
|
|
306
|
+
Grep) echo "Search(Content)" ;;
|
|
307
|
+
Bash) echo "Terminal" ;;
|
|
308
|
+
WebSearch) echo "Web Search" ;;
|
|
309
|
+
WebFetch) echo "Web Fetch" ;;
|
|
310
|
+
Skill) echo "Skill" ;;
|
|
311
|
+
AskUserQuestion) echo "Asking..." ;;
|
|
312
|
+
EnterPlanMode) echo "Planning" ;;
|
|
313
|
+
ExitPlanMode) echo "Plan Ready" ;;
|
|
314
|
+
TaskCreate) echo "Task Create" ;;
|
|
315
|
+
TaskUpdate) echo "Task Update" ;;
|
|
316
|
+
TaskGet) echo "Task Get" ;;
|
|
317
|
+
TaskList) echo "Task List" ;;
|
|
318
|
+
TaskStop) echo "Task Stop" ;;
|
|
319
|
+
TaskOutput) echo "Task Output" ;;
|
|
320
|
+
NotebookEdit) echo "Notebook" ;;
|
|
321
|
+
*) echo "$last_tool" ;;
|
|
322
|
+
esac
|
|
323
|
+
return
|
|
324
|
+
fi
|
|
325
|
+
fi
|
|
326
|
+
|
|
327
|
+
# Fallback: check .ccs/task.md
|
|
328
|
+
local task_file="${cwd}/.ccs/task.md"
|
|
329
|
+
if [ -f "$task_file" ]; then
|
|
330
|
+
local last_skill
|
|
331
|
+
last_skill=$(grep -oE '/ccs-[a-z]+' "$task_file" 2>/dev/null | tail -1)
|
|
332
|
+
[ -n "$last_skill" ] && { echo "$last_skill"; return; }
|
|
333
|
+
fi
|
|
334
|
+
|
|
335
|
+
echo "Idle"
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if [ -n "$clean_cwd" ]; then
|
|
339
|
+
# Cache skill detection for 5 seconds (was 2s — too frequent for heavy I/O)
|
|
340
|
+
SL_SKILL=$(cache_get "skill-label" "_detect_skill '$clean_cwd'" 5)
|
|
341
|
+
fi
|
|
342
|
+
|
|
343
|
+
# --- 6h. New fields ---
|
|
344
|
+
|
|
345
|
+
# Session duration
|
|
346
|
+
dur_ms=$(json_nested "cost" "total_duration_ms")
|
|
347
|
+
[ -z "$dur_ms" ] && dur_ms=0
|
|
348
|
+
SL_DURATION=$(fmt_duration "$dur_ms")
|
|
349
|
+
|
|
350
|
+
# Lines changed
|
|
351
|
+
SL_LINES_ADDED=$(json_nested "cost" "total_lines_added")
|
|
352
|
+
SL_LINES_REMOVED=$(json_nested "cost" "total_lines_removed")
|
|
353
|
+
[ -z "$SL_LINES_ADDED" ] && SL_LINES_ADDED=0
|
|
354
|
+
[ -z "$SL_LINES_REMOVED" ] && SL_LINES_REMOVED=0
|
|
355
|
+
|
|
356
|
+
# API duration
|
|
357
|
+
api_ms=$(json_nested "cost" "total_api_duration_ms")
|
|
358
|
+
[ -z "$api_ms" ] && api_ms=0
|
|
359
|
+
SL_API_DURATION=$(fmt_duration "$api_ms")
|
|
360
|
+
|
|
361
|
+
# Vim mode (absent when vim is off)
|
|
362
|
+
SL_VIM_MODE=""
|
|
363
|
+
if [ "$cfg_show_vim" = "true" ]; then
|
|
364
|
+
SL_VIM_MODE=$(json_nested_val "vim" "mode")
|
|
365
|
+
fi
|
|
366
|
+
|
|
367
|
+
# Agent name (absent when not in agent mode)
|
|
368
|
+
SL_AGENT_NAME=""
|
|
369
|
+
if [ "$cfg_show_agent" = "true" ]; then
|
|
370
|
+
SL_AGENT_NAME=$(json_nested_val "agent" "name")
|
|
371
|
+
fi
|
|
372
|
+
|
|
373
|
+
# Cache stats (formatted)
|
|
374
|
+
SL_CACHE_CREATE=$(fmt_tok "$cur_cache_create")
|
|
375
|
+
SL_CACHE_READ=$(fmt_tok "$cur_cache_read")
|
|
376
|
+
|
|
377
|
+
# Burn rate (cost per minute)
|
|
378
|
+
SL_BURN_RATE=""
|
|
379
|
+
if [ "$cfg_show_burn_rate" = "true" ] && [ "$dur_ms" -gt 60000 ] 2>/dev/null; then
|
|
380
|
+
SL_BURN_RATE=$(awk -v cost="$cost_raw" -v ms="$dur_ms" \
|
|
381
|
+
'BEGIN { if (ms > 0 && cost+0 > 0) { rate = cost / (ms / 60000); printf "$%.2f/m", rate } }')
|
|
382
|
+
fi
|
|
383
|
+
|
|
384
|
+
# Exceeds 200k flag
|
|
385
|
+
SL_EXCEEDS_200K=""
|
|
386
|
+
[ -n "$(json_bool "exceeds_200k_tokens")" ] && SL_EXCEEDS_200K="true"
|
|
387
|
+
|
|
388
|
+
# Version
|
|
389
|
+
SL_VERSION=$(json_val "version")
|
|
390
|
+
|
|
391
|
+
# ── 7. Dynamic column widths ──
|
|
392
|
+
SL_C1=$(( SL_TERM_WIDTH / 2 - 4 ))
|
|
393
|
+
[ "$SL_C1" -lt 25 ] && SL_C1=25
|
|
394
|
+
[ "$SL_C1" -gt 42 ] && SL_C1=42
|
|
395
|
+
|
|
396
|
+
# ── 8. Source layout and render ──
|
|
397
|
+
layout_file="${STATUSLINE_DIR}/layouts/${active_layout}.sh"
|
|
398
|
+
if [ -f "$layout_file" ]; then
|
|
399
|
+
source "$layout_file"
|
|
400
|
+
else
|
|
401
|
+
source "${STATUSLINE_DIR}/layouts/standard.sh"
|
|
402
|
+
fi
|
|
403
|
+
|
|
404
|
+
render_layout
|
|
405
|
+
|
|
406
|
+
# ── 9. Cleanup watchdog ──
|
|
407
|
+
kill "$_SL_WATCHDOG_PID" 2>/dev/null
|
|
408
|
+
wait "$_SL_WATCHDOG_PID" 2>/dev/null
|