feat: split resolve_destination, persona-driven prompts, qBittorrent relocation

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.
This commit is contained in:
2026-05-14 05:01:59 +02:00
parent 1723b9fa53
commit e45465d52d
81 changed files with 2904 additions and 896 deletions
+17 -5
View File
@@ -2,22 +2,20 @@
Tests for alfred.agent.registry — tool registration and JSON schema generation.
"""
import pytest
from alfred.agent.registry import Tool, _create_tool_from_function, make_tools
from alfred.settings import settings
# ---------------------------------------------------------------------------
# _create_tool_from_function
# ---------------------------------------------------------------------------
class TestCreateToolFromFunction:
class TestCreateToolFromFunction:
def test_name_from_function(self):
def my_tool(x: str) -> dict:
"""Does something."""
return {}
tool = _create_tool_from_function(my_tool)
assert tool.name == "my_tool"
@@ -28,12 +26,14 @@ class TestCreateToolFromFunction:
More details here.
"""
return {}
tool = _create_tool_from_function(my_tool)
assert tool.description == "First line description."
def test_description_fallback_to_name(self):
def no_doc(x: str) -> dict:
return {}
tool = _create_tool_from_function(no_doc)
assert tool.description == "no_doc"
@@ -41,6 +41,7 @@ class TestCreateToolFromFunction:
def tool(a: str, b: int) -> dict:
"""Tool."""
return {}
t = _create_tool_from_function(tool)
assert "a" in t.parameters["required"]
assert "b" in t.parameters["required"]
@@ -49,6 +50,7 @@ class TestCreateToolFromFunction:
def tool(a: str, b: str = "default") -> dict:
"""Tool."""
return {}
t = _create_tool_from_function(tool)
assert "a" in t.parameters["required"]
assert "b" not in t.parameters["required"]
@@ -57,6 +59,7 @@ class TestCreateToolFromFunction:
def tool(a: str, b: str | None = None) -> dict:
"""Tool."""
return {}
t = _create_tool_from_function(tool)
assert "b" not in t.parameters["required"]
@@ -64,6 +67,7 @@ class TestCreateToolFromFunction:
def tool(x: str) -> dict:
"""T."""
return {}
t = _create_tool_from_function(tool)
assert t.parameters["properties"]["x"]["type"] == "string"
@@ -71,6 +75,7 @@ class TestCreateToolFromFunction:
def tool(x: int) -> dict:
"""T."""
return {}
t = _create_tool_from_function(tool)
assert t.parameters["properties"]["x"]["type"] == "integer"
@@ -78,6 +83,7 @@ class TestCreateToolFromFunction:
def tool(x: float) -> dict:
"""T."""
return {}
t = _create_tool_from_function(tool)
assert t.parameters["properties"]["x"]["type"] == "number"
@@ -85,6 +91,7 @@ class TestCreateToolFromFunction:
def tool(x: bool) -> dict:
"""T."""
return {}
t = _create_tool_from_function(tool)
assert t.parameters["properties"]["x"]["type"] == "boolean"
@@ -92,6 +99,7 @@ class TestCreateToolFromFunction:
def tool(x: list) -> dict:
"""T."""
return {}
t = _create_tool_from_function(tool)
assert t.parameters["properties"]["x"]["type"] == "string"
@@ -99,6 +107,7 @@ class TestCreateToolFromFunction:
def tool(x) -> dict:
"""T."""
return {}
t = _create_tool_from_function(tool)
assert t.parameters["properties"]["x"]["type"] == "string"
@@ -107,6 +116,7 @@ class TestCreateToolFromFunction:
def tool(self, x: str) -> dict:
"""T."""
return {}
t = _create_tool_from_function(MyClass().tool)
assert "self" not in t.parameters["properties"]
@@ -114,6 +124,7 @@ class TestCreateToolFromFunction:
def tool(a: str, b: int = 0) -> dict:
"""T."""
return {}
t = _create_tool_from_function(tool)
assert t.parameters["type"] == "object"
assert "properties" in t.parameters
@@ -123,6 +134,7 @@ class TestCreateToolFromFunction:
def tool(x: str) -> dict:
"""T."""
return {"x": x}
t = _create_tool_from_function(tool)
assert t.func("hello") == {"x": "hello"}
@@ -131,8 +143,8 @@ class TestCreateToolFromFunction:
# make_tools
# ---------------------------------------------------------------------------
class TestMakeTools:
class TestMakeTools:
def test_returns_dict(self):
tools = make_tools(settings)
assert isinstance(tools, dict)