A patient listener for Apple Music: it watches every track, compares what each method says it is, and researches the disagreements.
StreamWatch has no window of its own. This is its status, and its controls, in RateCue's Developer Mode.
StreamWatch is an autonomous local-LLM research agent built to improve RateCue, the macOS menu bar app that shows Apple Music's sample rate and bit depth. It watches Apple Music on a dedicated appliance over long playback sessions. For every track it compares three ways of determining sample rate and bit depth, then researches each disagreement on the appliance, in the RateCue and LosslessSwitcher code, on GitHub and through DuckDuckGo. It writes up what it finds as draft RateCue issues.
See the StreamWatch charter for the authoritative mission, allowed authority, evidence doctrine, prohibited actions and human approval boundary. The agent's own system prompt implements the research subset of that charter; operations and security documentation describe the deployment boundaries.
Music appliance (macOS) LLM host (Linux + accelerator)
────────────────────────────── ─────────────────────────────────────
RateCue.app (Monitor Apple Music on) local inference, loopback-only
mac/collector.py (LaunchAgent, always on) llm-box/agent.py (systemd, always on)
log polling -> lifecycle_events, git mirrors: RateCue, LosslessSwitcher (hourly)
format_events, raw_log observe tracks -> scorecard + auto-leads
osascript -> playback_events focus lead -> LLM + tools:
system_profiler -> device_state ddg_search, fetch_url (DuckDuckGo)
RateCue menu-status.json -> ratecue_status github_search, github_read (GitHub API)
-> ~/streamwatch/streamwatch.db repo_grep, repo_history (local git)
mac/readonly_gate.py <── SSH (forced cmd) ──── query_playback_db, run_mac_command
read-only SQL + allowlisted diagnostics add_finding / add_lead / update_lead
(incl. read-only `ratecue` CLI commands) add_proposal -> proposals/*.md
-> /opt/streamwatch/agent.db, report.md
The collector runs without the LLM, so playback data keeps accumulating even when the LLM box is off. It samples Music logs with overlapping log show polls (3 seconds apart, 8-second lookback) and deduplicates events; this avoids the sustained CPU load of a continuous log stream. Every agent cycle rebuilds its context from the database, which means it can run for weeks without its context filling up.
The normal production layout is the diagram above: the Mac owns collection and the dedicated LLM box owns inference, repository mirrors and report generation. Ollama is loopback-only by default.
For a temporary test, the agent may run on the collection appliance while calling an OpenAI-compatible model server on another machine. In that mode the appliance's agent reaches the same read-only readonly_gate.py through a forced-command SSH key. See OPERATIONS.md for the exact smoke tests and service commands. Keep that arrangement off the normal playback/detection path and move the agent to the dedicated host for 24/7 operation.
The security model covers same-user trust, private Music metadata, external queries, remote inference and service credentials. For selecting and switching an OpenAI-compatible model host, use MODEL-SELECTION.md.
For every track start, StreamWatch puts three answers to "what format is this?" side by side: what Music's decoder reported, which is RateCue's method; what Music's audioCapabilities lines said, which is LosslessSwitcher's method; and what the RateCue menu app actually displayed. Each play is classified, and each mismatch, each unknown depth that had decoder evidence and each missing decoder report becomes a research lead.
The decoder report is Music's own statement, not independent ground truth. The agent treats it as the reference because it is the most direct evidence available. It is not the bit depth leaving the DAC.
The collector also measures how well the next track's format could have been predicted, both from its own playback history and from what Music logs about a queue item before it plays. These are measurements only. A hit is historical evidence, never permission to change audio hardware.
The three-way comparison defines each column and class, and next-track prediction metrics covers the prediction scoring.
The agent works in cycles. It refreshes its local mirrors of the RateCue and LosslessSwitcher code, pulls the new plays and flags the disagreements, picks the highest-priority open lead, and investigates it with its tools for a bounded number of steps: read-only queries on the Mac, the mirrors, GitHub and web search. It records findings and may draft a proposal. When no leads remain it brainstorms new ones, and then idles, still watching for new plays.
The agent has the cycle in detail, the tools and their limits, and the seed leads.
When the evidence supports a change, the agent calls add_proposal. That writes a draft issue (problem, proposed change, evidence, RateCue files involved) to /opt/streamwatch/proposals/NNN-title.md. Proposals with similar titles are merged and their new evidence is appended. Nothing is filed automatically. Review a draft and, if it holds up, file it:
gh issue create -R troylefevre65/RateCue -t "<title>" -F /opt/streamwatch/proposals/001-….mdThe proposals and the scorecard appear at the top of report.md.
-
Install Ubuntu Server 24.04 LTS with OpenSSH. Give it a DHCP reservation.
-
Set these in the BIOS:
- Integrated graphics as the primary display (monitor on the motherboard).
- Above 4G Decoding on.
- Restore on AC power loss: on.
-
Copy the
llm-box/folder to the box and run:chmod +x provision.sh sudo MAC_SSH=<mac-user>@<mac-host> LAN_CIDR=<trusted-lan-cidr> ./provision.sh sudo reboot # only the first time, after the NVIDIA driver install sudo MAC_SSH=<mac-user>@<mac-host> LAN_CIDR=<trusted-lan-cidr> ./provision.sh
Preinstall Ollama from a trusted operating-system package, or provide a reviewed installer with both
OLLAMA_INSTALLER_PATHandOLLAMA_INSTALLER_SHA256. The root script never downloads and executes an unpinned installer. It then installs the driver, git, the agent, a systemd unit, firewall rules and no-sleep settings, and configures Ollama for the available local resources. SetOLLAMA_BIND=0.0.0.0:11434explicitly only if remote Ollama access is required and firewall-restricted. The script finishes by printing the agent's public SSH key. Re-running it on an existing box keeps youragent.envvalues and only appends new settings.An Ollama server is not required when another trusted machine already provides an OpenAI-compatible endpoint. Set the following in the agent environment instead:
LLM_BASE_URL=http://<model-host>:8080/v1 LLM_API_KEY=<server-key-or-local-dummy> LLM_MODEL=<server-model-id> NO_THINK=1
With a thinking model,
NO_THINK=1sendschat_template_kwargs.enable_thinking=false. The server must support or ignore that extension. Do not expose an unauthenticated model server beyond a firewall-restricted trusted source. The operator-specific llama.cpp endpoint is configured privately and documented generically in MODEL-SELECTION.md. See OPERATIONS.md for a real tool-call check.On a private Windows model host, start the model with
llm-box/start-model-host.ps1plus operator-supplied executable/model paths and configure an operator-selectedLLM_MODELalias.
- Install RateCue (build it, or copy
RateCue.appto/Applications). Start it and turn on Monitor Apple Music. RateCue then keeps~/Library/Application Support/RateCue/menu-status.jsonup to date, and the collector records every change. - Copy the
mac/folder over. Ifpython3isn't available yet, runxcode-select --install. - Run the installer with the key that
provision.shprinted. It also links the RateCue CLI to~/streamwatch/ratecue; setRATECUE_BIN=/path/to/ratecueif the CLI is somewhere unusual.chmod +x install.sh ./install.sh "ssh-ed25519 AAAA... streamwatch-agent" - Turn on System Settings > General > Sharing > Remote Login.
- Play a track. When macOS asks whether python3/osascript may control Music, click Allow.
- Check that data is arriving:
sqlite3 -header ~/streamwatch/streamwatch.db "SELECT playback_id, decoder_rate_hz, decoder_bit_depth, ratecue_title, ratecue_vs_decoder, ls_vs_decoder FROM track_formats ORDER BY playback_id DESC LIMIT 5;"
The agent's key is locked to readonly_gate.py (command=...,restrict in authorized_keys). It can only:
- run read-only SQL against the collector database; SQLite authorization blocks track names, artists, albums, persistent IDs and raw JSON snapshots, including aliases;
- run
log showfor the exact Music-process predicate (with--lastup to 3 h, or--start/--endup to 3 h apart; no archives or files); - run
system_profiler SPAudioDataType -json(with identity-bearing fields removed),pmset -gandsw_vers; - run these RateCue CLI commands:
menu-status,log-format,decoder-status,--versionandfirst-track-trace export.
It cannot get a shell, write files, inspect arbitrary preference domains, change RateCue settings, or control Music. Reinstalling with the same public key replaces any older unrestricted entry with the forced read-only command.
# test the SSH gate once; this also records the Mac's host key
sudo -u streamwatch ssh -i /opt/streamwatch/.ssh/id_ed25519 -o StrictHostKeyChecking=accept-new <mac-user>@<mac-host>.local $(echo '{"op":"ping"}' | base64)
sudo systemctl enable --now streamwatch-agent
journalctl -u streamwatch-agent -f # live activity
less /opt/streamwatch/report.md # scorecard, proposals, findings, leads
ls /opt/streamwatch/proposals # draft RateCue issues
ollama ps # should show 100% GPUFor a temporary remote model, use systemctl status streamwatch-agent and the agent log instead of ollama ps. A healthy endpoint alone is insufficient: verify that a request can return a tool call.
| Variable | Default | Notes |
|---|---|---|
LLM_BASE_URL |
http://127.0.0.1:11434/v1 |
Ollama by default; may point to a firewall-restricted OpenAI-compatible host |
LLM_API_KEY |
ollama |
Dummy for local Ollama; keep a real key only in the service environment |
LLM_MODEL |
operator-selected | Any local model with reliable structured tool calling |
LLM_MAX_TOKENS |
4096 |
Maximum completion; lower values shorten slow thinking models |
LLM_TIMEOUT |
900 |
Per-model-call timeout in seconds |
NO_THINK |
0 |
1 sends chat_template_kwargs.enable_thinking=false (and a prompt fallback): faster, shallower cycles |
MAC_SSH |
empty | <mac-user>@<mac-host>; empty disables live Mac tools and observations |
MAC_SSH_KEY |
~/.ssh/id_ed25519 |
Private half of the forced-command key |
MAX_STEPS |
12 |
Tool steps per cycle |
MAX_LEAD_ATTEMPTS |
4 |
Attempts before an unanswered lead is auto-closed |
MAX_CYCLES |
0 |
Zero runs forever; a positive value is useful for bounded smoke tests |
CONTEXT_CHAR_BUDGET |
32000 |
About 9K tokens of messages; the 14 tool schemas add about 2K. Raise both together with OLLAMA_CONTEXT_LENGTH |
GITHUB_TOKEN |
empty | Fine-grained, public read-only. Needed for code search |
RATECUE_REPO |
troylefevre65/RateCue |
Target of proposals |
WATCH_REPOS |
RateCue, vincentneo/LosslessSwitcher |
Comma-separated repos mirrored for repo_grep/repo_history |
REPO_REFRESH |
3600 |
Seconds between mirror refreshes |
GITHUB_MIN_INTERVAL |
7 |
Seconds between GitHub API calls |
SEARCH_MIN_INTERVAL |
20 |
Seconds between DuckDuckGo searches (randomized ×1–1.6) |
SEARCH_BLOCK_BACKOFF |
900 |
First cooldown after DuckDuckGo rate-limits; doubles each time, max 2 h |
SEARCH_FALLBACK |
none |
ddgs uses the ddgs metasearch package (Bing, Brave, Mojeek and others, not DuckDuckGo) during cooldowns |
CYCLE_PAUSE / IDLE_PAUSE |
30 / 900 |
Seconds between cycles, and between idle checks |
After editing a dedicated-box service: sudo systemctl restart streamwatch-agent. Confirm the effective model and host in the first log line after restart; environment files are not re-read until restart.
To enable code search, create a fine-grained token with Public repositories (read-only) access and no other permissions. Put it in GITHUB_TOKEN= in /etc/streamwatch/agent.env (or the equivalent agent environment in a temporary deployment). Never commit that value.
- The decoder report is not ground truth. It is what Music says it decoded. Whether the device receives it bit-perfect depends on the device's rate and Core Audio, which the
resampled?flag and the device seed lead cover. - The view mirrors RateCue's selector only approximately. It uses nearest lifecycle, a ±30 s window and the 3 s ambiguity margin. It does not reproduce RateCue's retries, ledger or rate-change rules. A
MISMATCHis a lead to investigate, not proof of a RateCue bug. The agent is told to check the code before proposing a change. - RateCue's snapshot is sampled once per second and recorded only when it changes. A snapshot older than RateCue's five-second contract is stale.
ratecue_*is the state in effect one second before the next track started. - Apple can change these log formats in any macOS release.
raw_logkeeps matching Music log messages from StreamWatch's bounded audio-format predicate for 30 days, so changes can be investigated after the fact. It is not a copy of the entire Music log. - DuckDuckGo rate-limits automated queries. The block is IP-wide. The agent treats it as a cooldown and works on Mac-side and repository evidence in the meantime. If it stays blocked for long periods, set
SEARCH_FALLBACK=ddgs. device_stateis polled every 10 seconds, so short rate changes can be missed. Track comparisons only accept a sample from at most 30 seconds before the play (or five seconds after).- The SSH gate intentionally omits track and device identities. The local collector database retains raw Music metadata for an operator, but the default agent-facing view uses
playback_idand transport only. - Fetched pages are untrusted evidence, not agent instructions. Redirects are rechecked and private/loopback targets are refused.
- Model findings and confidence labels are hypotheses. The LLM decides which tool calls to make and which confidence word to store, so repeated queries, weak attribution and unsupported high-confidence wording can occur. The deterministic observations, scorecard and cited source evidence remain the review basis; proposals require human verification.
Run python3 -m unittest discover -s tests -v after a change. The tests cover repeated-track detection, report association, competing lifecycle starts, stale device state, SQL privacy authorization, the agent-readable track_formats view, log/CLI allowlists, forced-key replacement, redirect checks, external-query redaction and transcript trimming. GitHub Actions runs these tests plus Python and shell syntax validation. Python dependencies are pinned in llm-box/requirements.txt.
See OPERATIONS.md for service smoke tests, troubleshooting, upgrades and a 72-hour evidence capture, and SECURITY.md for trust boundaries and reporting.
- Charter: the mission, what the collector and the agent may and may not do, and the evidence doctrine.
- For developers and engineers: the collector's loops and database, the comparison view, the SSH gate's protocol and limits, the agent's cycle and tools, and what is kept from leaving the machine.
- Operations: installation checks, smoke tests, service commands and troubleshooting.
- Security model: trust boundaries, private data, and how to report a vulnerability.
- Model selection: choosing and switching an OpenAI-compatible model host.
- Contributing and code of conduct: the development workflow and the boundaries a change must keep.
- Changelog: what each version adds and fixes.
Copyright © 2026 the StreamWatch contributors. StreamWatch is free software, licensed under the GNU General Public License, version 3 only (GPL-3.0-only), and comes with no warranty. Every source file carries an SPDX identifier.
StreamWatch observes RateCue and follows its decoder-lifecycle patterns. Its comparison with the log-reading method follows the patterns of LosslessSwitcher, by Vincent Neo and the LosslessSwitcher contributors. See NOTICE for the full attribution and the licenses of the Python packages the agent installs.
StreamWatch is not affiliated with or endorsed by Apple, GitHub, DuckDuckGo or the LosslessSwitcher project. Apple Music is a trademark of Apple Inc.
