Skip to content

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.

fix(skills): prefer the user's morning routine over the builtin

Haraldde260369ab0e
diff --git a/jarvis/skills/trigger_matcher.py b/jarvis/skills/trigger_matcher.py
index 8716ec1784..9b9abf4376 100644
--- a/jarvis/skills/trigger_matcher.py
+++ b/jarvis/skills/trigger_matcher.py
@@ -11,6 +11,7 @@ import time
from collections.abc import AsyncIterator
from datetime import datetime
+from .builtin import BUILTIN_SKILL_NAMES
from .registry import SkillRegistry
from .schema import Skill, SkillLifecycleState
@@ -68,6 +69,16 @@ _FILLER_MATCH_PENALTY = 100_000
_PUNCT_RE = re.compile(r"[^\w\s]", re.UNICODE)
+def _normalize_punct(utterance: str) -> str:
+ """Flatten punctuation (hyphens, commas, …) to spaces. No filler stripping.
+
+ Speech-to-text routinely emits ``Morning-Routine`` for a pattern written as
+ ``morning routine``. That is spelling, not politeness, so it must not pay
+ the filler penalty.
+ """
+ return " ".join(_PUNCT_RE.sub(" ", utterance).split())
+
+
def _strip_fillers(utterance: str) -> str:
"""Return ``utterance`` with leading/trailing politeness fillers removed.
@@ -76,8 +87,7 @@ def _strip_fillers(utterance: str) -> str:
core must still satisfy the anchored pattern by itself, which is exactly
the "phrase must carry the sentence" contract.
"""
- cleaned = _PUNCT_RE.sub(" ", utterance)
- tokens = cleaned.split()
+ tokens = _normalize_punct(utterance).split()
if not tokens:
return ""
start, end = 0, len(tokens)
@@ -88,6 +98,10 @@ def _strip_fillers(utterance: str) -> str:
return " ".join(tokens[start:end])
+def _is_builtin_name(name: str) -> bool:
+ return name in BUILTIN_SKILL_NAMES
+
+
class TriggerMatcher:
"""Zentrale Match-Instanz — hält keinen State außer Cache der kompilierten Regexes."""
@@ -143,11 +157,12 @@ class TriggerMatcher:
"""
if not utterance:
return None
- # Step 2: politeness-tolerant fallback for ``^...$``-anchored patterns.
- # The raw utterance is tried first (preserves all existing behaviour,
- # incl. un-anchored "contains" patterns); only on a miss do we retry
- # against the filler-stripped core. A stripped hit carries a score
- # penalty so a direct hit on any skill always outranks it.
+ # Three attempts, cheapest first:
+ # 1. raw utterance (preserves existing un-anchored "contains" hits)
+ # 2. punctuation flattened, no penalty — "Morning-Routine" == "morning routine"
+ # 3. politeness fillers stripped, with a score penalty so a direct hit
+ # on any skill always outranks a tolerant fallback hit on another
+ punct = _normalize_punct(utterance)
stripped = _strip_fillers(utterance)
best: tuple[int, Skill, re.Match[str]] | None = None
for sk in self.registry.by_trigger("voice"):
@@ -165,7 +180,9 @@ class TriggerMatcher:
continue
penalty = 0
m = pat.search(utterance)
- if m is None and stripped and stripped != utterance:
+ if m is None and punct and punct != utterance:
+ m = pat.search(punct)
+ if m is None and stripped and stripped != utterance and stripped != punct:
m = pat.search(stripped)
penalty = _FILLER_MATCH_PENALTY
if m is None:
@@ -173,6 +190,17 @@ class TriggerMatcher:
score = len(m.group(0)) - penalty
if best is None or score > best[0]:
best = (score, sk, m)
+ continue
+ if (
+ score == best[0]
+ and _is_builtin_name(best[1].name)
+ and not _is_builtin_name(sk.name)
+ ):
+ # Equal span: the skill the user wrote beats a bundled one
+ # with the same phrase. Live 2026-08-20: "Morning Routine"
+ # always fired the builtin briefing, never the voice-authored
+ # replacement that actually plays music.
+ best = (score, sk, m)
return (best[1], best[2]) if best else None
# ------------------------------------------------------------------
diff --git a/tests/unit/skills/test_trigger_matcher.py b/tests/unit/skills/test_trigger_matcher.py
index 89f8a9ca6a..8e6c04b045 100644
--- a/tests/unit/skills/test_trigger_matcher.py
+++ b/tests/unit/skills/test_trigger_matcher.py
@@ -260,3 +260,68 @@ def test_anchored_no_false_positive_on_casual_mention(
def test_anchored_no_false_positive_on_unrelated(anchored_registry: SkillRegistry):
m = TriggerMatcher(anchored_registry)
assert m.match_voice("erzähl mir was über den morgen", lang="de") is None
+
+
+def test_hyphenated_utterance_matches_spaced_pattern(tmp_path: Path) -> None:
+ """ASR often emits Morning-Routine for a pattern written as morning routine."""
+ _write_skill(
+ tmp_path,
+ "user-morning",
+ """---
+schema_version: "1"
+name: user-morning
+triggers:
+ - type: voice
+ pattern: "(morning routine|morgenroutine)"
+ language: ["de", "en"]
+---
+body
+""",
+ )
+ reg = SkillRegistry(tmp_path)
+ reg.reload_sync()
+ m = TriggerMatcher(reg)
+ sk = m.match_voice("Morning-Routine", lang="en")
+ assert sk is not None
+ assert sk.name == "user-morning"
+
+
+def test_user_skill_wins_tie_against_builtin_name(tmp_path: Path) -> None:
+ """A voice-authored replacement must beat the bundled skill on the same phrase."""
+ _write_skill(
+ tmp_path,
+ "morning-routine",
+ """---
+schema_version: "1"
+name: morning-routine
+triggers:
+ - type: voice
+ pattern: "(morning routine|morgenroutine)"
+ language: ["de", "en"]
+---
+body
+""",
+ )
+ _write_skill(
+ tmp_path,
+ "morning-routine-2",
+ """---
+schema_version: "1"
+name: Morning Routine 2
+triggers:
+ - type: voice
+ pattern: "(morning routine|morgenroutine|starte morning routine)"
+ language: ["de", "en"]
+---
+body
+""",
+ )
+ reg = SkillRegistry(tmp_path)
+ reg.reload_sync()
+ m = TriggerMatcher(reg)
+ sk = m.match_voice("Morning Routine", lang="en")
+ assert sk is not None
+ assert sk.name == "Morning Routine 2"
+ sk2 = m.match_voice("Morgenroutine", lang="de")
+ assert sk2 is not None
+ assert sk2.name == "Morning Routine 2"