Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
refactor(music): one playlist-name matcher for every music connector
Harald1df4af008756
diff --git a/jarvis/plugins/tool/_playlist_match.py b/jarvis/plugins/tool/_playlist_match.pynew file mode 100644index 0000000000..e7db4d5e04--- /dev/null+++ b/jarvis/plugins/tool/_playlist_match.py@@ -0,0 +1,73 @@+"""Shared "which of the user's playlists did they mean" matcher.++Used by every music connector (Spotify, YouTube Music): a spoken playlist name+arrives with filler ("my running playlist", "meine Lauf-Wiedergabeliste") and+inflection, and the provider only knows exact titles. One matcher, one set of+rules, so "play my running playlist" resolves the same way whichever service+is connected. Pure functions, stdlib only.+"""+from __future__ import annotations++import difflib+import re+from typing import Any++# Names people use for the liked-songs list; matched after normalisation.+LIKED_NAMES: frozenset[str] = frozenset({+ "liked", "likes", "liked songs", "liked music", "my likes", "favorites", "favourites",+ # i18n-allow: spoken-input vocabulary (de/es), not prose+ "gelikte songs", "gelikte lieder", "geliked", "meine likes", "favoriten",+ "lieblingslieder", "lieblingssongs",+ "canciones que me gustan", "me gusta", "favoritos", "mis me gusta",+})++# Filler around a playlist name ("my running playlist" → "running").+_PLAYLIST_NOISE_RE = re.compile(+ r"\b(my|the|playlist"+ r"|mein|meine|meiner|meinen|wiedergabeliste|die|der|das" # i18n-allow: spoken-input vocabulary+ r"|mi|mis|lista|el|la)\b", # i18n-allow: spoken-input vocabulary+ re.IGNORECASE,+)++# Below this similarity a "closest" title is a guess, not a match.+_FUZZY_FLOOR = 0.6+++def normalize_name(name: str) -> str:+ cleaned = _PLAYLIST_NOISE_RE.sub(" ", (name or "").lower())+ return re.sub(r"\s+", " ", cleaned).strip()+++def is_liked_name(name: str) -> bool:+ """Does ``name`` mean the user's liked songs rather than a named list?"""+ return normalize_name(name) in {normalize_name(n) for n in LIKED_NAMES} or (+ (name or "").strip().lower() in LIKED_NAMES+ )+++def match_playlist(+ name: str, playlists: list[dict[str, Any]], *, title_key: str = "title"+) -> dict[str, Any] | None:+ """The playlist a spoken name most plausibly means: exact, then contains,+ then a fuzzy ratio — never a wild guess below the floor."""+ wanted = normalize_name(name)+ if not wanted or not playlists:+ return None+ titled = [(p, normalize_name(str(p.get(title_key) or ""))) for p in playlists]+ for playlist, title in titled:+ if title == wanted:+ return playlist+ for playlist, title in titled:+ if wanted in title or (title and title in wanted):+ return playlist+ scored = sorted(+ ((difflib.SequenceMatcher(None, wanted, title).ratio(), p) for p, title in titled),+ key=lambda pair: pair[0],+ reverse=True,+ )+ if scored and scored[0][0] >= _FUZZY_FLOOR:+ return scored[0][1]+ return None+++__all__ = ["LIKED_NAMES", "is_liked_name", "match_playlist", "normalize_name"]diff --git a/jarvis/plugins/tool/youtube_music_rest.py b/jarvis/plugins/tool/youtube_music_rest.pyindex ad49484920..f0d1e51e73 100644--- a/jarvis/plugins/tool/youtube_music_rest.py+++ b/jarvis/plugins/tool/youtube_music_rest.py@@ -35,15 +35,15 @@ A direct gated action, never a spawn (AP-5/AP-14).from __future__ import annotationsimport asyncio-import difflibimport htmlimport logging-import refrom collections.abc import Awaitable, Callablefrom typing import Anyfrom jarvis.core.protocols import ExecutionContext, ToolResult+from ._playlist_match import is_liked_name, match_playlist+log = logging.getLogger(__name__)_API = "https://www.googleapis.com/youtube/v3"@@ -89,22 +89,6 @@ _MUSIC_CATEGORY_ID = "10"_SEARCH_MAX = 25_ART_TRACK_SUFFIX = " - Topic"-# Names people use for the liked-songs list; matched after normalisation.-_LIKED_NAMES: frozenset[str] = frozenset({- "liked", "likes", "liked songs", "liked music", "my likes", "favorites", "favourites",- # i18n-allow: spoken-input vocabulary (de/es), not prose- "gelikte songs", "gelikte lieder", "geliked", "meine likes", "favoriten",- "lieblingslieder", "lieblingssongs",- "canciones que me gustan", "me gusta", "favoritos", "mis me gusta",-})-# Filler around a playlist name ("my running playlist" → "running").-_PLAYLIST_NOISE_RE = re.compile(- r"\b(my|the|playlist"- r"|mein|meine|meiner|meinen|wiedergabeliste|die|der|das" # i18n-allow: spoken-input vocabulary- r"|mi|mis|lista|el|la)\b", # i18n-allow: spoken-input vocabulary- re.IGNORECASE,-)-# How long `play` watches the media session for the new track before it stops# claiming to know. A warm browser registers the session within a second; a# cold start needs four to five (measured live 2026-08-18: Edge from closed took@@ -240,40 +224,6 @@ def _slim_video(item: dict[str, Any]) -> dict[str, Any]:}-def _normalize_name(name: str) -> str:- cleaned = _PLAYLIST_NOISE_RE.sub(" ", name.lower())- return re.sub(r"\s+", " ", cleaned).strip()---def is_liked_name(name: str) -> bool:- return _normalize_name(name) in {_normalize_name(n) for n in _LIKED_NAMES} or (- name.strip().lower() in _LIKED_NAMES- )---def match_playlist(name: str, playlists: list[dict[str, Any]]) -> dict[str, Any] | None:- """The user's playlist a spoken name most plausibly means: exact, then- contains, then a fuzzy ratio — never a wild guess below the floor."""- wanted = _normalize_name(name)- if not wanted or not playlists:- return None- titled = [(p, _normalize_name(str(p.get("title") or ""))) for p in playlists]- for playlist, title in titled:- if title == wanted:- return playlist- for playlist, title in titled:- if wanted in title or (title and title in wanted):- return playlist- scored = sorted(- ((difflib.SequenceMatcher(None, wanted, title).ratio(), p) for p, title in titled),- key=lambda pair: pair[0],- reverse=True,- )- if scored and scored[0][0] >= 0.6:- return scored[0][1]- return None--class YouTubeMusicRestTool:name: str = "youtube_music"risk_tier: str = "monitor"