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): narrow the tool surface instead of emptying it

Harald112068b96ddb
diff --git a/jarvis/brain/manager.py b/jarvis/brain/manager.py
index 2529a93c42..8db3957293 100644
--- a/jarvis/brain/manager.py
+++ b/jarvis/brain/manager.py
@@ -857,20 +857,31 @@ _AGENTIC_IDE_WORKSPACE_TOOL_NAMES: frozenset[str] = frozenset({
"agentic-ide-continue-interrupted",
})
-# Consequential action tools a turn with NO action signal of its own must never
-# INHERIT from the conversation context. GENERAL rule (not one phrase): a
-# question, a remark, or a mis-transcription asks for no desktop action, so it
-# must not be able to re-run the PREVIOUS turn's computer_use/spawn pulled from
-# context. Forensic 2026-06-27: the German smalltalk "Was geht ab?" was
-# mis-transcribed as "Lask it up!" [en] conf 0.509, missed every smalltalk /
+# Consequential action tools a signalless turn must never INHERIT from the
+# conversation context. Forensic 2026-06-27: the German smalltalk "Was geht ab?"
+# was mis-transcribed as "Lask it up!" [en] conf 0.509, missed every smalltalk /
# whisper-junk list, and the router-LLM (reading a 30k-token context full of the
# prior "open Discord, bridge-mine channel" command) re-ran that exact CU plan on
# a turn that asked for nothing. ``computer_use`` + the spawn vehicles are the
# heavy, irreversible-looking actions hidden here. Deliberately NOT hidden: the
# read-only ``screenshot`` tool (so "Was siehst du auf dem Bildschirm?" still
# works) and ``open_app`` (lighter; naming an app already reads as action-intent).
+# INHERITANCE NEEDS SOMETHING TO INHERIT (2026-08-17): the hide applies only
+# while a desktop episode is live or just ended — see
+# ``_hide_action_tools_on_signalless_turn``. Outside one there is no prior plan
+# in the context, and hiding the vehicle then only costs the turn its ability
+# to act.
_INHERITABLE_ACTION_TOOL_NAMES: frozenset[str] = _SPAWN_TOOL_NAMES | {"computer_use"}
+# The only tools a SMALLTALK turn may not see. The 2026-05-01 incident was ONE
+# tool class, not the whole surface: the LLM hallucinated a ``spawn_worker`` on
+# chit-chat and then reported test work it had never started. Nothing else in the
+# surface caused that. The historical full-hide additionally removed every action
+# vehicle from a turn the substring allowlist merely READ as chit-chat, which is
+# its own bug — the model then has nothing to act with, whatever the user asked
+# for. See ``_smalltalk_tool_override``.
+_SMALLTALK_HIDDEN_TOOL_NAMES: frozenset[str] = _SPAWN_TOOL_NAMES
+
# Deterministic write/record tools that create user-visible state (a contact, a
# profile field, a wiki note, a calendar event, a phone call). On a turn with NO
# action signal of its own these must NOT sit in the LLM surface, or the model
@@ -891,6 +902,20 @@ _DETERMINISTIC_WRITE_TOOL_NAMES: frozenset[str] = frozenset({
"call-contact",
})
+# Tools withheld on a turn that carries a CAPTURED SCREEN image. Screen pixels
+# and UI text are untrusted evidence (docs/screen-context.md §4.2), so injected
+# on-screen text must not be able to start something expensive and unattended:
+# a background worker, or a silent record write (a contact, a calendar entry, a
+# wiki note, an outbound call). Everything else stays — including
+# ``computer_use``, whose "looking is not operating" boundary (maintainer mandate
+# 2026-08-02) is enforced per call by ``cu_gate.llm_computer_use_allowed`` in
+# ``tool_use_loop``/``realtime.tools``. That gate reads the USER's utterance, so
+# a look request is refused there even inside a live desktop episode, and text
+# rendered on screen can never unlock it. See ``_image_turn_tool_override``.
+_SCREEN_TURN_HIDDEN_TOOL_NAMES: frozenset[str] = (
+ _SPAWN_TOOL_NAMES | _DETERMINISTIC_WRITE_TOOL_NAMES
+)
+
# The user literally names a skill ("nutz den Skill cloud-debug", "run the
# skill …"). An explicit skill request is its own vehicle and always keeps
# ``run-skill`` visible — the pc-control run-skill hide below must never veto
@@ -4754,8 +4779,8 @@ class BrainManager:
and hallucinated a Jarvis-Agent spawn. Result: main Jarvis claimed to have
started tests that it never started.
- Used in ``generate()`` to hide tools on clear smalltalk turns — the
- tool-use loop receives ``tools={}``, so the LLM can no longer spawn.
+ Used in ``generate()`` to hide the spawn vehicles on clear smalltalk
+ turns (``_smalltalk_tool_override``), so the LLM can no longer spawn.
Greeting-prefix guard (live bug 2026-06-07, data/jarvis_desktop.log
18:19:07): the user said "Hallo, öffne ihn für mich". The allowlist i18n-allow
@@ -4803,16 +4828,15 @@ class BrainManager:
return False
return True
- # Read-only tools that stay visible even on a smalltalk turn. The toolless
- # smalltalk path (2026-05-01) exists to stop the LLM hallucinating a
- # spawn_worker on chit-chat — that risk is the spawn/action tools, NOT the
- # read-only screenshot tool. Keeping `screenshot` here lets the brain look
- # at the screen on demand (Wave 2) even on a greeting-prefixed turn, e.g.
- # "Hallo, lies mir vor was oben links steht" (live failure 2026-05-31).
- # NOTE: `_gate_screen_tool` runs AFTER this override and removes `screenshot`
- # again unless the utterance carries a visual-reference marker (2026-06-14
- # screen-narration guard) — the 2026-05-31 case survives because "lies" /
- # "oben links" / "steht" are markers, so it still reaches the tool.
+ # Back-compat alias for the read-only tool the smalltalk path used to keep
+ # by allowlist. The override is a HIDE-list now
+ # (``_SMALLTALK_HIDDEN_TOOL_NAMES``), so screenshot survives like every
+ # other non-spawn tool; the name is kept because external introspection
+ # (telemetry, eval harness) reads it. NOTE: `_gate_screen_tool` still runs
+ # AFTER the override and removes `screenshot` unless the utterance carries a
+ # visual-reference marker (2026-06-14 screen-narration guard) — the
+ # 2026-05-31 "Hallo, lies mir vor was oben links steht" case survives
+ # because "lies" / "oben links" / "steht" are markers.
_SMALLTALK_SAFE_TOOLS: frozenset[str] = frozenset({"screenshot"})
# Skill-aware routing guard (AD-S3, 2026-06-09 rebuild): the Skill matched
@@ -5662,48 +5686,72 @@ class BrainManager:
return str(result.output or "")
def _smalltalk_tool_override(self) -> dict[str, Tool]:
- """Tool set visible on a smalltalk turn: only the read-only safe tools.
-
- Returns ``{}`` when none of the safe tools are registered — identical to
- the previous full-hide behaviour for deployments without a screenshot
- tool, so the anti-fake-spawn guard is unchanged there. On a
- skill-matched turn (AD-S3) ``run-skill`` stays visible so a greeting-
- style trigger ("guten Morgen" → morning-routine) can still invoke the
- skill.
+ """Tool set visible on a smalltalk turn: everything but the spawn vehicles.
+
+ The 2026-05-01 incident this gate exists for was ONE tool class. The
+ user said "es geht ab", the allowlist did not match, the LLM had the
+ full surface and hallucinated a Jarvis-Agent spawn — Jarvis then claimed
+ to have started tests it never started. Hiding ``spawn_worker`` /
+ ``multi_spawn`` removes exactly that, and an unwanted background agent
+ is the one tool whose wrong call is expensive and surprising.
+
+ Hiding EVERYTHING else was the bug on the other side (2026-08-17
+ review): smalltalk here is a substring allowlist, so a real request
+ that merely reads as chit-chat arrived at the model with no action tool
+ at all and could only be talked about. A tool the model declines to call
+ is free; a tool it cannot see is the failure users report. The genuinely
+ conversational turns still lose ``computer_use`` and the write/record
+ tools further down the chain — see
+ ``_hide_action_tools_on_signalless_turn``.
+
+ A tool the deterministic layer mandated this turn is never hidden
+ ("was steht heute an" can classify as smalltalk — AD-CLI8), and on a
+ skill-matched turn (AD-S3) ``run-skill`` stays visible so a
+ greeting-style trigger ("guten Morgen" → morning-routine) still fires.
"""
- allowed = self._SMALLTALK_SAFE_TOOLS
+ hidden = _SMALLTALK_HIDDEN_TOOL_NAMES
+ keep = {self._evidence_required_tool} if self._evidence_required_tool else set()
if self._skill_turn_match is not None:
- allowed = allowed | {"run-skill"}
- if self._evidence_required_tool:
- # "was steht heute an" can classify as smalltalk; the mandated
- # evidence tool must stay visible or the directive is
- # unfulfillable (AD-CLI8).
- allowed = allowed | {self._evidence_required_tool}
+ keep.add("run-skill")
return {
n: t for n, t in self._tools.items()
- if n in allowed
+ if n not in hidden or n in keep
}
def _image_turn_tool_override(self) -> dict[str, Tool]:
- """Tool surface for a turn that carries an attached image.
+ """Tool surface for a turn that carries a CAPTURED SCREEN image.
- Historically hard ``{}`` — an image turn answers from the pixels, so
- the tool loop was withheld entirely. But a WRITE mandate must survive
- it (code-review finding 2026-08-08): "erstell einen Ordner hier auf
+ Historically hard ``{}`` — the reasoning being that pixels answer the
+ turn and that emptying the surface is what keeps Screen Context and
+ Computer-Use from both running for one utterance (docs/screen-context.md
+ §3.1a, maintainer mandate 2026-08-02). The first exception was a WRITE
+ mandate (code-review finding 2026-08-08): "erstell einen Ordner hier auf
dem Desktop" matches the screen-intent phrase "hier auf dem", the
- explicit screen-context path attaches a screenshot, and zeroing the
- surface would blind the very run_shell call the local-outcome mandate
- requires — the honest "never ran" fallback would fire instead of the
- action. Mirrors the mandated-tool exemption in the smalltalk override
- above: ONLY the mandated write tool stays visible, every other tool
- keeps the historical image-turn hide.
+ explicit screen-context path attaches a screenshot, and a zeroed surface
+ blinded the very run_shell call the local-outcome mandate requires.
+
+ 2026-08-17: the hide is now a narrow deny-list, because the boundary it
+ was standing in for is enforced where it actually belongs. A turn that
+ mixes a look with an action ("Schau mal hier. Mach das Fenster zu.") is
+ classified SCREEN whenever ``intent.requests_screen_operation``'s
+ clause anchoring misses the action verb — and an emptied surface then
+ left the model describing a picture with no way to do the thing that was
+ asked. ``computer_use`` therefore stays: every call runs through
+ ``cu_gate.llm_computer_use_allowed`` first, which refuses a look request
+ even inside a live desktop episode, so the two paths still cannot both
+ run for one utterance. That gate reads the USER's utterance, never the
+ model's reasoning, so untrusted on-screen text cannot unlock it either.
+
+ What stays hidden is what injected screen text could otherwise start
+ unattended: the spawn vehicles and the deterministic record writes
+ (``_SCREEN_TURN_HIDDEN_TOOL_NAMES``) — minus any tool the deterministic
+ layer mandated this turn.
"""
- if self._evidence_required_is_write and self._evidence_required_tool:
- return {
- n: t for n, t in self._tools.items()
- if n == self._evidence_required_tool
- }
- return {}
+ keep = self._evidence_required_tool or ""
+ return {
+ n: t for n, t in self._tools.items()
+ if n not in _SCREEN_TURN_HIDDEN_TOOL_NAMES or n == keep
+ }
def _gate_screen_tool(
self,
@@ -5877,32 +5925,84 @@ class BrainManager:
log.debug("visualize request gate failed", exc_info=True)
return tools
+ @staticmethod
+ def _desktop_episode_is_live() -> bool:
+ """True while a Computer-Use mission is running or has just ended.
+
+ The one honest signal that the conversation context still holds a
+ desktop plan a signalless turn could INHERIT: every launch route
+ registers its mission (voice fast path, LLM tool, REST, scheduled). It
+ is deliberately the same registry and the same window
+ ``jarvis.brain.cu_gate`` consults for the mirror-image decision, so the
+ two readings of "are we in a desktop episode" cannot drift apart.
+
+ A failed probe answers "no episode": the default must be the full tool
+ surface, never a blinded one.
+ """
+ try:
+ from jarvis.brain.cu_gate import FOLLOW_UP_WINDOW_S # noqa: PLC0415
+ from jarvis.harness.cu_run_registry import ( # noqa: PLC0415
+ has_recent_run,
+ )
+
+ return bool(has_recent_run(FOLLOW_UP_WINDOW_S))
+ except Exception: # noqa: BLE001 — never blind the brain on a probe
+ log.debug("desktop-episode probe failed", exc_info=True)
+ return False
+
+ def _turn_reads_as_conversation(self, user_text: str) -> bool:
+ """True when the turn's own SHAPE says it asks for no record to be written.
+
+ Smalltalk or a plain question — the shapes the 2026-06-30 deep-dive
+ found exposed to the write/record tools ("does my budget fit?"). Each
+ detector is guarded on its own: ``_is_smalltalk`` needs the compiled
+ routing patterns, and a manager built without them must degrade to
+ "not obviously conversational" rather than take the whole gate down.
+ """
+ try:
+ if self._is_smalltalk(user_text):
+ return True
+ except Exception: # noqa: BLE001 — pattern cache unavailable
+ log.debug("smalltalk probe failed in the signalless gate", exc_info=True)
+ return _is_plain_knowledge_question(user_text)
+
def _hide_action_tools_on_signalless_turn(
self, tools: dict[str, Tool], user_text: str
) -> dict[str, Tool]:
- """Remove computer_use + the spawn vehicles from ANY turn that carries no
- action signal of its own, so the router-LLM cannot INHERIT the previous
- turn's desktop action from the conversation context.
-
- GENERAL rule, not one phrase (user mandate 2026-06-27 — "this must apply
- to ALL questions, that was only an example"): a question, a remark, or a
- mis-transcription asks for no desktop action. If the turn names no action
- of its own, it must not be able to fire ``computer_use``/spawn — whatever
- the conversation context holds. Length- and ``?``-agnostic: a long
- question is still a question; a trailing ``?`` no longer keeps the heavy
- tools (the prior version did, which let a mis-heard question still inherit
- a CU action). Forensic: "Was geht ab?" → STT "Lask it up!" [en] conf
- 0.509 → the brain re-ran the prior "open Discord, bridge-mine channel" CU
- plan on a turn that asked for nothing.
-
- A turn KEEPS the consequential tools only when it carries a real signal:
- an action-intent (open-app / PC-control / screen-surface / registry), an
- artifact-build request, or an explicitly named spawn vehicle. The
- read-only ``screenshot`` tool is never in the hidden set, so a visual
- question ("Was siehst du auf dem Bildschirm?") is still answered by
- looking — only the click/type AGENT loop is withheld. Any fault returns
- the tools unchanged so a gate bug can never blind the brain. Pure regex +
- the existing deterministic detectors (AP-11 safe, provider-agnostic).
+ """Withhold the consequential tools a turn could only have INHERITED.
+
+ Two distinct risks with two distinct pieces of evidence — and "the
+ action regex did not fire" is neither of them. The forensics:
+
+ 1. **Inheritance (2026-06-27).** "Was geht ab?" → STT "Lask it up!" [en]
+ conf 0.509 → the router-LLM, reading a 30k-token context full of the
+ prior "open Discord, bridge-mine channel" command, re-ran that exact
+ computer_use plan on a turn that asked for nothing. That risk needs
+ something to inherit: a desktop episode that is live or just ended
+ (``_desktop_episode_is_live``). Cold, there is no prior plan in the
+ context to re-run.
+ 2. **Write reflex (deep-dive 2026-06-30).** A "does my budget fit?" turn
+ carried google_calendar / contact-upsert / wiki-ingest /
+ update_profile in its surface. The evidence there is the turn's own
+ shape: smalltalk or a plain question asks for no record to be written
+ (``_turn_reads_as_conversation``).
+
+ What changed, and why (2026-08-17 review): the previous version hid both
+ sets from EVERY turn that missed ``is_open_app_intent`` /
+ ``_looks_like_pc_control`` / the capability registry. That regex knows
+ "klick" and "Bildschirm"; it does not know "spiel Musik", "ruf Anna an"
+ or "trag das in meinen Kalender ein" — so those turns reached the model
+ with no vehicle at all and could only be talked about. Absence of a
+ keyword is not evidence of absence of intent. A tool the model declines
+ to call is free; a tool it cannot see is the bug users report.
+
+ Both protections above still fire, on their own evidence. A genuine
+ action signal (action-intent, artifact-build request, named spawn
+ vehicle, request framing) short-circuits the gate, the read-only ``screenshot``
+ tool is never hidden, and a tool the deterministic layer mandated this
+ turn is never stripped (AD-CLI8). Pure regex + registry lookups, no
+ model in the path (AP-11 safe). Any fault returns the tools unchanged so
+ a gate bug can never blind the brain.
"""
if not isinstance(tools, dict):
return tools
@@ -5912,20 +6012,30 @@ class BrainManager:
return tools
# Any genuine ACTION signal keeps the consequential tools: an action
# intent (open-app / PC-control / names the screen surface / registry
- # intent), an artifact-build request, or an explicitly named spawn
- # vehicle. A turn with NONE of these asks for no desktop action.
+ # intent), an artifact-build request, an explicitly named spawn
+ # vehicle — or REQUEST FRAMING. The last one is the same signal
+ # ``_is_smalltalk`` already trusts to call a turn a command rather
+ # than chit-chat: "Kannst du Anna anrufen?" is question-SHAPED and
+ # would otherwise lose call-contact to the write-reflex half below,
+ # and "kannst du das nochmal machen?" is the corrective follow-up
+ # cu_gate's episode window exists to keep alive.
if (
self._turn_has_action_intent(t)
or self._research_wants_artifact(t)
or self._is_explicit_heavy_request(t)
+ or _ACTION_REQUEST_RE.search(t)
):
return tools
- # Hide computer_use/spawn AND the deterministic write/record tools so
- # the model cannot pick one on a no-action conversational turn — but
+ hidden: set[str] = set()
+ if self._desktop_episode_is_live():
+ hidden |= _INHERITABLE_ACTION_TOOL_NAMES
+ if self._turn_reads_as_conversation(t):
+ hidden |= _DETERMINISTIC_WRITE_TOOL_NAMES
+ if not hidden:
+ return tools
# NEVER strip a tool the deterministic layer already mandated this
# turn (a say-do write via resolve_save_mandate, or a calendar/email
# READ via the evidence gate), or those features regress (AD-CLI8).
- hidden = _INHERITABLE_ACTION_TOOL_NAMES | _DETERMINISTIC_WRITE_TOOL_NAMES
mandated = getattr(self, "_evidence_required_tool", "") or ""
return {
n: tool
@@ -10325,15 +10435,14 @@ class BrainManager:
if self._cost_meter.over_daily_budget():
return "Tagesbudget ueberschritten."
- # Smalltalk near-toolless path (bug fix 2026-05-01): on clearly
- # identified smalltalk the spawn/action tools are hidden so the LLM
- # cannot be tempted to hallucinate "spawn_worker" (see voice session
- # 2026-04-30 22:38, "es geht ab" → fake spawn). The read-only screenshot
- # tool stays visible (see _smalltalk_tool_override) so the brain can
- # still look at the screen on demand even on a greeting-prefixed turn
- # like "Hallo, lies mir vor was oben links steht" (live failure
- # 2026-05-31). Force-spawn already ran (smalltalk wins there against verb
- # match); now we also constrain the LLM tool-choice path.
+ # Smalltalk spawn-hide (bug fix 2026-05-01): on clearly identified
+ # smalltalk the spawn vehicles are hidden so the LLM cannot be tempted to
+ # hallucinate "spawn_worker" (see voice session 2026-04-30 22:38, "es
+ # geht ab" → fake spawn). Only those — the rest of the surface stays, so
+ # a request the substring allowlist merely READS as chit-chat still has
+ # something to act with (see _smalltalk_tool_override). Force-spawn
+ # already ran (smalltalk wins there against verb match); now we also
+ # constrain the LLM tool-choice path.
is_smalltalk_turn = self._is_smalltalk(user_text)
if is_smalltalk_turn:
log.info(
@@ -10629,8 +10738,10 @@ class BrainManager:
vision_capable_seen = True
_turn_tools = (
- # Image turn: pixels answer the turn — tools withheld, EXCEPT
- # a mandated write tool (see _image_turn_tool_override).
+ # Captured-screen turn: the pixels answer it, but the surface is
+ # NARROWED, not emptied — a look glued to an action still needs
+ # its vehicle, and cu_gate enforces the look/operate boundary per
+ # call (see _image_turn_tool_override).
self._image_turn_tool_override()
if screen_context.has_image
else self._smalltalk_tool_override() if is_smalltalk_turn
@@ -10658,11 +10769,12 @@ class BrainManager:
_turn_tools = self._hide_spawn_on_knowledge_question(
_turn_tools, user_text
)
- # Signalless-turn action-hide (forensic 2026-06-27): a short turn with
- # NO actionable signal of its own ("Was geht ab?" mis-heard as "Lask
- # it up!" conf 0.509) must not be able to reach computer_use/spawn —
- # the router-LLM would otherwise INHERIT the previous turn's CU action
- # from the conversation context and fire a wrong desktop action.
+ # Signalless-turn action-hide (forensic 2026-06-27): inside a live
+ # desktop episode a turn with NO actionable signal of its own ("Was
+ # geht ab?" mis-heard as "Lask it up!" conf 0.509) must not reach
+ # computer_use/spawn — the router-LLM would otherwise INHERIT the
+ # previous turn's CU action from the conversation context. Outside an
+ # episode there is nothing to inherit and the vehicle stays.
if isinstance(_turn_tools, dict):
_turn_tools = self._hide_action_tools_on_signalless_turn(
_turn_tools, user_text
@@ -11267,9 +11379,9 @@ class BrainManager:
return injected
# A turn under a WRITE mandate is an ACTION turn, not a vision turn
- # (shell-consistency rework 2026-08-08): an attached image zeroes the
- # tool surface downstream (screen_context.has_image → tools={}), which
- # would blind the very tool the mandate requires. "erstell einen Ordner
+ # (shell-consistency rework 2026-08-08): an attached image narrows the
+ # tool surface downstream (_image_turn_tool_override), and the mandated
+ # write tool is the one it must not lose. "erstell einen Ordner
# hier auf dem Desktop" carries the visual marker "hier auf" yet wants
# a shell action, not a screen answer — same for a mandated contact/
# wiki write. Read mandates are untouched (they never attach anyway:
diff --git a/tests/unit/brain/test_evidence_gate_wiring.py b/tests/unit/brain/test_evidence_gate_wiring.py
index da2af8403b..14480b857b 100644
--- a/tests/unit/brain/test_evidence_gate_wiring.py
+++ b/tests/unit/brain/test_evidence_gate_wiring.py
@@ -8,23 +8,28 @@ from jarvis.brain.manager import BrainManager
def _bare_manager() -> BrainManager:
m = BrainManager.__new__(BrainManager)
- m._tools = {"screenshot": object(), "cli_gam": object(), "spawn-worker": object()}
+ m._tools = {"screenshot": object(), "cli_gam": object(), "spawn_worker": object()}
return m
def test_smalltalk_override_keeps_required_evidence_tool():
+ # "was steht heute an" classifies as smalltalk; the mandated evidence tool
+ # must stay visible or the directive is unfulfillable (AD-CLI8).
m = _bare_manager()
m._evidence_required_tool = "cli_gam"
visible = m._smalltalk_tool_override()
assert "cli_gam" in visible
- assert "spawn-worker" not in visible
+ assert "spawn_worker" not in visible
-def test_smalltalk_override_unchanged_without_required_tool():
+def test_smalltalk_override_keeps_a_cli_tool_without_a_mandate():
+ # Since 2026-08-17 the override is a hide-list, not an allowlist: only the
+ # spawn vehicles go. A CLI read tool needs no mandate to stay reachable.
m = _bare_manager()
m._evidence_required_tool = ""
visible = m._smalltalk_tool_override()
- assert "cli_gam" not in visible
+ assert "cli_gam" in visible
+ assert "spawn_worker" not in visible
def test_run_evidence_gate_degrades_to_pass_on_missing_config():
diff --git a/tests/unit/brain/test_image_turn_tool_override.py b/tests/unit/brain/test_image_turn_tool_override.py
index 76ca73ceb3..72188c6345 100644
--- a/tests/unit/brain/test_image_turn_tool_override.py
+++ b/tests/unit/brain/test_image_turn_tool_override.py
@@ -1,12 +1,19 @@
-"""Image-turn tool surface: historically ``{}`` (pixels answer the turn), but
-a mandated WRITE tool must survive it (code-review finding 2026-08-08).
+"""Captured-screen turn: the tool surface is narrowed, never emptied.
-"erstell einen Ordner hier auf dem Desktop" matches the screen-intent phrase
-"hier auf dem", the explicit screen-context path attaches a screenshot, and
-the old hard ``{}`` stripped the very ``run_shell`` call the local-outcome
-mandate requires — the honest "never ran" fallback fired instead of the
-action. Mirrors ``test_smalltalk_tool_visibility.py``.
-"""
+Historically hard ``{}`` (docs/screen-context.md §3.1a, maintainer mandate
+2026-08-02 "looking is not operating"), then widened once for a mandated WRITE
+tool (code-review finding 2026-08-08).
+
+2026-08-17 review: an emptied surface left a turn that MIXES a look with an
+action ("Schau mal hier. Mach das Fenster zu.") describing a picture with no way
+to do the thing that was asked — ``intent.requests_screen_operation`` anchors its
+action verbs at the clause start, so a separable German verb slips through and
+the turn still classifies SCREEN. ``computer_use`` therefore stays in the
+surface; the look/operate boundary is enforced per call by
+``cu_gate.llm_computer_use_allowed``, which reads the USER's utterance and so
+refuses a pure look request anyway (pinned in
+``test_screen_turn_computer_use_boundary`` below).
+""" # i18n-allow: verbatim quote of the German utterance
from __future__ import annotations
@@ -21,34 +28,86 @@ def _mgr(tools: dict, *, required: str = "", is_write: bool = False) -> BrainMan
return m
-def test_image_turn_hides_all_tools_without_mandate() -> None:
- m = _mgr({"run_shell": object(), "spawn_worker": object(), "screenshot": object()})
- assert m._image_turn_tool_override() == {}
+def _surface() -> dict:
+ return {
+ "screenshot": object(), # read — must stay
+ "search_web": object(), # read — must stay
+ "computer_use": object(), # the action vehicle a screen turn may need
+ "run_shell": object(), # write mandate target (2026-08-08)
+ "spawn_worker": object(), # unattended background agent — hidden
+ "multi_spawn": object(), # ditto
+ "contact-upsert": object(), # silent record write — hidden
+ "wiki-ingest": object(), # ditto
+ "google_calendar": object(), # ditto
+ "call-contact": object(), # ditto
+ "update_profile": object(), # ditto
+ }
+
+
+def test_screen_turn_keeps_computer_use_and_the_read_tools() -> None:
+ out = _mgr(_surface())._image_turn_tool_override()
+ for kept in ("screenshot", "search_web", "computer_use", "run_shell"):
+ assert kept in out, kept
+
+
+def test_screen_turn_hides_the_unattended_vehicles() -> None:
+ # Screen pixels are untrusted evidence (docs/screen-context.md §4.2): text
+ # rendered on screen must not be able to start a background agent or write a
+ # record behind the user's back.
+ out = _mgr(_surface())._image_turn_tool_override()
+ for hidden in (
+ "spawn_worker", "multi_spawn", "contact-upsert", "wiki-ingest",
+ "google_calendar", "call-contact", "update_profile",
+ ):
+ assert hidden not in out, hidden
+
+
+def test_screen_turn_never_empties_the_surface() -> None:
+ m = _mgr({"screenshot": object(), "computer_use": object()})
+ assert m._image_turn_tool_override() != {}
-def test_image_turn_keeps_only_the_mandated_write_tool() -> None:
+def test_screen_turn_keeps_the_mandated_write_tool() -> None:
+ # "erstell einen Ordner hier auf dem Desktop" (2026-08-08): the local-outcome
+ # mandate needs run_shell, and it must survive the screen-turn hide.
shell = object()
- m = _mgr(
- {"run_shell": shell, "spawn_worker": object(), "screenshot": object()},
- required="run_shell",
- is_write=True,
- )
- assert m._image_turn_tool_override() == {"run_shell": shell}
-
-
-def test_image_turn_read_mandate_keeps_the_historical_hide() -> None:
- # A READ mandate answers from the mandated tool's data path elsewhere;
- # the image-turn hide only widens for WRITE mandates.
- m = _mgr(
- {"cli_gcloud": object(), "screenshot": object()},
- required="cli_gcloud",
- is_write=False,
- )
- assert m._image_turn_tool_override() == {}
-
-
-def test_image_turn_mandated_tool_missing_degrades_to_empty() -> None:
- # Mandate for a tool that is not registered (deployment without run_shell)
- # must not crash and keeps the historical hide.
- m = _mgr({"screenshot": object()}, required="run_shell", is_write=True)
- assert m._image_turn_tool_override() == {}
+ m = _mgr({"run_shell": shell, "spawn_worker": object()}, required="run_shell", is_write=True)
+ out = m._image_turn_tool_override()
+ assert out["run_shell"] is shell
+ assert "spawn_worker" not in out
+
+
+def test_screen_turn_mandate_exempts_a_hidden_tool() -> None:
+ # A mandated record write (say-do via resolve_save_mandate) outranks the
+ # hide, exactly as it does in the signalless gate (AD-CLI8).
+ ingest = object()
+ m = _mgr({"wiki-ingest": ingest, "contact-upsert": object()}, required="wiki-ingest")
+ out = m._image_turn_tool_override()
+ assert out["wiki-ingest"] is ingest
+ assert "contact-upsert" not in out
+
+
+def test_screen_turn_computer_use_boundary_still_holds() -> None:
+ """The 2026-08-02 mandate survives the widened surface.
+
+ computer_use being VISIBLE is not computer_use being ALLOWED: the execution
+ gate refuses a pure look request and permits the mixed look-plus-action turn
+ the empty surface used to break.
+ """
+ from jarvis.brain.cu_gate import llm_computer_use_allowed
+ from jarvis.screen_context.intent import classify
+ from jarvis.screen_context.models import VisualIntent
+
+ # A pure look request captures, and computer_use is refused for it even
+ # though the tool now sits in the surface. The mandate's outcome holds.
+ for look in ("Was siehst du auf meinem Bildschirm?", "Lies mir das mal vor"):
+ assert not llm_computer_use_allowed(look), look
+
+ # The turn the empty surface used to break: a look glued to an action whose
+ # verb ``requests_screen_operation`` misses (German separable "mach … zu"),
+ # so it still classifies SCREEN and still captures — but the action is real
+ # and the vehicle must be both visible AND allowed.
+ mixed = "Schau mal hier. Mach das Fenster zu."
+ assert classify(mixed).intent is VisualIntent.SCREEN
+ assert llm_computer_use_allowed(mixed)
+ assert "computer_use" in _mgr(_surface())._image_turn_tool_override()
diff --git a/tests/unit/brain/test_routing.py b/tests/unit/brain/test_routing.py
index 908eb970d0..d366093f63 100644
--- a/tests/unit/brain/test_routing.py
+++ b/tests/unit/brain/test_routing.py
@@ -3380,12 +3380,12 @@ def _manager_with_cu_spawn_search() -> BrainManager:
)
-# GENERAL rule (user mandate 2026-06-27 — "this must apply to ALL questions"):
-# ANY turn with no action signal of its own — short or long, with or without a
-# trailing "?" — loses computer_use/spawn so it cannot inherit the previous
-# turn's CU action. Mis-transcriptions, smalltalk, and plain questions all
-# qualify. (The real "Was geht ab?" is ALSO caught upstream by the smalltalk
-# gate; here we prove the filter itself no longer exempts it.)
+# User mandate 2026-06-27 ("this must apply to ALL questions"): a turn with no
+# action signal of its own — short or long, with or without a trailing "?" —
+# cannot inherit the previous turn's CU action. Since 2026-08-17 the hide is
+# gated on the evidence that makes inheritance possible at all: a desktop
+# episode that is live or just ended. Cold, the vehicle stays — see
+# tests/unit/brain/test_signalless_action_vehicles.py.
NO_ACTION_SIGNAL_TURNS = [
"Lask it up!", # the live STT junk
"Mask it up.", # sibling STT-junk variant
@@ -3398,11 +3398,13 @@ NO_ACTION_SIGNAL_TURNS = [
@pytest.mark.parametrize("utterance", NO_ACTION_SIGNAL_TURNS)
def test_no_action_signal_turn_hides_computer_use_and_spawn(utterance: str) -> None:
- """ANY turn with no action signal of its own (question, remark, or
- mis-transcription — regardless of length or a trailing '?') cannot reach
- computer_use/spawn, so the LLM cannot inherit the previous turn's CU action.
- The read-only search tool stays visible so the turn is still answerable."""
+ """Inside a live desktop episode, ANY turn with no action signal of its own
+ (question, remark, or mis-transcription — regardless of length or a trailing
+ '?') cannot reach computer_use/spawn, so the LLM cannot inherit the previous
+ turn's CU action. The read-only search tool stays visible so the turn is
+ still answerable."""
manager = _manager_with_cu_spawn_search()
+ manager._desktop_episode_is_live = lambda: True # type: ignore[method-assign]
gated = manager._hide_action_tools_on_signalless_turn(
dict(manager._tools), utterance
)
diff --git a/tests/unit/brain/test_signalless_action_vehicles.py b/tests/unit/brain/test_signalless_action_vehicles.py
new file mode 100644
index 0000000000..882e69f1a9
--- /dev/null
+++ b/tests/unit/brain/test_signalless_action_vehicles.py
@@ -0,0 +1,183 @@
+"""An ordinary action request keeps its vehicle; inheritance is still blocked.
+
+Two halves of ``_hide_action_tools_on_signalless_turn`` (2026-08-17 rework):
+
+* The 2026-06-27 forensic stays fixed. "Was geht ab?" -> STT "Lask it up!" [en]
+ conf 0.509, and the router-LLM re-ran the prior "open Discord, bridge-mine
+ channel" computer_use plan on a turn that asked for nothing. That inheritance
+ needs a desktop episode in the context to inherit FROM, so the hide is gated
+ on ``cu_run_registry.has_recent_run`` — the same signal ``cu_gate`` uses.
+* Cold, the vehicles stay. The old gate hid computer_use and every write tool
+ from any turn missing ``is_open_app_intent`` / ``_looks_like_pc_control`` /
+ the capability registry. That regex knows "klick" and "Bildschirm"; it does
+ not know "spiel Musik", "ruf Anna an" or "trag das in meinen Kalender ein",
+ so those requests reached the model with no vehicle at all.
+""" # i18n-allow: verbatim quotes of the live German utterances
+from __future__ import annotations
+
+import re
+
+import pytest
+
+from jarvis.brain.manager import BrainManager
+from jarvis.harness import cu_run_registry
+
+_NEVER = re.compile(r"(?!)") # matches nothing — no explicit heavy-work vehicle
+
+
[email protected](autouse=True)
+def _clean_registry():
+ cu_run_registry.clear_runs()
+ yield
+ cu_run_registry.clear_runs()
+
+
+def _mgr(*, episode_live: bool | None = None) -> BrainManager:
+ """A manager with every deterministic action detector answering "no signal"."""
+ m = BrainManager.__new__(BrainManager) # bypass heavy __init__
+ m._force_spawn_pattern = _NEVER
+ m._evidence_required_tool = ""
+ m._turn_has_action_intent = lambda _t: False # type: ignore[method-assign]
+ m._research_wants_artifact = lambda _t: False # type: ignore[method-assign]
+ m._is_smalltalk = lambda _t: False # type: ignore[method-assign]
+ if episode_live is not None:
+ m._desktop_episode_is_live = lambda: episode_live # type: ignore[method-assign]
+ return m
+
+
+def _surface() -> dict:
+ return {
+ "search_web": object(),
+ "screenshot": object(),
+ "computer_use": object(),
+ "spawn_worker": object(),
+ "multi_spawn": object(),
+ "call-contact": object(),
+ "google_calendar": object(),
+ "spotify/play": object(),
+ }
+
+
+# --------------------------------------------------------------------------
+# The vehicles survive an ordinary action request
+# --------------------------------------------------------------------------
+
+# Real requests whose verb is in no PC-control regex and in no seeded registry.
+# Each names an action; none may lose the tool that could perform it.
+VEHICLE_TURNS = [
+ "Spiel Musik", # i18n-allow: play music
+ "Ruf Anna an", # i18n-allow: call Anna
+ "Trag das in meinen Kalender ein", # i18n-allow: put that in my calendar
+ "Mach das Licht aus", # i18n-allow: turn off the light
+]
+
+
[email protected]("utterance", VEHICLE_TURNS)
+def test_ordinary_action_request_keeps_every_vehicle(utterance: str) -> None:
+ gated = _mgr(episode_live=False)._hide_action_tools_on_signalless_turn(
+ _surface(), utterance
+ )
+ for kept in ("computer_use", "call-contact", "google_calendar", "spotify/play"):
+ assert kept in gated, (
+ f"{kept} must stay visible on an action request the regex misses: "
+ f"{utterance!r}"
+ )
+
+
+def test_no_gate_fires_when_nothing_is_conversational_and_no_episode_runs() -> None:
+ surface = _surface()
+ gated = _mgr(episode_live=False)._hide_action_tools_on_signalless_turn(
+ surface, "Spiel Musik" # i18n-allow
+ )
+ assert set(gated) == set(surface), "a cold, non-conversational turn loses nothing"
+
+
+# --------------------------------------------------------------------------
+# The 2026-06-27 inheritance forensic stays fixed
+# --------------------------------------------------------------------------
+
+NO_ACTION_SIGNAL_TURNS = [
+ "Lask it up!", # the live STT junk
+ "Mask it up.", # sibling STT-junk variant
+ "Was geht ab?", # i18n-allow: the original question
+ "Wie viele Menschen leben in Australien?", # i18n-allow: long factual question
+ "Which company owns the most data centers in the world right now?",
+]
+
+
[email protected]("utterance", NO_ACTION_SIGNAL_TURNS)
+def test_signalless_turn_inside_a_desktop_episode_loses_the_heavy_tools(
+ utterance: str,
+) -> None:
+ gated = _mgr(episode_live=True)._hide_action_tools_on_signalless_turn(
+ _surface(), utterance
+ )
+ assert "computer_use" not in gated, (
+ f"computer_use must not be inheritable on: {utterance!r}"
+ )
+ assert "spawn_worker" not in gated
+ assert "multi_spawn" not in gated
+ assert "search_web" in gated, "read-only search_web must stay visible"
+
+
+def test_live_registry_run_drives_the_episode_probe() -> None:
+ # Not a stub: the real registry decides, so the gate and cu_gate can never
+ # read "are we in a desktop episode" differently.
+ assert BrainManager._desktop_episode_is_live() is False
+ cu_run_registry.register_run("m-1", "open Discord, bridge-mine channel", None)
+ assert BrainManager._desktop_episode_is_live() is True
+
+ gated = _mgr()._hide_action_tools_on_signalless_turn(_surface(), "Lask it up!")
+ assert "computer_use" not in gated
+
+ cu_run_registry.clear_runs()
+ gated = _mgr()._hide_action_tools_on_signalless_turn(_surface(), "Lask it up!")
+ assert "computer_use" in gated, (
+ "with no desktop episode there is no prior plan to inherit"
+ )
+
+
+def test_action_intent_keeps_the_vehicles_even_inside_an_episode() -> None:
+ m = _mgr(episode_live=True)
+ m._turn_has_action_intent = lambda _t: True # type: ignore[method-assign]
+ gated = m._hide_action_tools_on_signalless_turn(
+ _surface(), "Klick auf den Play-Button" # i18n-allow
+ )
+ assert "computer_use" in gated
+
+
+# --------------------------------------------------------------------------
+# Request framing is not a question
+# --------------------------------------------------------------------------
+
+POLITE_REQUESTS = [
+ "Kannst du Anna anrufen?", # i18n-allow: can you call Anna
+ "Kannst du das nochmal machen?", # i18n-allow: the BUG-105 follow-up shape
+ "Can you put that in my calendar?",
+ "Ich möchte Musik hören", # i18n-allow: I want to hear music
+]
+
+
[email protected]("utterance", POLITE_REQUESTS)
+def test_request_framing_keeps_every_vehicle(utterance: str) -> None:
+ """A politely framed request is question-SHAPED but it is a command.
+
+ ``_is_smalltalk`` already trusts ``_ACTION_REQUEST_RE`` for exactly this
+ call; without it here, "Kannst du Anna anrufen?" ends in "?" and loses
+ call-contact to the write-reflex half, and a corrective follow-up inside a
+ live desktop episode loses the computer_use that cu_gate's follow-up window
+ exists to keep alive.
+ """
+ m = _mgr(episode_live=True)
+ m._is_smalltalk = lambda _t: True # type: ignore[method-assign]
+ gated = m._hide_action_tools_on_signalless_turn(_surface(), utterance)
+ assert set(gated) == set(_surface()), f"nothing may be hidden on: {utterance!r}"
+
+
+def test_the_gate_never_empties_a_surface() -> None:
+ # Worst case: a conversational turn inside a live desktop episode. Even then
+ # the read-only tools survive — a gate narrows, it never blanks.
+ m = _mgr(episode_live=True)
+ m._is_smalltalk = lambda _t: True # type: ignore[method-assign]
+ gated = m._hide_action_tools_on_signalless_turn(_surface(), "Was geht ab?")
+ assert set(gated) == {"search_web", "screenshot", "spotify/play"}
diff --git a/tests/unit/brain/test_signalless_write_tool_hide.py b/tests/unit/brain/test_signalless_write_tool_hide.py
index 5678cadfc3..bb935adcb2 100644
--- a/tests/unit/brain/test_signalless_write_tool_hide.py
+++ b/tests/unit/brain/test_signalless_write_tool_hide.py
@@ -1,14 +1,14 @@
-"""A signalless turn must not be able to reach a deterministic write/record tool.
+"""A conversational turn must not be able to reach a deterministic write tool.
Latent exposure found 2026-06-30 (deep-dive agent 2): on a no-action
-conversational turn the model still sees the foreground write/record tools
+conversational turn the model still saw the foreground write/record tools
(``contact-upsert``, ``update-profile``, ``wiki-ingest``, ``google_calendar``
-writes, ``call-contact``). The existing ``_hide_action_tools_on_signalless_turn``
-only stripped ``computer_use`` + the spawn vehicles. This widens it to the
-write/record tools too — with a hard exemption for any tool the deterministic
-layer ALREADY mandated this turn (a real "merk dir, dass…" keeps ``wiki-ingest``
-via ``resolve_save_mandate``; a calendar READ keeps ``google_calendar`` via the
-evidence gate), so the say-do write feature and calendar reads do not regress.
+writes, ``call-contact``) — "does my budget fit?" is the forensic shape.
+
+2026-08-17: the trigger is the turn's own SHAPE (smalltalk or a plain question),
+not "the action regex did not fire". The old signalless reading stripped these
+tools from "ruf Anna an" and "trag das in meinen Kalender ein" too — see
+``test_signalless_action_vehicles.py`` for the other half of the rework.
"""
from __future__ import annotations
@@ -19,13 +19,15 @@ from jarvis.brain.manager import BrainManager
_NEVER = re.compile(r"(?!)") # matches nothing — no explicit heavy-work vehicle
-def _mgr() -> BrainManager:
+def _mgr(*, smalltalk: bool = False) -> BrainManager:
m = BrainManager.__new__(BrainManager) # bypass heavy __init__
m._force_spawn_pattern = _NEVER
m._evidence_required_tool = ""
# Signalless by default; individual tests flip these as needed.
m._turn_has_action_intent = lambda _t: False # type: ignore[method-assign]
m._research_wants_artifact = lambda _t: False # type: ignore[method-assign]
+ m._is_smalltalk = lambda _t: smalltalk # type: ignore[method-assign]
+ m._desktop_episode_is_live = lambda: False # type: ignore[method-assign]
return m
@@ -34,26 +36,29 @@ def _surface() -> dict:
"search_web": object(), # read — must stay
"wiki-recall": object(), # read — must stay
"screenshot": object(), # read — must stay
- "contact-upsert": object(), # write — hide on signalless
+ "contact-upsert": object(), # write — hide on a conversational turn
# Keyed by the tool's .name attribute (update_profile) — NOT the
# hyphenated entry-point name. The 2026-07-06 pipeline audit found the
# constant AND this test both carried "update-profile", so the gate
# never actually stripped the real tool from a live turn.
- "update_profile": object(), # write — hide on signalless
- "wiki-ingest": object(), # write — hide on signalless
- "google_calendar": object(), # write path — hide on signalless
+ "update_profile": object(), # write — hide on a conversational turn
+ "wiki-ingest": object(), # write — hide on a conversational turn
+ "google_calendar": object(), # write path — hide on a conversational turn
"call-contact": object(), # action (places a call) — hide
- "computer_use": object(), # existing hidden
- "spawn_worker": object(), # existing hidden
+ "computer_use": object(), # inheritance half — see the sibling module
+ "spawn_worker": object(), # inheritance half — see the sibling module
}
-def test_signalless_turn_hides_write_and_record_tools():
+def test_plain_question_hides_write_and_record_tools():
+ # The 2026-06-30 forensic shape: a question that writes nothing.
m = _mgr()
- out = m._hide_action_tools_on_signalless_turn(_surface(), "Was geht ab?")
+ out = m._hide_action_tools_on_signalless_turn(
+ _surface(), "Passt das noch in mein Budget?" # i18n-allow: the forensic turn
+ )
for hidden in (
"contact-upsert", "update_profile", "wiki-ingest",
- "google_calendar", "call-contact", "computer_use", "spawn_worker",
+ "google_calendar", "call-contact",
):
assert hidden not in out, hidden
# Read-only tools are never stripped — the turn stays answerable inline.
@@ -61,6 +66,13 @@ def test_signalless_turn_hides_write_and_record_tools():
assert kept in out, kept
+def test_smalltalk_turn_hides_write_and_record_tools():
+ m = _mgr(smalltalk=True)
+ out = m._hide_action_tools_on_signalless_turn(_surface(), "Alles klar bei dir")
+ assert "contact-upsert" not in out
+ assert "google_calendar" not in out
+
+
def test_action_intent_keeps_the_write_tools():
m = _mgr()
m._turn_has_action_intent = lambda _t: True # type: ignore[method-assign]
@@ -73,9 +85,9 @@ def test_action_intent_keeps_the_write_tools():
def test_mandated_write_tool_is_exempt_say_do_stays_green():
# resolve_save_mandate fired for "merk dir, dass…" and set the mandate; the
- # signalless hide must NOT strip the mandated write tool, or the say-do
- # write feature breaks again (project_bug_contact_say_do_gap_no_upsert).
- m = _mgr()
+ # hide must NOT strip the mandated write tool, or the say-do write feature
+ # breaks again (project_bug_contact_say_do_gap_no_upsert).
+ m = _mgr(smalltalk=True)
m._evidence_required_tool = "wiki-ingest"
out = m._hide_action_tools_on_signalless_turn(
_surface(), "Merk dir, dass ich nach Bora Bora will" # i18n-allow
@@ -85,10 +97,25 @@ def test_mandated_write_tool_is_exempt_say_do_stays_green():
def test_explicit_subagent_vehicle_keeps_tools():
- m = _mgr()
+ m = _mgr(smalltalk=True)
m._force_spawn_pattern = re.compile(r"deep dive|subagent", re.I)
+ m._desktop_episode_is_live = lambda: True # type: ignore[method-assign]
out = m._hide_action_tools_on_signalless_turn(
_surface(), "Mach einen deep dive und trag das ein" # i18n-allow
)
assert "spawn_worker" in out
assert "google_calendar" in out
+
+
+def test_a_broken_smalltalk_probe_does_not_take_the_gate_down():
+ # _is_smalltalk needs the compiled routing patterns; a manager without them
+ # must degrade to the question-shape check, not lose the whole gate.
+ m = _mgr()
+
+ def _boom(_t: str) -> bool:
+ raise RuntimeError("no routing patterns")
+
+ m._is_smalltalk = _boom # type: ignore[method-assign]
+ out = m._hide_action_tools_on_signalless_turn(_surface(), "Was kostet das?")
+ assert "google_calendar" not in out
+ assert "search_web" in out
diff --git a/tests/unit/brain/test_skill_routing_guard.py b/tests/unit/brain/test_skill_routing_guard.py
index 6356072237..b13587ab31 100644
--- a/tests/unit/brain/test_skill_routing_guard.py
+++ b/tests/unit/brain/test_skill_routing_guard.py
@@ -202,10 +202,15 @@ def test_smalltalk_override_keeps_run_skill_on_skill_turn(skill_ctx) -> None:
assert "run-skill" in tools
-def test_smalltalk_override_hides_run_skill_without_match() -> None:
+def test_smalltalk_override_keeps_run_skill_without_match() -> None:
+ # Since 2026-08-17 the override hides only the spawn vehicles, so run-skill
+ # is reachable on any smalltalk turn — the SKILLS-FIRST router rule wants it
+ # there, and a skill the deterministic matcher missed can still be invoked.
+ # The AD-S3 keep above is belt and braces for a matched turn.
m = _make_manager()
tools = m._smalltalk_tool_override()
- assert "run-skill" not in tools
+ assert "run-skill" in tools
+ assert "spawn_worker" not in tools
# ----------------------------------------------------------------------
diff --git a/tests/unit/brain/test_smalltalk_tool_visibility.py b/tests/unit/brain/test_smalltalk_tool_visibility.py
index 3c87ad6fdd..231006b471 100644
--- a/tests/unit/brain/test_smalltalk_tool_visibility.py
+++ b/tests/unit/brain/test_smalltalk_tool_visibility.py
@@ -1,25 +1,78 @@
-"""P2 fix: a smalltalk turn hides spawn/action tools (anti-fake-spawn, 2026-05-01)
-but KEEPS the read-only screenshot tool, so the brain can still look at the screen
-on demand (Wave 2) even when the turn was classified smalltalk — e.g. the live
-2026-05-31 failure "Hallo, lies mir vor was oben links steht" left the brain with
-no screenshot tool and it could only stall ("ich schaue nach … einen Moment").""" # i18n-allow: verbatim quote of the hallucinated runtime output
+"""A smalltalk turn hides the SPAWN vehicles and nothing else.
+
+The 2026-05-01 incident was one tool class: the user said "es geht ab", the
+allowlist missed it, and the LLM hallucinated a Jarvis-Agent spawn — Jarvis then
+claimed to have started tests it never started. That protection is pinned below.
+
+Hiding the whole surface was the bug on the other side (2026-08-17 review):
+smalltalk here is a substring allowlist, so a real request that merely reads as
+chit-chat reached the model with no action tool at all and could only be talked
+about — the same shape as the live 2026-05-31 failure "Hallo, lies mir vor was
+oben links steht", where the brain could only stall.
+""" # i18n-allow: verbatim quotes of the live German utterances
from __future__ import annotations
from jarvis.brain.manager import BrainManager
-def _mgr(tools: dict) -> BrainManager:
+def _mgr(tools: dict, *, required: str = "", skill_match: object = None) -> BrainManager:
m = BrainManager.__new__(BrainManager) # bypass heavy __init__
m._tools = tools
+ m._evidence_required_tool = required
+ m._skill_turn_match_fallback = skill_match
return m
-def test_smalltalk_keeps_screenshot_hides_spawn() -> None:
- m = _mgr({"screenshot": object(), "spawn_worker": object(), "run_shell": object()})
+def test_smalltalk_hides_the_spawn_vehicles() -> None:
+ m = _mgr({"spawn_worker": object(), "multi_spawn": object(), "run_shell": object()})
+ override = m._smalltalk_tool_override()
+ assert "spawn_worker" not in override
+ assert "multi_spawn" not in override
+
+
+def test_smalltalk_keeps_the_read_only_and_action_tools() -> None:
+ # Everything that is not a spawn vehicle survives: the turn may still be a
+ # real request the allowlist merely read as chit-chat.
+ m = _mgr(
+ {
+ "screenshot": object(),
+ "search_web": object(),
+ "computer_use": object(),
+ "run_shell": object(),
+ "spawn_worker": object(),
+ }
+ )
+ override = m._smalltalk_tool_override()
+ assert set(override) == {"screenshot", "search_web", "computer_use", "run_shell"}
+
+
+def test_smalltalk_turn_with_an_action_keeps_an_action_vehicle() -> None:
+ # "Hallo, mach mal Musik an" — a greeting-prefixed request. Even when the
+ # allowlist classifies the turn as smalltalk, the model must still see a
+ # vehicle it could act with, or the request is impossible by construction.
+ m = _mgr({"computer_use": object(), "spotify/play": object(), "spawn_worker": object()})
override = m._smalltalk_tool_override()
- assert set(override) == {"screenshot"}
+ assert "computer_use" in override
+ assert "spotify/play" in override
+
+
+def test_mandated_tool_survives_even_when_it_is_a_spawn_vehicle() -> None:
+ # AD-CLI8: the deterministic layer's mandate outranks the hide.
+ spawn = object()
+ m = _mgr({"spawn_worker": spawn, "multi_spawn": object()}, required="spawn_worker")
+ assert m._smalltalk_tool_override() == {"spawn_worker": spawn}
+
+
+def test_skill_matched_turn_keeps_run_skill() -> None:
+ # AD-S3: a greeting-style trigger ("guten Morgen" -> morning-routine) still
+ # invokes its skill. run-skill is not in the hidden set anyway; the explicit
+ # keep is belt and braces and this pins it.
+ m = _mgr({"run-skill": object(), "spawn_worker": object()}, skill_match=object())
+ assert "run-skill" in m._smalltalk_tool_override()
-def test_smalltalk_override_empty_without_screenshot() -> None:
- m = _mgr({"spawn_worker": object(), "run_shell": object()})
- assert m._smalltalk_tool_override() == {}
+def test_smalltalk_override_never_empties_a_populated_surface() -> None:
+ # The core rule: a gate may narrow, never blank. A deployment whose only
+ # tools are non-spawn tools keeps all of them.
+ m = _mgr({"search_web": object(), "wiki-recall": object()})
+ assert set(m._smalltalk_tool_override()) == {"search_web", "wiki-recall"}