Repository navigation
feat(dj): dj-core, the shared tool layer under both DJ front doors - #428
Conversation
Bottom of a five-PR stack splitting feat/ai-dj-mcp-server into reviewable pieces. This lands the implementation both DJ front doors sit on: the taste brief built from the local listening history, the name to URI resolver, the avoid-library index, and the tool table, with no MCP server and no in-TUI DJ screen attached yet. Nothing consumes dj-core until those front doors arrive, so the module carries a crate-level allow(dead_code) and CI exercises it through the all-sources leg.
📝 WalkthroughWalkthroughAdded a feature-gated AI DJ layer with shared state, tool schemas, listening-history briefs, Spotify library indexing, suggestion resolution, queue management, and CI coverage. ChangesAI DJ functionality
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant DjToolCall
participant App
participant Network
participant Spotify
Client->>DjToolCall: submit DJ operation
DjToolCall->>App: execute app-only operation
DjToolCall->>Network: route network-dependent operation
Network->>Spotify: index library or resolve tracks
Spotify-->>Network: return library or track data
Network-->>App: return DJ operation result
App-->>Client: report queue, playback, history, or vibe outcome
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
src/infra/dj/resolve.rs (1)
226-254: 🎯 Functional Correctness | 🔵 Trivial | 🏗️ Heavy liftSubstring matching accepts some of the cases this function exists to reject.
Two gaps follow from
contains:
- Artist: a candidate credited "Radiohead Tribute Band" contains the wanted "radiohead", so it scores 1 and is accepted. The doc comment names tribute and cover versions as wrong. The existing test only covers "Karaoke Kings", which does not contain the wanted artist, so it does not catch this.
- Title: a short wanted title such as "Go" is a substring of almost any candidate title, so the title floor stops rejecting.
A token-set check (require every token of the wanted artist to appear as a whole token in the candidate, and require a minimum wanted-title length before allowing the substring branch) keeps the "Bob Moses" vs "Bob Moses, RAC" case working while closing both gaps. Add tests for the tribute credit and the short title if you change this.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/infra/dj/resolve.rs` around lines 226 - 254, Replace the broad artist substring check in the matching function with whole-token containment for every normalized wanted-artist token, preserving exact matches and the existing empty-artist behavior; this must reject credits such as “Radiohead Tribute Band” while still accepting “Bob Moses, RAC”. In the title matching branch, require a minimum normalized wanted-title length before allowing substring matches, so short titles like “Go” are rejected unless exactly equal. Add regression tests covering both the tribute artist and short-title cases.src/infra/dj/tools.rs (1)
556-569: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winKeep the
get_now_playingstructured payload shape stable across both branches.The
Somebranch emitstrack,is_playing,is_liveandqueue_depth. TheNonebranch omitsis_live. An MCP client that readsis_livegets a missing key whenever nothing is playing. Add"is_live": falseto the empty branch so the object keys do not depend on playback state.🛠️ Proposed fix
None => ToolOutcome::with_data( format!("Nothing is playing ({queue_depth} track(s) queued)"), - json!({"track": Value::Null, "is_playing": false, "queue_depth": queue_depth}), + json!({ + "track": Value::Null, + "is_playing": false, + "is_live": false, + "queue_depth": queue_depth, + }), ),🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/infra/dj/tools.rs` around lines 556 - 569, Update the None branch of get_now_playing to include is_live: false in its structured JSON payload, matching the keys emitted by the Some branch while preserving the existing values for track, is_playing, and queue_depth.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/core/queue.rs`:
- Around line 49-54: Update is_playable_track_uri to reject the exact empty
Spotify track form "spotify:track:" while continuing to accept Spotify URIs with
a non-empty identifier and preserving the existing behavior for file:,
subsonic:, and youtube: schemes. Add the corresponding assertion in
only_single_track_uris_are_playable.
In `@src/infra/dj/library.rs`:
- Around line 101-118: Update build_index’s collect_playlist error branch to
mark library.truncated as true whenever a playlist is skipped, while preserving
the existing debug logging and continued iteration behavior.
In `@src/infra/dj/tools.rs`:
- Around line 350-360: Update the named-entry match arm in the URI/title/artist
parsing logic to require both !title.trim().is_empty() and
!artist.trim().is_empty(). Reject blank artists through the existing
argument-error path rather than constructing a DjSuggestion with an empty
artist; preserve the current trimming and QueueItem::Named behavior for valid
values.
---
Nitpick comments:
In `@src/infra/dj/resolve.rs`:
- Around line 226-254: Replace the broad artist substring check in the matching
function with whole-token containment for every normalized wanted-artist token,
preserving exact matches and the existing empty-artist behavior; this must
reject credits such as “Radiohead Tribute Band” while still accepting “Bob
Moses, RAC”. In the title matching branch, require a minimum normalized
wanted-title length before allowing substring matches, so short titles like “Go”
are rejected unless exactly equal. Add regression tests covering both the
tribute artist and short-title cases.
In `@src/infra/dj/tools.rs`:
- Around line 556-569: Update the None branch of get_now_playing to include
is_live: false in its structured JSON payload, matching the keys emitted by the
Some branch while preserving the existing values for track, is_playing, and
queue_depth.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 7e8e7f17-56a1-4433-b052-07c853c550fa
📒 Files selected for processing (14)
.github/workflows/ci.ymlCLAUDE.mdCargo.tomlsrc/core/app.rssrc/core/queue.rssrc/infra/dj/brief.rssrc/infra/dj/library.rssrc/infra/dj/mod.rssrc/infra/dj/resolve.rssrc/infra/dj/tools.rssrc/infra/mod.rssrc/infra/network/dj.rssrc/infra/network/mod.rssrc/infra/network/search.rs
A bare scheme with nothing behind it ("spotify:track:", "file:") no longer
counts as a playable track URI. A playlist the library crawl had to skip now
marks the index partial, so the avoid-library filter stops claiming to have
seen everything. A queue entry with a blank artist is an argument error rather
than a suggestion the resolver can never find. get_now_playing sends the same
keys whether or not something is playing. And the resolver stops accepting a
tribute band for the artist it covers, or a two-letter title as a substring of
anything: artist credits are compared as lists of artists, and only titles of
four normalised characters or more may match as substrings.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/infra/dj/library.rs (1)
116-121: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover the failed-playlist path with a regression test.
Add or adjust a test that verifies
build_indexreturnstruncated == truewhencollect_playlistfails and continues indexing later playlists.As per coding guidelines, add or adjust tests when behavior changes.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/infra/dj/library.rs` around lines 116 - 121, Add a regression test for build_index covering a collect_playlist failure: assert the returned index has truncated == true and verify indexing continues to subsequent playlists. Reuse the existing playlist/index test fixtures and failure-injection mechanism, keeping successful playlist behavior unchanged.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/infra/dj/library.rs`:
- Around line 116-121: Add a regression test for build_index covering a
collect_playlist failure: assert the returned index has truncated == true and
verify indexing continues to subsequent playlists. Reuse the existing
playlist/index test fixtures and failure-injection mechanism, keeping successful
playlist behavior unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 2eec0485-c3e6-4479-9536-5966b6d2c268
📒 Files selected for processing (4)
src/core/queue.rssrc/infra/dj/library.rssrc/infra/dj/resolve.rssrc/infra/dj/tools.rs
🚧 Files skipped from review as they are similar to previous changes (3)
- src/infra/dj/resolve.rs
- src/infra/dj/tools.rs
- src/core/queue.rs
This branch is the pre-split reference tree, so it has to stay byte-equal with the top of the stack. Two rounds of review fixes had landed on the stack branches without coming back here: the five core-layer findings that went onto dj/core before #428 merged, and the fifteen MCP-layer ones just made on dj/mcp-server. Tree is now identical to dj/agent-plugin again.
Summary
Bottom of a 5-PR stack splitting the AI DJ / MCP server work (~16k lines) into
reviewable layers. Part of #196.
This PR adds the
dj-corecargo feature: the implementation both DJ frontdoors sit on, with neither door attached yet.
track/artist/album names, no identifiers or timestamps)
are dropped rather than approximated
DjIndexLibraryasthe one IoEvent this layer needs
Nothing consumes
dj-coreon its own, so the module carries a crate-levelscoped
allow(dead_code)that narrows as the front doors land in the nextPRs, and CI exercises it through the all-sources leg until the single-door
legs arrive.
The stack re-authors this work into layers, so commits here do not correspond
1:1 to
feat/ai-dj-mcp-server; the tree at the top of the stack is verifiedbyte-identical to that branch. Stack: dj/core -> dj/mcp-server -> dj/brains ->
dj/screen -> dj/agent-plugin.
Testing
Additional notes
Review scope for this PR is the shared layer only; the MCP server, the model
backends, the DJ screen, and the agent plugin each get their own PR in the
stack.
💬 Questions or want to chat with other contributors? Join the spotatui Discord.
Summary by CodeRabbit