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): make the subscription CLIs usable as writers, and never ship their debris

Ruben Lütke3272091ad76c
diff --git a/jarvis/agentic_ide/prompt_blueprint.py b/jarvis/agentic_ide/prompt_blueprint.py
index 9ae9ae4427..3a28115cf5 100644
--- a/jarvis/agentic_ide/prompt_blueprint.py
+++ b/jarvis/agentic_ide/prompt_blueprint.py
@@ -333,11 +333,34 @@ def looks_truncated(text: str) -> bool:
return not last.endswith(_SENTENCE_ENDINGS)
+def looks_like_brief(text: str) -> bool:
+ """True when ``text`` has the shape of a brief rather than of an accident.
+
+ The writer can be a subscription CLI, and a CLI answers on stdout whether it
+ understood the request or not. Measured live 2026-07-26: one returned
+ ``Error: invalid model selection (--model "..." --effort ""): ... requires
+ --effort`` — 146 characters, exit path unknown to us, and the composer
+ reported it as a successfully composed prompt. That string would then have
+ been typed at a coding agent as its task.
+
+ So the test is structural, not semantic: every brief the blueprint asks for
+ carries at least one markdown heading (``## Task`` at minimum), and no
+ single-line tool error does. Deliberately loose — this rejects debris, it
+ does not grade quality. A false positive costs one rougher prompt; a missed
+ one sends an agent off with a diagnostic string for a task.
+ """
+ body = (text or "").strip()
+ if not body:
+ return False
+ return any(line.lstrip().startswith("#") for line in body.splitlines())
+
+
__all__ = [
"MAX_BODY_CHARS",
"TARGET_MAX_CHARS",
"TARGET_MIN_CHARS",
"ends_on_reference",
+ "looks_like_brief",
"looks_truncated",
"render_fallback",
"system_prompt",
diff --git a/jarvis/agentic_ide/prompt_composer.py b/jarvis/agentic_ide/prompt_composer.py
index a5fd65c067..c413337106 100644
--- a/jarvis/agentic_ide/prompt_composer.py
+++ b/jarvis/agentic_ide/prompt_composer.py
@@ -393,6 +393,18 @@ async def compose(
if not composed:
return _deterministic("fallback", "composer returned nothing usable")
+ if not blueprint.looks_like_brief(composed):
+ # A subscription CLI writes its own errors to stdout, so "the process
+ # answered" is not the same as "a brief came back". Live 2026-07-26: one
+ # returned a one-line flag-validation error that shipped as the composed
+ # prompt. Anything without a single heading is debris, not a task.
+ logger.info(
+ "Agentic IDE prompt composer returned something that is not a brief "
+ "({} chars) — falling back",
+ len(composed),
+ )
+ return _deterministic("fallback", "composer output was not a brief")
+
if blueprint.looks_truncated(composed):
# Half a brief reads as a whole one, which is exactly what makes it
# dangerous: the agent starts on an instruction whose second half was
diff --git a/jarvis/plugins/brain/antigravity.py b/jarvis/plugins/brain/antigravity.py
index d0654eb128..3bab8649dd 100644
--- a/jarvis/plugins/brain/antigravity.py
+++ b/jarvis/plugins/brain/antigravity.py
@@ -135,19 +135,53 @@ def _build_cli_prompt(req: BrainRequest) -> str:
return "\n".join(lines)
-def _build_argv(cli: GoogleCli, prompt: str, model: str) -> list[str]:
+# Reasoning effort sent alongside an explicit ``--model`` on the agy CLI. The
+# binary REQUIRES the pair: passing a model without an effort aborts the run.
+_DEFAULT_AGY_EFFORT = "medium"
+# The levels agy accepts (``agy --help``: low|medium|high). A request asking to
+# disable thinking maps to the lowest level agy offers, since it has no "off".
+_AGY_EFFORTS = frozenset({"low", "medium", "high"})
+
+
+def _agy_effort(req: BrainRequest | None) -> str:
+ """Effort flag for an agy run, derived from the caller's own hint."""
+ requested = str(getattr(req, "reasoning_effort", "") or "").strip().lower()
+ if requested == "none":
+ return "low"
+ return requested if requested in _AGY_EFFORTS else _DEFAULT_AGY_EFFORT
+
+
+def _build_argv(
+ cli: GoogleCli, prompt: str, model: str, effort: str = _DEFAULT_AGY_EFFORT
+) -> list[str]:
"""Build the headless argv for the resolved CLI — flags differ per binary.
- * ``agy`` (Antigravity CLI 1.0.9): ``--print <prompt> --model <id>``. It has
- neither ``--approval-mode`` nor ``-o json`` (live ``agy --help`` 2026-06-20);
- output is plain text, which ``_parse_cli_answer`` handles via its raw
- fallback. A read-only conversational answer needs no tool permissions.
+ * ``agy`` (Antigravity CLI): ``--print <prompt> --model <id> --effort <level>``.
+ It has neither ``--approval-mode`` nor ``-o json`` (live ``agy --help``
+ 2026-06-20); output is plain text, which ``_parse_cli_answer`` handles via
+ its raw fallback. A read-only conversational answer needs no tool
+ permissions.
+
+ ``--effort`` is NOT optional next to ``--model``: a newer agy aborts with
+ ``invalid model selection (--model "..." --effort ""): ... requires
+ --effort`` and writes that line to stdout, where a caller happily reads it
+ as the answer (live 2026-07-26 — the Agentic IDE composer shipped it as a
+ composed prompt). Sending the pair is what keeps the model choice usable
+ at all on current agy.
* ``gemini`` (Gemini CLI): read-only ``--approval-mode plan`` + ``--skip-trust``
(so the throwaway workdir is trusted and the sandbox policy is not loaded —
forensic 2026-06-20) + ``-o json``.
"""
if cli.kind == "agy":
- return [*cli.argv_prefix, "--print", prompt, "--model", model]
+ return [
+ *cli.argv_prefix,
+ "--print",
+ prompt,
+ "--model",
+ model,
+ "--effort",
+ effort,
+ ]
return [
*cli.argv_prefix,
"-p",
@@ -236,7 +270,7 @@ class AntigravityBrain:
)
prompt = self._render_prompt(req)
- argv = _build_argv(cli, prompt, self._model)
+ argv = _build_argv(cli, prompt, self._model, _agy_effort(req))
# agy is a TUI tool: over a plain pipe it emits 0 bytes (the brain then
# sees "no answer"). It must be driven over a real pseudo-terminal. The
# Gemini CLI writes clean JSON to a pipe, so it keeps the fast path.
diff --git a/jarvis/plugins/brain/cli_prompt_context.py b/jarvis/plugins/brain/cli_prompt_context.py
index 3aca567414..d6b0fd2967 100644
--- a/jarvis/plugins/brain/cli_prompt_context.py
+++ b/jarvis/plugins/brain/cli_prompt_context.py
@@ -19,6 +19,15 @@ _NO_ACTIVE_PREFS_MARKER = "No active user preferences are currently set"
# user ..." auto line — start with this marker.
_REPLY_LANG_MARKER = "REPLY LANGUAGE"
+# Prepended to every structured CLI prompt. See render_structured_prompt for the
+# failure this prevents: an agent that reaches for a file it may not open in
+# headless mode returns a permissions notice instead of an answer.
+_NO_TOOLS_PREAMBLE = (
+ "Answer directly from the information in this message. Do not read files, "
+ "do not search the filesystem, do not run commands, and do not use any "
+ "tools — everything you need is already included below."
+)
+
def extract_standing_instructions_block(system_prompt: str | None) -> str:
"""Return only the user standing-instructions block from a system prompt."""
@@ -70,8 +79,22 @@ def render_structured_prompt(req: object) -> str:
broken to the wiki provider chain (live 2026-07-18: every antigravity
extraction died with "no JSON array found in response"). Structured mode
forwards the system contract and the user payload verbatim instead.
+
+ One line is added ahead of the contract, and it is not decoration. These
+ CLIs are autonomous AGENTS, while a structured caller is addressing them as
+ a model: given a payload full of file paths, the agent tries to go READ
+ those files, headless mode cannot prompt for the permission, and the run is
+ auto-denied. Measured live 2026-07-26 — an Agentic IDE brief came back as
+
+ jetski: no output produced — a tool required the "read_file" permission
+ that headless mode cannot prompt for, so it was auto-denied.
+
+ A structured caller has already gathered everything the answer needs (the
+ composer ships file outlines; the wiki extractor ships the text), so telling
+ the agent to work from what it was given costs nothing and is what makes the
+ difference between an answer and a permissions notice.
"""
- parts: list[str] = []
+ parts: list[str] = [_NO_TOOLS_PREAMBLE]
system = str(getattr(req, "system", "") or "").strip()
if system:
parts.append(system)
diff --git a/tests/unit/agentic_ide/test_composer_rejects_debris.py b/tests/unit/agentic_ide/test_composer_rejects_debris.py
new file mode 100644
index 0000000000..b89c1ee883
--- /dev/null
+++ b/tests/unit/agentic_ide/test_composer_rejects_debris.py
@@ -0,0 +1,101 @@
+"""A CLI writes its own errors to stdout, so "it answered" is not "a brief came".
+
+Live 2026-07-26: with the writer on a coding subscription, one CLI aborted on a
+flag-validation problem and printed
+
+ Error: invalid model selection (--model "..." --effort ""): ... requires --effort
+
+The composer reported ``composed_by="llm"`` and would have typed that line at a
+coding agent as its task. The structural check exists so debris can never again
+be mistaken for a composed prompt.
+"""
+from __future__ import annotations
+
+from types import SimpleNamespace
+
+import pytest
+
+from jarvis.agentic_ide import prompt_blueprint as blueprint
+from jarvis.agentic_ide import prompt_composer
+
+
+def test_a_cli_error_line_is_not_a_brief() -> None:
+ debris = (
+ 'Error: invalid model selection (--model "gemini-3.5-flash" --effort ""): '
+ "--model gemini-3.5-flash requires --effort (available: low, medium, high)"
+ )
+ assert blueprint.looks_like_brief(debris) is False
+
+
+ "debris",
+ [
+ "",
+ " ",
+ "command not found: claude",
+ "Traceback (most recent call last):\n File x, line 1\nRuntimeError: boom",
+ "I'm sorry, I cannot help with that.",
+ ],
+)
+def test_other_debris_is_rejected_too(debris: str) -> None:
+ assert blueprint.looks_like_brief(debris) is False
+
+
+ "brief",
+ [
+ "## Task\nDo the thing.",
+ "# Task\nDo the thing.\n\n## Done when\nTests pass.",
+ "Some lead-in line.\n\n## Task\nDo the thing.",
+ ],
+)
+def test_a_real_brief_survives(brief: str) -> None:
+ """The check rejects debris; it must not grade quality."""
+ assert blueprint.looks_like_brief(brief) is True
+
+
+class _Brain:
+ """Brain double that answers with whatever it was given."""
+
+ def __init__(self, answer: str) -> None:
+ self._answer = answer
+
+ async def complete(self, _req: object): # noqa: ANN202 - test double
+ from jarvis.core.protocols import BrainDelta
+
+ yield BrainDelta(content=self._answer)
+
+
+def _session(tmp_path) -> object: # noqa: ANN001 - pytest tmp_path
+ profile = SimpleNamespace(
+ instruction_files=[],
+ summary_lines=lambda: ["Test workspace"],
+ )
+ return SimpleNamespace(folder=str(tmp_path), profile=profile)
+
+
+async def test_composer_falls_back_when_the_writer_returns_debris(tmp_path) -> None: # noqa: ANN001
+ result = await prompt_composer.compose(
+ "have a look at the wake word please",
+ session=_session(tmp_path),
+ terminal_name="Kai",
+ brain=_Brain("Error: invalid model selection (--model x --effort '')"),
+ )
+
+ assert result.composed_by == "fallback"
+ assert "not a brief" in result.note
+ # The user still gets something usable, never the raw error.
+ assert "Error: invalid model selection" not in result.text
+ assert result.text.strip()
+
+
+async def test_composer_keeps_a_real_brief(tmp_path) -> None: # noqa: ANN001
+ result = await prompt_composer.compose(
+ "have a look at the wake word please",
+ session=_session(tmp_path),
+ terminal_name="Kai",
+ brain=_Brain("## Task\nInvestigate the wake word path.\n"),
+ )
+
+ assert result.composed_by == "llm"
+ assert "## Task" in result.text
diff --git a/tests/unit/plugins/brain/test_antigravity_effort_flag.py b/tests/unit/plugins/brain/test_antigravity_effort_flag.py
new file mode 100644
index 0000000000..518be04d58
--- /dev/null
+++ b/tests/unit/plugins/brain/test_antigravity_effort_flag.py
@@ -0,0 +1,68 @@
+"""agy requires --effort next to --model, and silently "answers" without it.
+
+Live 2026-07-26: a current agy aborted with
+
+ invalid model selection (--model "gemini-3.5-flash" --effort ""): ...
+
+and wrote that to stdout, where the caller read it as the model's answer. The
+pairing is therefore not cosmetic — without it the provider is unusable while
+looking like it works.
+"""
+from __future__ import annotations
+
+from types import SimpleNamespace
+
+import pytest
+
+from jarvis.core.protocols import BrainRequest
+from jarvis.plugins.brain import antigravity
+
+
+def _agy() -> SimpleNamespace:
+ return SimpleNamespace(kind="agy", argv_prefix=["agy"])
+
+
+def _gemini() -> SimpleNamespace:
+ return SimpleNamespace(kind="gemini", argv_prefix=["gemini"])
+
+
+def test_agy_always_gets_an_effort_beside_its_model() -> None:
+ argv = antigravity._build_argv(_agy(), "prompt", "gemini-3.5-flash")
+
+ assert "--effort" in argv
+ effort = argv[argv.index("--effort") + 1]
+ assert effort in {"low", "medium", "high"}
+ assert effort, "an empty effort is exactly what agy rejects"
+
+
+def test_the_gemini_cli_is_left_alone() -> None:
+ """Only agy demands the pair; adding it elsewhere would break that path."""
+ argv = antigravity._build_argv(_gemini(), "prompt", "gemini-3.5-flash")
+
+ assert "--effort" not in argv
+
+
+ ("requested", "expected"),
+ [
+ ("low", "low"),
+ ("medium", "medium"),
+ ("high", "high"),
+ # agy has no "off"; the caller's intent maps to the lowest it offers.
+ ("none", "low"),
+ # Anything unknown or unset falls back rather than passing debris on.
+ (None, "medium"),
+ ("nonsense", "medium"),
+ ],
+)
+def test_effort_follows_the_caller_and_never_goes_empty(
+ requested: str | None, expected: str
+) -> None:
+ req = BrainRequest(messages=(), reasoning_effort=requested) # type: ignore[arg-type]
+
+ assert antigravity._agy_effort(req) == expected
+
+
+def test_a_request_without_the_field_still_yields_a_valid_effort() -> None:
+ assert antigravity._agy_effort(None) == "medium"
+ assert antigravity._agy_effort(SimpleNamespace()) == "medium"
diff --git a/tests/unit/plugins/brain/test_cli_prompt_context.py b/tests/unit/plugins/brain/test_cli_prompt_context.py
index e2152ab96d..82ebab295b 100644
--- a/tests/unit/plugins/brain/test_cli_prompt_context.py
+++ b/tests/unit/plugins/brain/test_cli_prompt_context.py
@@ -56,9 +56,18 @@ def test_render_structured_prompt_keeps_system_and_user_verbatim() -> None:
),
)
prompt = render_structured_prompt(req)
- assert prompt.startswith("Return ONLY a single JSON array.")
+ assert "Return ONLY a single JSON array." in prompt
assert "Source content." in prompt
assert "never included" not in prompt # assistant turns are not payload
+ # A no-tools preamble frames the call, but the caller's contract must stay
+ # AFTER it: these models weight the end of a prompt most heavily, and the
+ # contract is the instruction that has to win.
+ assert prompt.index("Do not read files") < prompt.index(
+ "Return ONLY a single JSON array."
+ )
+ assert prompt.index("Return ONLY a single JSON array.") < prompt.index(
+ "Source content."
+ )
def test_extracts_trailing_mandatory_directive() -> None: