feat: detect & link album mentions, not just artists (closes task/album-detection)

Source: task/album-detection (objective/linker-improvements) — project brief asks for artist OR album linking; MVP linked artists only.

- service/lib.js: pickAlbum (the exact-name gate, named for the album path) + linkResult now carries kind:"artist"|"album" (additive; defaults to artist so older clients keep working).
- service/resolver.js: one Spotify type=artist,album search per candidate, exact-match against either; returns {url,kind}; cache key includes the kind hint. resolveOne/resolveAll thread the LLM kind hint through.
- service/llm.js: parseClassification now returns Map(name -> "artist"|"album") so album-kind candidates route to the album path (.has() still works like the old Set).
- extension/extract.js: albumMatchesIn over two precise signals (quoted strings + album cue phrases "the album X", "X LP/EP"), folded into allMatchesIn.
- extension/content.js + styles.css: album links render italicised (.rsl-album) with an album tooltip; artist behavior unchanged.
- Tests: new pure-logic coverage in lib.test.js / llm.test.js / extract.test.cjs (album shaping, Map-kind routing, album candidate extraction). scripts/check.sh green.
- README.md + AGENTS.md: document album linking.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
paul
2026-06-22 22:33:32 +00:00
co-authored by Claude Opus 4.8
parent ef57761859
commit 2b4babf955
11 changed files with 243 additions and 83 deletions
+13 -6
View File
@@ -9,12 +9,16 @@ export const norm = (s) => String(s).normalize("NFKC").trim().toLowerCase();
export const googleSearch = (n) => `https://www.google.com/search?q=${encodeURIComponent(`${n} bandcamp`)}`;
// The precision lever: return the item whose name matches the candidate
// case-insensitively, else null. Tolerates null/garbage items.
// case-insensitively, else null. Tolerates null/garbage items. Used for both
// Spotify artist items and album items — the exact-name match is the same gate.
export function pickArtist(name, items) {
const want = norm(name);
return (items ?? []).find((a) => a && norm(a.name) === want) ?? null;
}
// Same exact-name gate, named for the album path's readability.
export const pickAlbum = pickArtist;
// A "/search" url means we don't have a direct artist page (just a search fallback).
export const isSearchUrl = (url) => typeof url === "string" && url.includes("/search");
@@ -29,14 +33,17 @@ export function isHttpUrl(u) {
}
}
// Build the single link to show for a confirmed name. Prefer the direct Spotify artist
// Build the single link to show for a confirmed name. Prefer the direct Spotify
// url (validated http(s), not a /search url); otherwise fall back to a Google→Bandcamp
// search. `primary` is what the extension renders ({ platform, url }).
export function linkResult(name, spotifyUrl) {
// search. `primary` is what the extension renders ({ platform, url }); `kind`
// ("artist" | "album") tells it which affordance to show. `kind` is additive — the
// extension defaults to "artist" when absent, so older clients keep working.
export function linkResult(name, spotifyUrl, kind = "artist") {
const k = kind === "album" ? "album" : "artist";
const direct = spotifyUrl && isHttpUrl(spotifyUrl) && !isSearchUrl(spotifyUrl) ? spotifyUrl : null;
if (direct) {
return { name, spotify: direct, primary: { platform: "spotify", url: direct } };
return { name, kind: k, spotify: direct, primary: { platform: "spotify", url: direct } };
}
const url = googleSearch(name);
return { name, google: url, primary: { platform: "google", url } };
return { name, kind: k, google: url, primary: { platform: "google", url } };
}