blob: 578dc2b641227d187c4ac18cc2c2df1180ee7da9 (
plain)
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
|
#!/usr/bin/env bash
input=$(cat)
session_name=$(echo "$input" | jq -r '.session_name // empty')
project_dir=$(echo "$input" | jq -r '.workspace.project_dir')
cwd=$(echo "$input" | jq -r '.workspace.current_dir')
model=$(echo "$input" | jq -r '.model.display_name')
total_in=$(echo "$input" | jq -r '.context_window.total_input_tokens // empty')
total_out=$(echo "$input" | jq -r '.context_window.total_output_tokens // empty')
ctx_size=$(echo "$input" | jq -r '.context_window.context_window_size // empty')
cur_in=$(echo "$input" | jq -r '.context_window.current_usage.input_tokens // empty')
cur_out=$(echo "$input" | jq -r '.context_window.current_usage.output_tokens // empty')
cache_read=$(echo "$input" | jq -r '.context_window.current_usage.cache_read_input_tokens // empty')
git_branch=$(cd "$cwd" 2>/dev/null && git -c core.useBuiltinFSMonitor=false rev-parse --abbrev-ref HEAD 2>/dev/null)
git_stat=$(cd "$cwd" 2>/dev/null && git -c core.useBuiltinFSMonitor=false diff --shortstat HEAD 2>/dev/null | awk '{
ins=0; del=0
for (i = 1; i <= NF; i++) {
if ($i ~ /insertion/) { ins = $(i-1) }
if ($i ~ /deletion/) { del = $(i-1) }
}
if (ins > 0 || del > 0) { printf "+%d/-%d", ins, del }
}')
output=""
[ -n "$session_name" ] && output="[$session_name] "
project_name=$(basename "$project_dir")
output="${output}${project_name}"
if [ -n "$git_branch" ]; then
git_info="git:$git_branch"
[ -n "$git_stat" ] && git_info="$git_info $git_stat"
output="$output ($git_info)"
fi
output="$output | $model"
if [ -n "$total_in" ] && [ -n "$total_out" ] && [ -n "$ctx_size" ]; then
total_used=$((total_in + total_out))
used_k=$(awk "BEGIN {printf \"%.1f\", $total_used/1000}")
output="$output | Session: ${used_k}k"
fi
if [ -n "$cur_in" ] && [ -n "$cur_out" ]; then
cur_total=$((cur_in + cur_out))
cur_k=$(awk "BEGIN {printf \"%.1f\", $cur_total/1000}")
if [ -n "$cache_read" ] && [ "$cache_read" != "0" ]; then
cache_read_k=$(awk "BEGIN {printf \"%.1f\", $cache_read/1000}")
output="$output | Cached: ${cache_read_k}k (last:${cur_k}k)"
else
output="$output | Last: ${cur_k}k"
fi
fi
echo "$output"
|