Give AI_ASSIST_CLEANUP the consumer it has never had: it describes the shape of a classification and decides nothing, so switching it off changes no deletion

This commit is contained in:
Gmer4Lfe
2026-08-26 18:03:17 -04:00
parent 96d8a5e3f0
commit 1838eed855
3 changed files with 94 additions and 1 deletions
+46
View File
@@ -2782,6 +2782,52 @@ apply_delete_budget() {
_BUDGET_DEFERRED_BYTES _BUDGET_DEFERRED_COUNT _BUDGET_STUCK <<< "$out"
}
# Asks the local generation model to characterise a block of evidence, for the one line a human
# would otherwise have to derive by hand. Prints the note on stdout and returns 0; returns 1 and
# prints nothing whenever anything at all is missing, off, slow or malformed.
#
# The contract is that failure is indistinguishable from the feature being switched off, because
# every caller must behave identically either way. An assist that can block a nightly cleanup is
# not an assist — so this never retries, never blocks longer than its timeout, and never returns
# a partial answer for a caller to interpret.
#
# Usage: note=$(ai_assist_note AI_ASSIST_CLEANUP "$prompt") && echo "$note"
# $1 name of the AI_ASSIST_* flag governing this caller — passed by name, checked here, so a
# caller cannot accidentally run an assist its own toggle says is off
# $2 the prompt, evidence included
# $3 timeout in seconds (default AI_ASSIST_TIMEOUT, else 45)
ai_assist_note() {
local flag="$1" prompt="$2" ai_timeout="${3:-${AI_ASSIST_TIMEOUT:-45}}"
[[ "${AI_ENABLED:-false}" == "true" ]] || return 1
[[ "${!flag:-false}" == "true" ]] || return 1
[[ -n "${MY_ID:-}" ]] || return 1
command -v jq >/dev/null 2>&1 || return 1
local u_var="${MY_ID}_OLLAMA_URL" m_var="${MY_ID}_OLLAMA_MODEL"
local url="${!u_var:-}" model="${!m_var:-}"
[[ -n "$url" && -n "$model" ]] || return 1
local body out
# temperature 0: this is a description of evidence, and the same evidence should not produce a
# different characterisation on a rerun.
body=$(jq -nc --arg m "$model" --arg p "$prompt" \
'{model:$m, prompt:$p, stream:false, options:{temperature:0}}' 2>/dev/null) || return 1
out=$(timeout "$ai_timeout" curl -sf --max-time "$ai_timeout" \
-H 'Content-Type: application/json' -d "$body" \
"${url%/}/api/generate" 2>/dev/null | jq -r '.response // empty' 2>/dev/null)
# Reasoning models emit a <think> block before the answer. It is not the note — a log line a
# human is meant to skim cannot open with several hundred words of the model talking itself
# through the arithmetic. Strip to the last close tag; a response with no block is unchanged.
[[ "$out" == *"</think>"* ]] && out="${out##*</think>}"
out="${out#"${out%%[![:space:]]*}"}"
[[ -n "$out" ]] || return 1
printf '%s\n' "$out"
}
# True if filepath's extension (case-insensitive) matches one of the given extensions.
# Usage: has_extension "$filepath" "${LIDARR_EXTENSIONS[@]}"
has_extension() {