music-audit: overnight follow-up timer and cohere strict-mode fix
followup.sh + music-followup.timer wake a headless pi session when the AcoustID identification pass ends: it writes the duplicate report (read-only), records the identification totals and the Jellyfin grouping, then starts the agent in tmux. It is idempotent via a state file and Persistent=true so a suspended Deck catches up on resume. Two things had to be worked around: pi lives in a mise npm install (a timer has no shell profile), and Cohere rejects requests whose tool definitions mix strict and non-strict in pi 1.4.0 headless, so the default model is a local Ollama one. Also sets compat.supportsStrictMode=false for cohere in the pi model catalog.
This commit is contained in:
1 parent
6bc006e90a
commit
3fd4ae0109
6 files changed
+179
-2
No files matched your search
@@ -155,7 +155,8 @@
|
||||
"supportsStore": false,
|
||||
"supportsStrictMode": false,
|
||||
"supportsUsageInStreaming": true
|
||||
}
|
||||
},
|
||||
"supportsStrictMode": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,3 +47,22 @@ Loose download folders are imported as **singletons** (`beet import -s`), which
|
||||
track its own album/albumartist instead of one pooled fake album. Files that MusicBrainz
|
||||
cannot match are given a single's shape directly (album = title, albumartist = artist,
|
||||
track 1/1) because quiet mode will not import unmatched singletons even with `asis`.
|
||||
|
||||
## Overnight follow-up (`followup.sh`)
|
||||
|
||||
`followup.sh` runs from `music-followup.timer` (user timer, every 15 min, `Persistent=true`
|
||||
so a suspended Deck catches up on resume). It is a cheap no-op until the identify process on
|
||||
yveltal is gone, then, once only:
|
||||
|
||||
1. writes the duplicate report (`music-duplicates --out /var/lib/beets/duplicates.json`),
|
||||
2. collects the identification totals and the Jellyfin "Licensed to Ill" view,
|
||||
3. writes `~/music-followup-report.md`,
|
||||
4. starts `pi -p` in tmux session `music-followup` to work through the follow-up.
|
||||
|
||||
Knobs: `FORCE=1` skips the "still running" check (for testing the report path),
|
||||
`MUSIC_FOLLOWUP_NO_AGENT=1` writes the report without starting an agent, `MODEL=...`
|
||||
picks the model (default `ollama/gemma4-12b-qat-128k`, because Cohere rejects mixed
|
||||
strict-mode tool definitions in `pi` 1.4.0's headless mode).
|
||||
|
||||
`jellyfin-licensed.py` prints how Jellyfin currently groups that album — a healthy
|
||||
result is "no album matching ... any more".
|
||||
Executable
+93
@@ -0,0 +1,93 @@
|
||||
#!/usr/bin/env bash
|
||||
# Wait for the AcoustID identification pass to finish, then hand the next stage
|
||||
# to an agent session — so the overnight work does not sit idle until morning.
|
||||
#
|
||||
# Runs from a systemd timer every 15 minutes. It is a cheap no-op until:
|
||||
# * the identify process on yveltal is gone, AND
|
||||
# * the state file does not exist yet (so it acts exactly once).
|
||||
#
|
||||
# What it does when the pass is over:
|
||||
# 1. writes the duplicate report (read-only, nothing is deleted),
|
||||
# 2. collects the identification totals and the Jellyfin view,
|
||||
# 3. writes ~/music-followup-report.md,
|
||||
# 4. starts a `pi` session in tmux (session: music-followup) to act on it.
|
||||
#
|
||||
# Set MUSIC_FOLLOWUP_NO_AGENT=1 to only produce the report.
|
||||
|
||||
set -uo pipefail
|
||||
|
||||
SSH_HOST="${SSH_HOST:-yveltal_local}"
|
||||
STATE="${STATE:-$HOME/.local/state/music-followup.done}"
|
||||
REPORT="${REPORT:-$HOME/music-followup-report.md}"
|
||||
LOG="${LOG:-$HOME/music-followup.log}"
|
||||
MODEL="${MODEL:-ollama/gemma4-12b-qat-128k}" # Cohere rejects mixed strict-mode tools in pi 1.4.0 headless
|
||||
# pi lives in a mise npm install; a systemd timer has no shell profile to find it.
|
||||
PI_BIN="${PI_BIN:-$(command -v pi 2>/dev/null || ls "$HOME"/.local/share/mise/installs/npm-earendil-works-pi-coding-agent/*/node_modules/.bin/pi 2>/dev/null | head -1)}"
|
||||
JELLYFIN_KEY="${JELLYFIN_KEY:-6fd79f0a2cfe4465bb1a0167c3660064}"
|
||||
JELLYFIN_URL="${JELLYFIN_URL:-http://10.0.0.38:8096}"
|
||||
|
||||
mkdir -p "$(dirname "$STATE")" "$(dirname "$LOG")"
|
||||
|
||||
# Already handled.
|
||||
[ -f "$STATE" ] && exit 0
|
||||
|
||||
# Still working? (FORCE=1 skips this, for testing the report path)
|
||||
if [ "${FORCE:-0}" != "1" ] && ssh -o BatchMode=yes -o ConnectTimeout=10 "$SSH_HOST" 'pgrep -f music-identify >/dev/null' 2>/dev/null; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Process gone: distinguish "finished" from "died".
|
||||
finished=$(ssh -o BatchMode=yes -o ConnectTimeout=10 "$SSH_HOST" \
|
||||
'sudo -n grep -E "finished: matched=" /var/log/music-identify.log | tail -1' 2>/dev/null)
|
||||
index_lines=$(ssh -o BatchMode=yes -o ConnectTimeout=10 "$SSH_HOST" \
|
||||
'sudo -n wc -l < /var/lib/beets/acoustid-index.jsonl' 2>/dev/null | tr -d ' ')
|
||||
|
||||
if [ -z "$finished" ]; then
|
||||
verdict="INCOMPLETE — the identify process is gone but the log has no completion line (index has ${index_lines:-?} rows)"
|
||||
else
|
||||
verdict="COMPLETE — ${finished#*finished: } (index has ${index_lines:-?} rows)"
|
||||
fi
|
||||
|
||||
# Duplicate report (read-only).
|
||||
dupe_summary=$(ssh -o BatchMode=yes -o ConnectTimeout=10 "$SSH_HOST" \
|
||||
'sudo -n /opt/beets-venv/bin/python /usr/local/bin/music-duplicates --out /var/lib/beets/duplicates.json' 2>&1 | head -6)
|
||||
|
||||
# How Jellyfin currently groups the worst offender.
|
||||
jf_children=$("$(dirname "$0")/jellyfin-licensed.py" 2>/dev/null)
|
||||
|
||||
cat > "$REPORT" <<EOF
|
||||
# Music library — overnight follow-up
|
||||
|
||||
Generated: $(date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||
|
||||
## Identification pass
|
||||
$verdict
|
||||
|
||||
## Duplicate report (nothing deleted)
|
||||
\`\`\`
|
||||
$dupe_summary
|
||||
\`\`\`
|
||||
Full JSON on yveltal: \`/var/lib/beets/duplicates.json\`
|
||||
|
||||
## Jellyfin: "Licensed to Ill" grouping
|
||||
$jf_children
|
||||
|
||||
## What to do next
|
||||
1. Read the duplicate report. \`exact\` groups are same-audio re-encodes — review the
|
||||
nominated keeper before removing anything. \`uncertain\` groups need your eyes.
|
||||
2. Stage B (album-level MusicBrainz imports) has not been started on purpose: it
|
||||
rewrites tags across thousands of files and should run while you can watch it.
|
||||
The rollback snapshot is \`/var/lib/beets/tags-backup-*.jsonl.gz\`.
|
||||
3. The Jellyfin scan must have finished before any further rescan, or the "Licensed
|
||||
to Ill" grouping will still look stale in the UI.
|
||||
EOF
|
||||
|
||||
echo "$(date -u +%H:%M:%SZ) followup written: ${verdict}" >> "$LOG"
|
||||
|
||||
if [ "${MUSIC_FOLLOWUP_NO_AGENT:-0}" != "1" ] && ! tmux has-session -t music-followup 2>/dev/null; then
|
||||
prompt="Overnight music-library follow-up. Read $REPORT first. Then continue the plan in ~/HANDOFF-rdtc-decypharr.md's sibling context and the LaPis memories about the Jellyfin music library: (1) verify the Jellyfin scan finished and that the 'Licensed to Ill' album now holds only Beastie Boys tracks; (2) summarise the exact/uncertain duplicate groups from /var/lib/beets/duplicates.json on yveltal so a human can approve them — do NOT delete anything; (3) if the tag snapshot /var/lib/beets/tags-backup-*.jsonl.gz is complete, begin Stage B (album-level beets imports) on the largest discography folders one at a time, logging each run, and stop before anything destructive. Report what you did at the top of $REPORT."
|
||||
tmux new-session -d -s music-followup "cd $HOME && \"$PI_BIN\" -p --model $MODEL $(printf '%q' "$prompt") >> $LOG 2>&1"
|
||||
echo "$(date -u +%H:%M:%SZ) agent session started (tmux: music-followup)" >> "$LOG"
|
||||
fi
|
||||
|
||||
touch "$STATE"
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Print how Jellyfin currently groups the mis-matched "Licensed to Ill" album.
|
||||
|
||||
One album row plus its child count, or nothing if the album is gone — which is
|
||||
the healthy outcome after the tags were fixed.
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import urllib.request
|
||||
|
||||
KEY = os.environ.get("JELLYFIN_KEY", "6fd79f0a2cfe4465bb1a0167c3660064")
|
||||
BASE = os.environ.get("JELLYFIN_URL", "http://10.0.0.38:8096")
|
||||
|
||||
|
||||
def api(path):
|
||||
req = urllib.request.Request(BASE + path,
|
||||
headers={"Authorization": 'MediaBrowser Token="%s"' % KEY})
|
||||
with urllib.request.urlopen(req, timeout=30) as r:
|
||||
return json.loads(r.read().decode())
|
||||
|
||||
|
||||
def main():
|
||||
term = os.environ.get("JELLYFIN_TERM", "Licensed")
|
||||
try:
|
||||
albums = api("/Items?Recursive=true&IncludeItemTypes=MusicAlbum"
|
||||
"&SearchTerm=%s&Fields=Path" % term).get("Items", [])
|
||||
except Exception as e:
|
||||
print(" could not query Jellyfin: %s" % type(e).__name__)
|
||||
return 0
|
||||
if not albums:
|
||||
print(" no album matching %r any more — the mis-grouping is gone" % term)
|
||||
return 0
|
||||
for a in albums:
|
||||
try:
|
||||
kids = api("/Items?ParentId=%s&Limit=1" % a["Id"]).get("TotalRecordCount")
|
||||
except Exception:
|
||||
kids = "?"
|
||||
print(" %-24s %s songs (albumartist: %s)"
|
||||
% (a.get("Name"), kids, a.get("AlbumArtist") or "?"))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=Music library follow-up (duplicate report + agent handoff)
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
# The agent it launches needs pi, secretctl and tmux on PATH, and a model key.
|
||||
Environment=PATH=%h/.local/bin:%h/.nix-profile/bin:/usr/local/bin:/usr/bin:/bin
|
||||
Environment=HOME=%h
|
||||
ExecStart=%h/.dotfiles/tools/music-audit/followup.sh
|
||||
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Check every 15 minutes whether the AcoustID pass has finished
|
||||
|
||||
[Timer]
|
||||
OnBootSec=5m
|
||||
OnUnitActiveSec=15m
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
Reference in new issue
Block a user