e45465d52d
Destination resolution
- Replace the single ResolveDestinationUseCase with four dedicated
functions, one per release type:
resolve_season_destination (pack season, folder move)
resolve_episode_destination (single episode, file move)
resolve_movie_destination (movie, file move)
resolve_series_destination (multi-season pack, folder move)
- Each returns a dedicated DTO carrying only the fields relevant to
that release type — no more polymorphic ResolvedDestination with
half the fields unused depending on the case.
- Looser series folder matching: exact computed-name match is reused
silently; any deviation (different group, multiple candidates) now
prompts the user with all options including the computed name.
Agent tools
- Four new tools wrapping the use cases above; old resolve_destination
removed from the registry.
- New move_to_destination tool: create_folder + move, chained — used
after a resolve_* call to perform the actual relocation.
- Low-level filesystem_operations module (create_folder, move via mv)
for instant same-FS renames (ZFS).
Prompt & persona
- New PromptBuilder (alfred/agent/prompt.py) replacing prompts.py:
identity + personality block, situational expressions, memory
schema, episodic/STM/config context, tool catalogue.
- Per-user expression system: knowledge/users/common.yaml +
{username}.yaml are merged at runtime; one phrase per situation
(greeting/success/error/...) is sampled into the system prompt.
qBittorrent integration
- Credentials now come from settings (qbittorrent_url/username/password)
instead of hardcoded defaults.
- New client methods: find_by_name, set_location, recheck — the trio
needed to update a torrent's save path and re-verify after a move.
- Host→container path translation settings (qbittorrent_host_path /
qbittorrent_container_path) for docker-mounted setups.
Subtitles
- Identifier: strip parenthesized qualifiers (simplified, brazil…) at
tokenization; new _tokenize_suffix used for the episode_subfolder
pattern so episode-stem tokens no longer pollute language detection.
- Placer: extract _build_dest_name so it can be reused by the new
dry_run path in ManageSubtitlesUseCase.
- Knowledge: add yue, ell, ind, msa, rus, vie, heb, tam, tel, tha,
hin, ukr; add 'fre' to fra; add 'simplified'/'traditional' to zho.
Misc
- LTM workspace: add 'trash' folder slot.
- Default LLM provider switched to deepseek.
- testing/debug_release.py: CLI to parse a release, hit TMDB, and
dry-run the destination resolution end-to-end.
80 lines
2.3 KiB
Python
80 lines
2.3 KiB
Python
"""Expression loader — charge et merge les fichiers YAML d'expressions par user."""
|
|
|
|
import random
|
|
from pathlib import Path
|
|
|
|
import yaml
|
|
|
|
_USERS_DIR = Path(__file__).parent.parent / "knowledge" / "users"
|
|
|
|
|
|
def _load_yaml(path: Path) -> dict:
|
|
if not path.exists():
|
|
return {}
|
|
return yaml.safe_load(path.read_text(encoding="utf-8")) or {}
|
|
|
|
|
|
def load_expressions(username: str | None) -> dict:
|
|
"""
|
|
Charge common.yaml et le merge avec {username}.yaml.
|
|
|
|
Retourne un dict avec :
|
|
- nickname: str (surnom de l'user, ou username en fallback)
|
|
- expressions: dict[situation -> list[str]]
|
|
"""
|
|
common = _load_yaml(_USERS_DIR / "common.yaml")
|
|
user_data = _load_yaml(_USERS_DIR / f"{username}.yaml") if username else {}
|
|
|
|
# Merge expressions : common + user (les phrases user s'ajoutent)
|
|
common_exprs: dict[str, list] = common.get("expressions", {})
|
|
user_exprs: dict[str, list] = user_data.get("expressions", {})
|
|
|
|
merged: dict[str, list] = {}
|
|
all_situations = set(common_exprs) | set(user_exprs)
|
|
for situation in all_situations:
|
|
base = list(common_exprs.get(situation, []))
|
|
extra = list(user_exprs.get(situation, []))
|
|
merged[situation] = base + extra
|
|
|
|
nickname = user_data.get("user", {}).get("nickname") or username or "mec"
|
|
|
|
return {
|
|
"nickname": nickname,
|
|
"expressions": merged,
|
|
}
|
|
|
|
|
|
def pick(expressions: dict, situation: str, nickname: str | None = None) -> str:
|
|
"""
|
|
Pioche une expression aléatoire pour une situation donnée.
|
|
|
|
Résout {user} avec le nickname si fourni.
|
|
Retourne une string vide si la situation n'existe pas.
|
|
"""
|
|
options = expressions.get("expressions", {}).get(situation, [])
|
|
if not options:
|
|
return ""
|
|
chosen = random.choice(options)
|
|
if nickname:
|
|
chosen = chosen.replace("{user}", nickname)
|
|
return chosen
|
|
|
|
|
|
def build_expressions_context(username: str | None) -> dict:
|
|
"""
|
|
Point d'entrée principal.
|
|
|
|
Retourne :
|
|
- nickname: str
|
|
- samples: dict[situation -> une phrase résolue] — une seule par situation
|
|
"""
|
|
data = load_expressions(username)
|
|
nickname = data["nickname"]
|
|
samples = {
|
|
situation: pick(data, situation, nickname) for situation in data["expressions"]
|
|
}
|
|
return {
|
|
"nickname": nickname,
|
|
"samples": samples,
|
|
}
|