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(brain): keep the answer when a promise merely frames it

Harald41cab39428a9
diff --git a/jarvis/brain/action_honesty.py b/jarvis/brain/action_honesty.py
index 3aab8807fc..a33b491c5e 100644
--- a/jarvis/brain/action_honesty.py
+++ b/jarvis/brain/action_honesty.py
@@ -5,6 +5,14 @@ get back to you" without emitting a tool call. Jarvis has no autonomous
continuation after that response, so the sentence is not harmless filler: it is
an ungrounded claim that work is running. This module detects that narrow,
high-confidence shape with regex only and provides a localized honest fallback.
+
+The judgement is made per clause, never over the whole text. An answer that
+opens with "Let me check." and signs off with "I'll get back to you when that
+changes." matches the promise vocabulary at both ends while the delivered
+result sits between them; replacing that text would destroy the answer. A
+clause that carries an independent, unconditional statement is therefore
+treated as substance: the promise clauses around it are dropped and the
+substance is kept. Only a text that is promise wording end to end is replaced.
"""
from __future__ import annotations
@@ -12,6 +20,7 @@ from __future__ import annotations
import re
import unicodedata
from collections.abc import Collection
+from typing import NamedTuple
def _normalize(text: str) -> str:
@@ -54,21 +63,90 @@ _DEFER_MARKER_RE = re.compile(
r")"
)
-_GROUNDED_RESULT_RE = re.compile(
+# Clause boundaries. A period between digits (20.5) and a colon between digits
+# (14:30) are not boundaries, and a comma only separates when whitespace
+# follows it, so decimal commas (20,5) stay inside one clause. The pattern is
+# a capturing group: ``re.split`` keeps every separator, so the clauses
+# reassemble into the original string byte for byte.
+_CLAUSE_SPLIT_RE = re.compile(
+ r"((?:[!?…]|(?<!\d)\.(?!\d))+[\s\"'“”)\]]*"
+ r"|[;\n\r]+\s*"
+ r"|,\s+"
+ r"|(?<!\d):(?!\d)\s*"
+ r"|\s+[—–]+\s+)"
+)
+
+_TOKEN_RE = re.compile(r"[0-9a-z]+")
+
+# Closed-class words plus the politeness and hedging filler that a promise
+# clause is built from. Everything outside this set counts as content, so
+# substance is recognised by structure (an independent clause that carries
+# content words) instead of by a handful of fixed result phrasings.
+_FUNCTION_WORDS: frozenset[str] = frozenset(
+ (
+ "der die das den dem des dessen deren ein eine einen einem " # i18n-allow: matcher
+ "einer eines ich du er sie es wir ihr man mich dich sich uns " # i18n-allow: matcher
+ "euch mir dir ihm ihn ihnen mein meine meinen meinem dein " # i18n-allow: matcher
+ "deine deinen deinem sein ihre unser euer und oder aber denn " # i18n-allow: matcher
+ "doch dann noch nur auch schon mal kurz gerne gern eben " # i18n-allow: matcher
+ "schnell sofort bitte danke ja nein nicht kein keine keinen " # i18n-allow: matcher
+ "nichts etwas alles ist sind bin bist seid war waren sei habe " # i18n-allow: matcher
+ "hast hat haben hatte hatten wird werden werde wurde wurden " # i18n-allow: matcher
+ "kann kannst konnen konnte soll sollte muss mussen darf fur " # i18n-allow: matcher
+ "mit vom von zu zum zur in im am an auf aus bei nach uber " # i18n-allow: matcher
+ "unter vor durch ohne um als wie so dass da hier dort jetzt " # i18n-allow: matcher
+ "gleich bescheid sage sagen sag melde melden moment " # i18n-allow: matcher
+ "the a an this that these those i you he she it we they me "
+ "him her us them my your his its our their and or but so then "
+ "just also only quick quickly right now please thanks ok okay "
+ "yes no not sure is are was were be been being am do does did "
+ "doing have has had will would shall should can could may "
+ "might must to of in on at for with from by about into over "
+ "under after before as than here there when while "
+ "el la los las un una unos unas lo yo tu ella nosotros ellos " # i18n-allow: matcher
+ "me te se nos les le mi mis tus su sus y o pero entonces ya " # i18n-allow: matcher
+ "solo tambien claro por favor gracias si no nada algo todo es " # i18n-allow: matcher
+ "son era eran ser estar estoy esta estan estaba fue fueron " # i18n-allow: matcher
+ "hay he ha hemos han de en a con para sobre desde hasta como " # i18n-allow: matcher
+ "que aqui alli ahora luego" # i18n-allow: matcher
+ ).split()
+)
+
+# A clause introduced by a subordinating conjunction states a condition, not a
+# result ("once the report is ready" / "when it changes"), so it never
+# counts as delivered substance and it never survives on its own once the
+# clause it depends on is dropped.
+_SUBORDINATE_OPENER_RE = re.compile(
+ r"^(?:(?:und|oder|aber|and|or|but|y|pero)\s+)?" # i18n-allow: German/Spanish output matcher
r"(?:"
- r"\b(?:the\s+(?:answer|result)\s+is|i\s+(?:found|checked)\b|it\s+shows\b)|"
- r"\b(?:die\s+antwort\s+ist|das\s+ergebnis\s+ist|" # i18n-allow: German output matcher
- r"ich\s+habe\s+(?:gefunden|nachgesehen|" # i18n-allow: German output matcher
- r"nachgeschaut))\b|" # i18n-allow: German output matcher
- r"\b(?:la\s+respuesta\s+es|el\s+resultado\s+es|" # i18n-allow: Spanish output matcher
- r"he\s+encontrado)\b" # i18n-allow: Spanish output matcher
- r")"
+ r"wenn|sobald|falls|weil|damit|bevor|nachdem|" # i18n-allow: German output matcher
+ r"bis|solange|sofern|obwohl|dass|ob|sowie|" # i18n-allow: German output matcher
+ r"once|if|until|till|because|unless|whether|while|when|"
+ r"as\s+soon\s+as|so\s+that|"
+ r"cuando|apenas|porque|mientras|aunque|que|" # i18n-allow: Spanish output matcher
+ r"en\s+cuanto|para\s+que" # i18n-allow: Spanish output matcher
+ r")\b"
)
+_TRAILING_CONJUNCTION_RE = re.compile(
+ r"\s+(?:und|oder|aber|and|or|but|y|pero)$" # i18n-allow: German/Spanish output matcher
+)
+
+# Two content words are enough for a delivered result ("Es sind 20 Grad"), and
+# few enough that a promise clause never reaches the bar once its own promise
+# wording is discounted.
+_MIN_SUBSTANCE_TOKENS = 2
+
+# Length of the tail a bare commitment may carry before it stops looking like
+# a promise. Kept from the original guard so the acknowledgement path (which
+# shares this predicate) keeps its established suppression boundary.
+_MAX_BARE_COMMITMENT_TAIL = 24
+
_ACTION_NOT_STARTED_PHRASES: dict[str, str] = {
"de": (
- "Ich habe dafür gerade keine Aktion gestartet und deshalb noch kein " # i18n-allow: runtime voice phrase
- "Ergebnis. Bitte sag es noch einmal." # i18n-allow: runtime voice phrase
+ "Ich habe dafür gerade keine Aktion gestartet " # i18n-allow: runtime voice phrase
+ "und deshalb noch kein Ergebnis. " # i18n-allow: runtime voice phrase
+ "Bitte sag es noch einmal." # i18n-allow: runtime voice phrase
), # i18n-allow: German runtime voice/chat output
"en": (
"I did not start an action for that, so I do not have a result yet. Please ask me again."
@@ -80,24 +158,126 @@ _ACTION_NOT_STARTED_PHRASES: dict[str, str] = {
}
-def has_deferred_action_claim(text: str) -> bool:
- """Return whether ``text`` ends the turn on uncompleted future work."""
+class _Clause(NamedTuple):
+ """One clause of the response plus the separator that closed it."""
+
+ body: str
+ separator: str
+ commitment: bool
+ defer: bool
+ substance: bool
+
+
+class _Analysis(NamedTuple):
+ """What the promise vocabulary means for this particular text.
+
+ ``kind`` is one of:
+
+ * ``"none"`` — no commitment at all; the text is not this guard's business.
+ * ``"answered"`` — a commitment plus at least one clause of real substance.
+ ``kept`` holds the text with the promise clauses removed.
+ * ``"bare"`` — promise wording end to end, nothing delivered.
+ * ``"open"`` — a commitment whose tail is too long to read as a bare
+ promise and that carries no defer marker; left untouched, as before.
+ """
+
+ kind: str
+ kept: str
+
+
+def _content_tokens(normalized: str) -> list[str]:
+ return [token for token in _TOKEN_RE.findall(normalized) if token not in _FUNCTION_WORDS]
+
+
+def _split_clauses(text: str) -> list[_Clause]:
+ """Split ``text`` into classified clauses that reassemble losslessly."""
+ parts = _CLAUSE_SPLIT_RE.split(str(text or ""))
+ pairs: list[list[str]] = []
+ for index in range(0, len(parts), 2):
+ body = parts[index]
+ separator = parts[index + 1] if index + 1 < len(parts) else ""
+ if not body.strip() and pairs:
+ # An empty body means two separators met (". — "); keep the run
+ # attached to the clause before it rather than inventing a clause.
+ pairs[-1][1] += body + separator
+ continue
+ pairs.append([body, separator])
+
+ clauses: list[_Clause] = []
+ for body, separator in pairs:
+ normalized = _normalize(body).strip()
+ commitment = bool(_ACTION_COMMITMENT_RE.search(normalized))
+ defer = bool(_DEFER_MARKER_RE.search(normalized))
+ substance = (
+ not commitment
+ and not defer
+ and _SUBORDINATE_OPENER_RE.match(normalized) is None
+ and len(_content_tokens(normalized)) >= _MIN_SUBSTANCE_TOKENS
+ )
+ clauses.append(_Clause(body, separator, commitment, defer, substance))
+ return clauses
+
+
+def _tidy(text: str) -> str:
+ """Repair the seams left behind when promise clauses are cut out."""
+ cleaned = text.strip().lstrip(",;:—–- ").strip()
+ cleaned = cleaned.rstrip().rstrip(",;:—–-").rstrip()
+ cleaned = _TRAILING_CONJUNCTION_RE.sub("", cleaned).rstrip()
+ if not cleaned:
+ return ""
+ if cleaned[-1] not in ".!?…":
+ cleaned += "."
+ if cleaned[0].islower():
+ cleaned = cleaned[0].upper() + cleaned[1:]
+ return cleaned
+
+
+def _keep_substance(clauses: list[_Clause]) -> str:
+ """Drop the promise clauses and everything that only depends on them."""
+ kept: list[str] = []
+ previous_kept = False
+ for clause in clauses:
+ if clause.commitment or clause.defer:
+ previous_kept = False
+ continue
+ if not clause.substance and not previous_kept:
+ # A dependent tail ("when that changes") whose clause is gone
+ # would be left dangling, so it goes with it.
+ continue
+ kept.append(clause.body + clause.separator)
+ previous_kept = True
+ return _tidy("".join(kept))
+
+
+def _analyse(text: str) -> _Analysis:
normalized = _normalize(text).strip()
if not normalized:
- return False
- match = _ACTION_COMMITMENT_RE.search(normalized)
- if match is None:
- return False
-
- remainder = normalized[match.end() :].strip()
- if _GROUNDED_RESULT_RE.search(remainder):
- return False
+ return _Analysis("none", "")
+
+ commitment = _ACTION_COMMITMENT_RE.search(normalized)
+ if commitment is None:
+ return _Analysis("none", "")
+
+ clauses = _split_clauses(text)
+ if any(clause.substance for clause in clauses):
+ kept = _keep_substance(clauses)
+ if kept:
+ return _Analysis("answered", kept)
+
if _DEFER_MARKER_RE.search(normalized):
- return True
+ return _Analysis("bare", "")
# A bare commitment with no delivered result is still terminal: after the
# model response closes there is no hidden continuation that will do it.
- return len(remainder.strip(" .,!?:;-")) <= 24
+ tail = normalized[commitment.end() :].strip(" .,!?:;-")
+ if len(tail) <= _MAX_BARE_COMMITMENT_TAIL:
+ return _Analysis("bare", "")
+ return _Analysis("open", "")
+
+
+def has_deferred_action_claim(text: str) -> bool:
+ """Return whether ``text`` ends the turn on uncompleted future work."""
+ return _analyse(text).kind == "bare"
def action_not_started_phrase(language: str) -> str:
@@ -114,10 +294,15 @@ def replace_unbacked_action_claim(
executed_tools: Collection[str],
language: str,
) -> str:
- """Replace a deferred claim unless this turn has execution evidence."""
- if executed_tools or not has_deferred_action_claim(text):
+ """Drop an unbacked promise without ever dropping a delivered answer."""
+ if executed_tools:
return text
- return action_not_started_phrase(language)
+ analysis = _analyse(text)
+ if analysis.kind == "bare":
+ return action_not_started_phrase(language)
+ if analysis.kind == "answered":
+ return analysis.kept
+ return text
__all__ = [
diff --git a/tests/unit/brain/test_action_honesty.py b/tests/unit/brain/test_action_honesty.py
index 94ebc77669..728979a88d 100644
--- a/tests/unit/brain/test_action_honesty.py
+++ b/tests/unit/brain/test_action_honesty.py
@@ -49,6 +49,109 @@ def test_grounded_or_explanatory_text_is_not_a_deferred_claim(text: str) -> None
assert has_deferred_action_claim(text) is False
+def test_an_answer_between_two_promise_clauses_survives() -> None:
+ """The reported loss: a full answer framed by promise wording.
+
+ The opener matches the commitment vocabulary and the sign-off matches the
+ defer vocabulary, so a whole-text match discarded the weather report in
+ between and spoke the canned fallback instead.
+ """
+ original = (
+ "Ich schaue kurz. Draussen sind 20 Grad und es " # i18n-allow: German fixture
+ "regnet nicht. Sage ich dir, wenn sich das ändert." # i18n-allow: German fixture
+ )
+
+ honest = replace_unbacked_action_claim(original, executed_tools=(), language="de")
+
+ assert honest == (
+ "Draussen sind 20 Grad und es regnet nicht." # i18n-allow: German runtime fixture
+ )
+ assert has_deferred_action_claim(original) is False
+
+
+ ("original", "language", "expected"),
+ [
+ (
+ "Let me check that for you. The build finished at 14:30 with 0 "
+ "errors. I'll report back if anything changes.",
+ "en",
+ "The build finished at 14:30 with 0 errors.",
+ ),
+ (
+ "Voy a revisar eso. Hace 20 grados y no llueve. " # i18n-allow: Spanish runtime fixture
+ "Te digo si cambia.", # i18n-allow: Spanish runtime fixture
+ "es",
+ "Hace 20 grados y no llueve.", # i18n-allow: Spanish runtime fixture
+ ),
+ (
+ "Ich schaue kurz nach, draussen sind 20,5 Grad.", # i18n-allow: German runtime fixture
+ "de",
+ "Draussen sind 20,5 Grad.", # i18n-allow: German runtime fixture
+ ),
+ (
+ "Draussen sind 20 Grad und es regnet nicht. " # i18n-allow: German runtime fixture
+ "Ich schaue nochmal nach und melde mich.", # i18n-allow: German runtime fixture
+ "de",
+ "Draussen sind 20 Grad und es regnet nicht.", # i18n-allow: German runtime fixture
+ ),
+ ],
+)
+def test_only_the_promise_clause_is_dropped(original: str, language: str, expected: str) -> None:
+ assert (
+ replace_unbacked_action_claim(
+ original,
+ executed_tools=(),
+ language=language,
+ )
+ == expected
+ )
+
+
+ "text",
+ [
+ "Ich schaue kurz nach und sage dir Bescheid.", # i18n-allow: German runtime fixture
+ "Ich schaue kurz nach dem Wetter.", # i18n-allow: German runtime fixture
+ "Let me check and get back to you.",
+ ],
+)
+def test_a_bare_promise_has_nothing_worth_keeping(text: str) -> None:
+ assert has_deferred_action_claim(text) is True
+ assert replace_unbacked_action_claim(
+ text,
+ executed_tools=(),
+ language="de",
+ ) == action_not_started_phrase("de")
+
+
+def test_substance_needs_no_fixed_result_phrasing() -> None:
+ """Substance is structural, not a whitelist of five result openings."""
+ original = (
+ "Ich schaue kurz. Der Serverraum liegt im zweiten " # i18n-allow: German runtime fixture
+ "Stock. Melde ich dir, falls sich das ändert." # i18n-allow: German runtime fixture
+ )
+
+ assert replace_unbacked_action_claim(
+ original,
+ executed_tools=(),
+ language="de",
+ ) == (
+ "Der Serverraum liegt im zweiten Stock." # i18n-allow: German runtime fixture
+ )
+
+
+def test_a_conditional_tail_is_not_a_delivered_result() -> None:
+ """A clause like "as soon as the export is ready" is a condition, not an outcome."""
+ original = "One moment, I'll check that as soon as the export is ready."
+
+ assert replace_unbacked_action_claim(
+ original,
+ executed_tools=(),
+ language="en",
+ ) == action_not_started_phrase("en")
+
+
def test_unbacked_claim_is_replaced_with_honest_localized_result() -> None:
original = "Give me a moment; I'll open that and report back."