Skip to content

feat(dj): dj-core, the shared tool layer under both DJ front doors - #428

Merged
LargeModGames merged 2 commits into
mainfrom
dj/core
Aug 8, 2026
Merged

LargeModGames merged 2 commits into
mainfrom
dj/core

Conversation

@LargeModGames

@LargeModGames LargeModGames commented Aug 8, 2026 •

Copy link
Copy Markdown
Owner

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-core cargo feature: the implementation both DJ front
doors sit on, with neither door attached yet.

  • The taste brief built from the local listening history (only aggregate
    track/artist/album names, no identifiers or timestamps)
  • The name-to-URI resolver: suggestions the catalogue cannot confidently match
    are dropped rather than approximated
  • The avoid-library index (Liked Songs plus owned/collaborative playlists)
  • The shared tool table and bulk-enqueue plumbing, with DjIndexLibrary as
    the one IoEvent this layer needs

Nothing consumes dj-core on its own, so the module carries a crate-level
scoped allow(dead_code) that narrows as the front doors land in the next
PRs, 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 verified
byte-identical to that branch. Stack: dj/core -> dj/mcp-server -> dj/brains ->
dj/screen -> dj/agent-plugin.

Testing

  • cargo fmt --all
  • cargo clippy --locked --no-default-features --features telemetry -- -D warnings
  • cargo clippy --locked --no-default-features --features telemetry,dj-core -- -D warnings
  • cargo test --no-default-features --features telemetry (567 passed)
  • cargo test --no-default-features --features telemetry,dj-core (612 passed)
  • cargo check --locked
  • clippy on the all-sources set minus audio-viz (that leg builds only in CI)

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

  • New Features
    • Added shared AI DJ capabilities for listening-history summaries, playback context, music discovery, vibe control, and queue management.
    • AI DJ suggestions can resolve tracks from Spotify, with optional YouTube fallback and duplicate filtering.
    • Added playlist and liked-song library indexing to improve personalized recommendations.
  • Bug Fixes
    • Improved queue validation for Spotify, local, Subsonic, and YouTube tracks.
    • Preserves user-added tracks when AI DJ queue content is refreshed or removed.

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.
@coderabbitai

coderabbitai Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Added a feature-gated AI DJ layer with shared state, tool schemas, listening-history briefs, Spotify library indexing, suggestion resolution, queue management, and CI coverage.

Changes

AI DJ functionality

Layer / File(s) Summary
DJ state and listening data
src/infra/dj/mod.rs, src/infra/dj/brief.rs, src/core/app.rs
Added DJ session state, transcript lifecycle helpers, suggestions, library metadata, listening-history briefs, deduplication, and default App initialization.
Tool parsing and queue execution
src/infra/dj/tools.rs, src/core/queue.rs, src/core/app.rs
Added deterministic tool schemas, typed argument validation, app-only execution, URI checks, DJ queue insertion, and removal of DJ-contributed tracks.
Spotify library indexing
src/infra/dj/library.rs, src/infra/network/dj.rs, src/infra/network/mod.rs
Added playlist and Liked Songs indexing, pagination, truncation handling, cached library state, and DjIndexLibrary dispatch.
Suggestion resolution
src/infra/dj/resolve.rs, src/infra/network/search.rs
Added Spotify matching, duplicate and library filtering, optional YouTube fallback, resolution reports, and crate-visible search results.
Feature gating and CI coverage
Cargo.toml, src/infra/mod.rs, src/infra/network/mod.rs, .github/workflows/ci.yml, CLAUDE.md
Added the dj-core feature, feature-gated modules, documentation, and all-sources coverage for check, test, and Clippy jobs.

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
Loading
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title uses the valid feat(dj): prefix and clearly summarizes the shared dj-core tool-layer changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dj/core
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch dj/core

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
src/infra/dj/resolve.rs (1)

226-254: 🎯 Functional Correctness | 🔵 Trivial | 🏗️ Heavy lift

Substring 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 win

Keep the get_now_playing structured payload shape stable across both branches.

The Some branch emits track, is_playing, is_live and queue_depth. The None branch omits is_live. An MCP client that reads is_live gets a missing key whenever nothing is playing. Add "is_live": false to 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

📥 Commits

Reviewing files that changed from the base of the PR and between 29e3c36 and 93c2967.

📒 Files selected for processing (14)
  • .github/workflows/ci.yml
  • CLAUDE.md
  • Cargo.toml
  • src/core/app.rs
  • src/core/queue.rs
  • src/infra/dj/brief.rs
  • src/infra/dj/library.rs
  • src/infra/dj/mod.rs
  • src/infra/dj/resolve.rs
  • src/infra/dj/tools.rs
  • src/infra/mod.rs
  • src/infra/network/dj.rs
  • src/infra/network/mod.rs
  • src/infra/network/search.rs

Comment thread src/core/queue.rs Resolved
Comment thread src/infra/dj/library.rs Resolved
Comment thread src/infra/dj/tools.rs Resolved
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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/infra/dj/library.rs (1)

116-121: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover the failed-playlist path with a regression test.

Add or adjust a test that verifies build_index returns truncated == true when collect_playlist fails 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

📥 Commits

Reviewing files that changed from the base of the PR and between 93c2967 and f6ef525.

📒 Files selected for processing (4)
  • src/core/queue.rs
  • src/infra/dj/library.rs
  • src/infra/dj/resolve.rs
  • src/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

@LargeModGames
LargeModGames merged commit 22f531e into main Aug 8, 2026
16 checks passed
@LargeModGames
LargeModGames deleted the dj/core branch August 8, 2026 08:24
LargeModGames added a commit that referenced this pull request Aug 8, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant