From f0c92d6b9938bd6bb2d6e24aeb833fed175a9222 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Mon, 5 Oct 2026 12:53:03 +0200 Subject: fix(ai): count a running sd-cli as the sd engine fanfictioner runs sd-cli one-shot, not through sd-server, so the sd row read down while a CLI run held VRAM and generated. A running sd-cli now reads up and busy, its model marked (sd-cli), and outranks the web UI. The model is the first --diffusion-model/-m: sd-cli's prompt follows and is free text that may contain "-m". Co-Authored-By: Claude Opus 5.5 --- desktop/modules/ai/ai-state.sh | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'desktop/modules/ai/ai-state.sh') diff --git a/desktop/modules/ai/ai-state.sh b/desktop/modules/ai/ai-state.sh index b3b9642..8b10368 100755 --- a/desktop/modules/ai/ai-state.sh +++ b/desktop/modules/ai/ai-state.sh @@ -15,7 +15,7 @@ # these six lines, tab separated, and exits 0: # # enginellamaup|downidle|busymodel -# enginesdup|downidle|busymodel +# enginesdup|downidle|busymodel, "(sd-cli)" for a CLI run # appassistantrunning|stopped- # appchatrunning|stopped- # appimggenrunning|stoppedmodel @@ -50,21 +50,34 @@ llama() { row engine llama up "$busy" "${id:--}" } -sd() { - local line words i model=- busy=idle mtime - line="$(pgrep -axo sd-server)" || { row engine sd down idle -; return; } - read -ra words <<<"$line" +# The basename of the model in a "pid args..." line, or "-". First match +# wins: sd-cli's prompt comes later and is free text that may contain "-m". +model_of() { + local words i + read -ra words <<<"$1" for ((i = 1; i < ${#words[@]} - 1; i++)); do case "${words[i]}" in - --diffusion-model|-m) model="${words[i + 1]##*/}" ;; + --diffusion-model|-m) printf '%s' "${words[i + 1]##*/}"; return ;; esac done + printf - +} + +sd() { + local line busy=idle mtime + # A one-shot sd-cli (fanfictioner runs them) holds VRAM and generates for + # as long as it lives, so it outranks whatever the web UI is doing. + if line="$(pgrep -axo sd-cli)"; then + row engine sd up busy "$(model_of "$line") (sd-cli)" + return + fi + line="$(pgrep -axo sd-server)" || { row engine sd down idle -; return; } # ponytail: sd-server has no progress endpoint, but its log streams # progress bars while generating, so a log written in the last 5s means # busy. A step slower than 5s reads as idle. mtime="$(stat -c %Y "$SD_LOG" 2>/dev/null)" || mtime=0 (( $(date +%s) - mtime < 5 )) && busy=busy - row engine sd up "$busy" "$model" + row engine sd up "$busy" "$(model_of "$line")" } apps() { -- cgit v1.2.3