From 6c7324bfd894640f96b319d109f61fd041751721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D1=82=D0=B0=D0=BB=D0=B8=D0=B9=20=D0=9D=D0=B8?= =?UTF-8?q?=D0=BA=D0=B8=D1=82=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Mon, 8 Jun 2026 07:51:52 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=D1=81=D1=82=D0=B0=D1=82=D1=83=D1=81?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0=20?= =?UTF-8?q?=E2=80=94=20DeepSeek=20per-request=20=D1=81=D1=82=D0=BE=D0=B8?= =?UTF-8?q?=D0=BC=D0=BE=D1=81=D1=82=D1=8C=20=D0=B2=D0=BC=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=BE=20=D1=81=D1=82=D0=B0=D1=82=D0=B8=D1=87=D0=BD=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20=D0=B1=D0=B0=D0=BB=D0=B0=D0=BD=D1=81=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DeepSeek: накопленная стоимость сессии по DeepSeek-ценам (V4: $0.55/$2.19, V3: $0.27/$1.10) Anthropic/Kimi/прочие: рейт-лимиты (5h, 7d) без долларов Все: заполнение контекста (ctx%) Co-Authored-By: Claude Opus 4.8 --- home-configs/claude/statusline-command.sh | 74 ++++++++++++++++++++--- 1 file changed, 67 insertions(+), 7 deletions(-) diff --git a/home-configs/claude/statusline-command.sh b/home-configs/claude/statusline-command.sh index ad1b1d9..453039b 100644 --- a/home-configs/claude/statusline-command.sh +++ b/home-configs/claude/statusline-command.sh @@ -2,6 +2,8 @@ input=$(cat) cwd=$(echo "$input" | jq -r '.cwd') model=$(echo "$input" | jq -r '.model.display_name // empty') +model_id=$(echo "$input" | jq -r '.model.id // empty') +session_id=$(echo "$input" | jq -r '.session_id // empty') five_pct=$(echo "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty') five_reset=$(echo "$input" | jq -r '.rate_limits.five_hour.resets_at // empty') week_pct=$(echo "$input" | jq -r '.rate_limits.seven_day.used_percentage // empty') @@ -16,6 +18,69 @@ printf "\033[00;37m%s\033[00m" "$short_cwd" [ -n "$branch" ] && printf " \033[00;37m[%s]\033[00m" "$branch" [ -n "$model" ] && printf " \033[38;5;173m%s\033[00m" "$model" +# --- Накопленная стоимость DeepSeek (per-request) --- + +COST_FILE="$HOME/.cache/ai-setup/deepseek_cost_state" + +if [[ "$model_id" == *deepseek* ]] && [ -n "$session_id" ]; then + # Цены DeepSeek за 1M токенов + case "$model_id" in + *deepseek-v4*|*deepseek-reasoner*) + inp_p=0.55; out_p=2.19; cc_p=0.55; cr_p=0.14 ;; + *deepseek-chat*|*deepseek-v3*|*deepseek*) + inp_p=0.27; out_p=1.10; cc_p=0.27; cr_p=0.07 ;; + *) + inp_p=0.27; out_p=1.10; cc_p=0.27; cr_p=0.07 ;; + esac + + usage=$(echo "$input" | jq -r '.context_window.current_usage // empty') + + if [ -n "$usage" ] && [ "$usage" != "null" ]; then + in_tok=$(echo "$usage" | jq -r '.input_tokens // 0') + out_tok=$(echo "$usage" | jq -r '.output_tokens // 0') + cc_tok=$(echo "$usage" | jq -r '.cache_creation_input_tokens // 0') + cr_tok=$(echo "$usage" | jq -r '.cache_read_input_tokens // 0') + + last_cost=$(echo "scale=10; ($in_tok * $inp_p + $out_tok * $out_p + $cc_tok * $cc_p + $cr_tok * $cr_p) / 1000000" | bc -l) + + # Читаем накопленное + if [ -f "$COST_FILE" ]; then + existing=$(grep "^${session_id}|" "$COST_FILE" 2>/dev/null | tail -1) + fi + + if [ -n "$existing" ]; then + IFS='|' read -r sid old_in old_out old_cc old_cr old_total <<< "$existing" + if [ "$old_in" = "$in_tok" ] && [ "$old_out" = "$out_tok" ] && [ "$old_cc" = "$cc_tok" ] && [ "$old_cr" = "$cr_tok" ]; then + accumulated="$old_total" + else + accumulated=$(echo "scale=6; $old_total + $last_cost" | bc -l) + fi + else + accumulated="$last_cost" + fi + + mkdir -p "$(dirname "$COST_FILE")" + grep -v "^${session_id}|" "$COST_FILE" 2>/dev/null > "$COST_FILE.tmp" || true + echo "${session_id}|${in_tok}|${out_tok}|${cc_tok}|${cr_tok}|${accumulated}" >> "$COST_FILE.tmp" + mv "$COST_FILE.tmp" "$COST_FILE" 2>/dev/null + + deepseek_cost="$accumulated" + else + if [ -f "$COST_FILE" ]; then + existing=$(grep "^${session_id}|" "$COST_FILE" 2>/dev/null | tail -1) + if [ -n "$existing" ]; then + IFS='|' read -r sid _ _ _ _ total <<< "$existing" + deepseek_cost="$total" + fi + fi + fi + + cost_int=$(printf '%.0f' "$deepseek_cost" 2>/dev/null) + if [ "$cost_int" -gt 0 ] 2>/dev/null; then + printf " \033[00;35m\$%.2f\033[00m" "$deepseek_cost" + fi +fi + # Форматирует оставшееся время до сброса лимита fmt_remaining() { local reset_ts="$1" @@ -47,13 +112,8 @@ pct_color() { fi } -if [[ "$model" == *[Dd]eep[Ss]eek* ]]; then - cache_file="$HOME/.cache/ai-setup/deepseek_balance" - if [ -f "$cache_file" ]; then - balance=$(head -1 "$cache_file") - [ -n "$balance" ] && printf " \033[00;35m\$%s\033[00m" "$balance" - fi -else +# Рейт-лимиты для Anthropic / Kimi / прочих (НЕ DeepSeek) +if [[ "$model_id" != *deepseek* ]]; then if [ -n "$five_pct" ] && [ -n "$five_reset" ]; then five_int=$(printf '%.0f' "$five_pct") remaining=$(fmt_remaining "$five_reset")