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
feat(wiki): evidence-tier classifier in grounding (behavioral basis)
Personal Jarvis Maintaineree3b8ad5ee5e
diff --git a/jarvis/memory/wiki/grounding.py b/jarvis/memory/wiki/grounding.pyindex c5e0a02647..f709209982 100644--- a/jarvis/memory/wiki/grounding.py+++ b/jarvis/memory/wiki/grounding.py@@ -4,6 +4,14 @@ These checks are deliberately narrow. They do not try to prove arbitrarynatural-language entailment; they only block a known high-cost failure mode:turning a topic question into a personal interest or preference. The LLMstill handles general semantic judgement in Stage 2.++Besides the block/pass verdict, :func:`classify_user_attitude_evidence`+grades HOW an attitude or habit claim about the user is grounded: an+``explicit`` first-person assertion ("I love golf"), or a ``behavioral``+first-person lived-experience report ("I was out on the golf course again+on Saturday with my buddies") that supports the claim without literally+naming a preference. Topic questions and bare topic mentions ground+neither and stay blocked."""from __future__ import annotations@@ -44,7 +52,8 @@ _GENERIC_USER_REF_RE = re.compile(re.IGNORECASE,)_SUBJECTLESS_INTEREST_RE = re.compile(- r"^(?:interest(?:ed)?|curious|preference|likes?|loves?|enjoys?|prefers?)\b",+ r"^(?:interest(?:ed)?|curious|preference|likes?|loves?|enjoys?|prefers?|"+ r"plays?|trains?|practi[cs]es?)\b",re.IGNORECASE,)@@ -103,6 +112,49 @@ _NEGATIVE_CANDIDATE_RE = re.compile(re.IGNORECASE,)+# Habit/activity claims about the user ("plays golf regularly", "trains every+# week") are attitude-adjacent: they assert a durable relationship to a topic+# and therefore need the same evidence grounding as interest claims.+_CANDIDATE_HABIT_RE = re.compile(+ r"\b(?:"+ r"plays?|practi[cs]es?|trains?|"+ r"regularly|routinely|habitually|frequently|actively|"+ r"spielt|trainiert|regelmaessig|regelmassig|" # i18n-allow: input vocabulary+ r"juega|entrena|practica|regularmente"+ r")\b",+ re.IGNORECASE,+)++# First-person lived-experience signal in a declarative evidence clause:+# the user reports DOING, habitually doing, or enjoying being at/around+# something. Matched against folded (casefolded, accent-stripped) text.+_FIRST_PERSON_EXPERIENCE_RE = re.compile(+ r"(?:"+ # en: "I play/go/train...", "we meet...", "I was/am out/at/on...",+ # "I always/usually...", "every Saturday ... I ..."+ r"\bi\s+(?:play|go|ride|drive|run|train|practi[cs]e|swim|hike|climb|"+ r"cook|bake|paint|garden|collect|volunteer|spend|meet|attend|visit)\b|"+ r"\bwe\s+(?:play|go|ride|train|meet)\b|"+ r"\bi\s+(?:was|am|'m)\s+(?:out|at|on)\b|"+ r"\bi\s+(?:always|usually|often|normally|typically)\b|"+ r"\bevery\s+(?:day|morning|evening|night|week|weekend|month|"+ r"monday|tuesday|wednesday|thursday|friday|saturday|sunday)\b|"+ # de folded: "ich spiele/gehe/fahre...", "wir spielen...", "ich war/bin",+ # "ich ... gern(e)", "jeden Samstag", "ich ... immer/oft"+ r"\bich\s+(?:spiele|gehe|fahre|laufe|trainiere|treffe|besuche|" # i18n-allow: input vocabulary+ r"verbringe|koche|sammle|male|wandere|schwimme|klettere|war|bin)\b|" # i18n-allow: input vocabulary+ r"\bwir\s+(?:spielen|gehen|fahren|treffen|trainieren)\b|" # i18n-allow: input vocabulary+ r"\bich\s+[^.!?;,\n]{0,60}\bgerne?\b|" # i18n-allow: input vocabulary+ r"\bich\s+[^.!?;,\n]{0,60}\b(?:immer|meistens|oft|staendig)\b|" # i18n-allow: input vocabulary+ r"\bjede[nrs]?\s+\w+|" # i18n-allow: input vocabulary+ # es folded: "juego/voy/entreno...", "cada sabado", "siempre/suelo"+ r"\b(?:yo\s+)?(?:juego|voy|entreno|corro|nado|cocino|paso|quedo|"+ r"asisto|visito|estuve|estaba)\b|"+ r"\bcada\s+\w+|\bsiempre\b|\bsuelo\b"+ r")",+ re.IGNORECASE,+)+def _fold(text: object) -> str:"""Case-fold and remove accents without discarding non-Latin text."""@@ -137,23 +189,41 @@ def _asserted_interest_polarities(focus_text: str) -> set[bool]:return polarities-def is_unsupported_user_interest_claim(+def _behavioral_experience_grounded(focus_text: str) -> bool:+ """True when a declarative focus clause reports first-person experience."""+ folded = _fold(focus_text)+ for match in _CLAUSE_RE.finditer(folded):+ clause = match.group(1).strip(" \t¿¡")+ terminal = match.group(2)+ if not clause or terminal == "?" or _QUESTION_PREFIX_RE.match(clause):+ continue+ if _FIRST_PERSON_EXPERIENCE_RE.search(clause):+ return True+ return False+++def classify_user_attitude_evidence(*,fact: str,subjects: Sequence[str],evidence_excerpt: str,user_slug: str,-) -> bool:- """Return whether a user-interest claim lacks an explicit user assertion.+) -> str | None:+ """Grade how an attitude/habit claim about the user is grounded.- Topic choice is not evidence of personal interest. The guard activates- only for an interest/preference attitude about the current user; ownership,- plans, events, and other fact families are deliberately untouched.+ Returns ``"explicit"`` (literal first-person assertion, or the guard is+ not applicable to this fact family), ``"behavioral"`` (a declarative+ first-person lived-experience report supports a positive claim), or+ ``None`` (blocked: the evidence grounds neither — topic choice alone is+ not evidence of personal interest). Ownership, plans, events, and other+ fact families return ``"explicit"`` untouched."""folded_fact = _fold(fact)candidate_probe = _INTEREST_RATE_RE.sub("", folded_fact)- if not _CANDIDATE_INTEREST_RE.search(candidate_probe):- return False+ is_attitude = bool(_CANDIDATE_INTEREST_RE.search(candidate_probe))+ is_habit = bool(_CANDIDATE_HABIT_RE.search(folded_fact))+ if not is_attitude and not is_habit:+ return "explicit"folded_slug = _fold(user_slug).strip()folded_subjects = {_fold(subject).strip() for subject in subjects}@@ -173,14 +243,43 @@ def is_unsupported_user_interest_claim(and bool(_SUBJECTLESS_INTEREST_RE.match(folded_fact)))if not user_referenced:- return False+ return "explicit"expected_polarity = not bool(_NEGATIVE_CANDIDATE_RE.search(folded_fact))- asserted = _asserted_interest_polarities(focus_user_evidence(evidence_excerpt))- return expected_polarity not in asserted+ focus = focus_user_evidence(evidence_excerpt)+ if expected_polarity in _asserted_interest_polarities(focus):+ return "explicit"+ if expected_polarity and _behavioral_experience_grounded(focus):+ return "behavioral"+ return None+++def is_unsupported_user_interest_claim(+ *,+ fact: str,+ subjects: Sequence[str],+ evidence_excerpt: str,+ user_slug: str,+) -> bool:+ """Return whether a user attitude/habit claim lacks ANY grounding.++ Thin wrapper over :func:`classify_user_attitude_evidence`: blocked means+ the evidence contains neither an explicit assertion nor a first-person+ lived-experience report supporting the claim.+ """+ return (+ classify_user_attitude_evidence(+ fact=fact,+ subjects=subjects,+ evidence_excerpt=evidence_excerpt,+ user_slug=user_slug,+ )+ is None+ )__all__ = [+ "classify_user_attitude_evidence","focus_user_evidence","is_unsupported_user_interest_claim",]diff --git a/tests/unit/memory/wiki/test_grounding.py b/tests/unit/memory/wiki/test_grounding.pynew file mode 100644index 0000000000..29c2130c34--- /dev/null+++ b/tests/unit/memory/wiki/test_grounding.py@@ -0,0 +1,123 @@+"""Guard tests for the deterministic evidence-tier classifier.++The classifier is the deterministic floor under the Stage-1 prompt rules:+it decides whether an attitude/habit claim about the user is grounded+``explicit`` (literal assertion), ``behavioral`` (first-person+lived-experience report), or not at all (``None`` — blocked). Topic+questions must NEVER ground a personal claim, in any supported language.+"""+from __future__ import annotations++import pytest++from jarvis.memory.wiki.grounding import (+ classify_user_attitude_evidence,+ is_unsupported_user_interest_claim,+)++_USER = "ruben"+++def _classify(fact: str, evidence: str, subjects: tuple[str, ...] = (_USER, "golf")):+ return classify_user_attitude_evidence(+ fact=fact,+ subjects=subjects,+ evidence_excerpt=f"Evidence user turn [turn-1]: {evidence}",+ user_slug=_USER,+ )+++def test_explicit_interest_assertion_classifies_explicit() -> None:+ assert _classify(+ "The user loves golf.",+ "I love being out on golf courses with my buddies, "+ "playing this sport actively.",+ ) == "explicit"+++def test_habitual_activity_without_interest_verb_classifies_behavioral() -> None:+ assert _classify(+ "The user plays golf regularly with friends.",+ "I was out on the golf course again on Saturday with my buddies.",+ ) == "behavioral"+++def test_enjoyment_claim_from_lived_experience_classifies_behavioral() -> None:+ # The fact claims enjoyment; the evidence reports doing, not liking.+ assert _classify(+ "The user enjoys golf.",+ "Every Saturday I meet my buddies out on the golf course.",+ ) == "behavioral"+++def test_topic_question_stays_blocked() -> None:+ assert _classify(+ "The user is interested in Monaco.",+ "Tell me about Monaco.",+ subjects=(_USER, "monaco"),+ ) is None+ assert is_unsupported_user_interest_claim(+ fact="The user is interested in Monaco.",+ subjects=(_USER, "monaco"),+ evidence_excerpt="Evidence user turn [turn-1]: Tell me about Monaco.",+ user_slug=_USER,+ )+++def test_question_clause_never_grounds_behavioral() -> None:+ assert _classify(+ "The user plays golf regularly.",+ "Do I play golf on Saturdays?",+ ) is None+++def test_third_party_activity_is_not_a_user_claim() -> None:+ # A fact about another person never activates the user-attitude guard.+ assert _classify(+ "Lena plays golf regularly.",+ "My friend Lena plays golf every weekend.",+ subjects=("lena", "golf"),+ ) == "explicit"+++def test_negative_assertion_polarity_unchanged() -> None:+ assert _classify(+ "The user dislikes golf.",+ "I hate golf.",+ ) == "explicit"+ # A positive-experience report cannot ground a negative attitude claim.+ assert _classify(+ "The user dislikes golf.",+ "I was out on the golf course again on Saturday.",+ ) is None+++def test_non_attitude_fact_families_stay_untouched() -> None:+ assert _classify(+ "The user owns a yacht named Aurora.",+ "I own a yacht named Aurora.",+ subjects=(_USER, "aurora"),+ ) == "explicit"+++ "evidence",+ [+ "Ich spiele jeden Samstag Golf mit meinen Freunden.", # i18n-allow: input vocabulary under test+ "Ich bin sehr gerne draussen auf Golfplaetzen unterwegs.", # i18n-allow: input vocabulary under test+ "Juego al golf cada sabado con mis amigos.",+ ],+)+def test_multilingual_behavioral_reports_classify_behavioral(evidence: str) -> None:+ assert _classify(+ "The user plays golf regularly with friends.",+ evidence,+ ) == "behavioral"+++def test_multilingual_topic_question_stays_blocked() -> None:+ assert _classify(+ "The user is interested in Monaco.",+ "Erzaehl mir was ueber Monaco?", # i18n-allow: input vocabulary under test+ subjects=(_USER, "monaco"),+ ) is None