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.

feat(workflows): give the workflow runner a harness and a tool surface

Harald00cf28403ae0
diff --git a/jarvis/ui/desktop_app.py b/jarvis/ui/desktop_app.py
index 6ac309d0ef..67794e5a29 100644
--- a/jarvis/ui/desktop_app.py
+++ b/jarvis/ui/desktop_app.py
@@ -2040,10 +2040,41 @@ class DesktopApp:
workflow_runner = WorkflowRunner(
store=workflow_store,
bus=server.bus,
- brain=None,
+ brain=None, # set later via attach_brain
tool_registry=None, # set later via attach_tools
tool_executor=None,
)
+ # Harness + tools (audit 2026-08-17, AU-03): the runner shipped
+ # with attach_harness_manager/attach_tools defined and NEVER
+ # called, so every harness_dispatch step died on "No
+ # HarnessManager available" and every tool_call on "Tool
+ # registry/executor not available" — a scheduled workflow could
+ # not touch the desktop or call a single tool. Same defect the
+ # TaskRunner had (deep-dive H-02, server.py:3224), fixed the same
+ # way. Both attachments are references, not work: the
+ # HarnessManager ctor only zeroes four fields (entry-point scan
+ # is lazy, on first dispatch), and BrainToolSurface resolves the
+ # brain per lookup — so the boot critical path stays untouched.
+ # A live surface rather than brain._tools, because
+ # BrainManager.refresh_tools() swaps that dict out on every
+ # CLI/MCP connect.
+ try:
+ from jarvis.harness.manager import HarnessManager
+ from jarvis.workflows.runner import BrainToolSurface
+
+ workflow_runner.attach_harness_manager(
+ HarnessManager(bus=server.bus)
+ )
+ tool_surface = BrainToolSurface(
+ lambda: getattr(server.app.state, "brain", None)
+ )
+ workflow_runner.attach_tools(tool_surface, tool_surface)
+ except Exception as exc: # noqa: BLE001 — degrade, don't kill workflows.
+ from loguru import logger as _wf_logger
+ _wf_logger.opt(exception=exc).warning(
+ "Workflow runner has no harness/tools — harness_dispatch "
+ "and tool_call steps will fail; the rest still runs."
+ )
workflow_scheduler = WorkflowScheduler(
store=workflow_store,
runner=workflow_runner,
@@ -2206,11 +2237,9 @@ class DesktopApp:
added = await ensure_seed_workflows(store)
_logger.info("Workflow store ready ({} new seed workflow(s)).",
added)
- # Attaching the tool registry would activate ``tool_call``
- # steps, but that requires a ToolExecutor adapter with
- # risk-tier integration. MVP: we run the runner without
- # tools — the seed workflows use brain_prompt/harness_dispatch/
- # speak, which don't need a ToolExecutor.
+ # Harness manager + tool surface are attached above, at runner
+ # construction — ``tool_call`` and ``harness_dispatch`` steps
+ # run through the brain's own risk-tier-aware ToolExecutor.
if scheduler is not None:
scheduler.start()
_logger.info("Workflow scheduler started.")
diff --git a/jarvis/workflows/runner.py b/jarvis/workflows/runner.py
index 33041480cd..7f1d17c517 100644
--- a/jarvis/workflows/runner.py
+++ b/jarvis/workflows/runner.py
@@ -23,6 +23,7 @@ import json
import logging
import re
import time
+from collections.abc import Callable
from typing import TYPE_CHECKING, Any, Protocol
from jarvis.core.bus import EventBus
@@ -65,6 +66,53 @@ class _ToolExecutorLike(Protocol):
async def execute(self, tool: Any, args: dict[str, Any], **kwargs: Any) -> Any: ...
+# ----------------------------------------------------------------------
+# Live view onto a BrainManager's tools
+# ----------------------------------------------------------------------
+
+class BrainToolSurface:
+ """Live view of the brain's tool registry AND its ToolExecutor.
+
+ Serves both ``attach_tools`` arguments — ``attach_tools(surface, surface)``
+ — because both sides hang off the same brain reference: ``brain._tools``
+ is the registry, ``brain._tool_executor_ref`` the executor.
+
+ Why a view instead of the dict itself: ``BrainManager.refresh_tools()``
+ REPLACES ``_tools`` wholesale, and it fires on every CLI/MCP server that
+ connects. A dict captured at wiring time would freeze the workflow runner
+ on the tool set from boot. Every lookup here re-reads the current one.
+
+ The brain reference is a callable, so the bootstrap can wire this up
+ before the (deferred) brain build has finished. Until it does, the
+ registry simply reads empty and a ``tool_call`` step fails with an honest
+ "tool not in registry" instead of silently doing nothing.
+ """
+
+ def __init__(self, brain_ref: Callable[[], Any]) -> None:
+ self._brain_ref = brain_ref
+
+ def _registry(self) -> dict[str, Any]:
+ brain = self._brain_ref()
+ return getattr(brain, "_tools", None) or {}
+
+ def __contains__(self, name: object) -> bool:
+ return name in self._registry()
+
+ def __getitem__(self, name: str) -> Any:
+ return self._registry()[name]
+
+ def get(self, name: str, default: Any = None) -> Any:
+ return self._registry().get(name, default)
+
+ async def execute(self, tool: Any, args: dict[str, Any], **kwargs: Any) -> Any:
+ executor = getattr(self._brain_ref(), "_tool_executor_ref", None)
+ if executor is None:
+ raise RuntimeError(
+ "No ToolExecutor available — the brain is still starting up"
+ )
+ return await executor.execute(tool, args, **kwargs)
+
+
# ----------------------------------------------------------------------
# Runner
# ----------------------------------------------------------------------
diff --git a/tests/unit/workflows/test_store_and_runner.py b/tests/unit/workflows/test_store_and_runner.py
index 9ad6ffdead..f25b4ce9a3 100644
--- a/tests/unit/workflows/test_store_and_runner.py
+++ b/tests/unit/workflows/test_store_and_runner.py
@@ -443,3 +443,154 @@ async def test_runner_telegram_posts_to_api(
assert body["chat_id"] == "987654"
assert body["text"] == "hallo von jarvis"
assert "TESTTOKEN" in captured_payloads[0]["url"]
+
+
+# ----------------------------------------------------------------------
+# Runtime dependency attachment (audit AU-03)
+# ----------------------------------------------------------------------
+#
+# The runner defined ``attach_harness_manager`` and ``attach_tools`` but the
+# bootstrap never called them, so EVERY ``tool_call`` step died on "Tool
+# registry/executor not available" and every ``harness_dispatch`` step on
+# "No HarnessManager available". These two tests pin the wiring down.
+
+
+class FakeTool:
+ """Minimal Tool stand-in — the executor is what calls it, not the runner."""
+
+ name = "note_down"
+
+ def __init__(self) -> None:
+ self.calls: list[dict] = []
+
+
+class FakeToolExecutor:
+ """Stands in for ToolExecutor — records the call, returns a ToolResult."""
+
+ def __init__(self) -> None:
+ self.calls: list[tuple[str, dict, str]] = []
+
+ async def execute(self, tool, args: dict, **kwargs): # noqa: ANN001
+ from jarvis.core.protocols import ToolResult
+
+ self.calls.append((tool.name, dict(args), kwargs.get("user_utterance", "")))
+ tool.calls.append(dict(args))
+ return ToolResult(success=True, output={"stored": args.get("text")})
+
+
+class FakeBrainWithTools:
+ """Brain stand-in exposing the two attributes BrainToolSurface reads."""
+
+ def __init__(self, tools: dict, executor: FakeToolExecutor) -> None:
+ self._tools = tools
+ self._executor = executor
+
+ @property
+ def _tool_executor_ref(self) -> FakeToolExecutor:
+ return self._executor
+
+
+async def test_runner_tool_call_reaches_the_tool_via_attached_brain_surface(
+ store: WorkflowStore,
+) -> None:
+ """``tool_call`` runs the tool once the brain surface is attached.
+
+ Also covers the reason the surface is a live view: the brain replaces
+ ``_tools`` wholesale on every ``refresh_tools()`` (each CLI/MCP connect),
+ so we swap the dict AFTER attaching and the runner must still find the
+ tool the brain holds *now*.
+ """
+ from jarvis.workflows.runner import BrainToolSurface
+ from jarvis.workflows.schema import ToolCallStep
+
+ executor = FakeToolExecutor()
+ brain = FakeBrainWithTools({}, executor)
+
+ bus = EventBus()
+ runner = WorkflowRunner(store=store, bus=bus)
+ surface = BrainToolSurface(lambda: brain)
+ runner.attach_tools(surface, surface)
+
+ # The tool only shows up after the attachment — as it does in the real
+ # bootstrap, where the brain builds in the background.
+ tool = FakeTool()
+ brain._tools = {"note_down": tool}
+
+ wf = WorkflowDef(
+ name="Tool-Call",
+ trigger=ManualTrigger(),
+ steps=(
+ BrainPromptStep(prompt="what is going on"),
+ ToolCallStep(tool_name="note_down", args={"text": "{{prev.output}}"}),
+ ),
+ )
+ # brain_prompt feeds the tool arg, so the template path is covered too.
+ runner.attach_brain(FakeBrain())
+ wid = await store.upsert_workflow(wf)
+ run_id = await runner.trigger(wid)
+
+ import asyncio
+ for _ in range(200):
+ await asyncio.sleep(0.02)
+ run = await store.get_run(run_id)
+ if run and run["state"] in ("completed", "failed"):
+ break
+
+ run = await store.get_run(run_id)
+ assert run["state"] == "completed", f"Runner failed: {run['error']}"
+ assert len(executor.calls) == 1
+ tool_name, args, utterance = executor.calls[0]
+ assert tool_name == "note_down"
+ assert args["text"].startswith("ECHO:")
+ assert utterance == "<workflow:note_down>"
+ assert tool.calls == [args]
+ assert "stored" in run["steps"][1]["output"]
+
+
+async def test_runner_harness_dispatch_reaches_the_attached_manager(
+ store: WorkflowStore,
+) -> None:
+ """``harness_dispatch`` streams from the manager instead of raising."""
+ from jarvis.core.protocols import HarnessResult
+
+ class FakeHarnessManager:
+ def __init__(self) -> None:
+ self.dispatched: list[tuple[str, str, bool]] = []
+
+ async def dispatch(self, name: str, task): # noqa: ANN001
+ self.dispatched.append((name, task.prompt, task.allow_computer_use))
+ yield HarnessResult(stdout="window focused")
+ yield HarnessResult(stdout="", exit_code=0, is_final=True)
+
+ manager = FakeHarnessManager()
+ bus = EventBus()
+ runner = WorkflowRunner(store=store, bus=bus)
+ runner.attach_harness_manager(manager)
+
+ wf = WorkflowDef(
+ name="Harness-Dispatch",
+ trigger=ManualTrigger(),
+ steps=(
+ HarnessDispatchStep(
+ harness="jarvis_agent",
+ prompt="bring the window to the front",
+ allow_computer_use=True,
+ ),
+ ),
+ )
+ wid = await store.upsert_workflow(wf)
+ run_id = await runner.trigger(wid)
+
+ import asyncio
+ for _ in range(200):
+ await asyncio.sleep(0.02)
+ run = await store.get_run(run_id)
+ if run and run["state"] in ("completed", "failed"):
+ break
+
+ run = await store.get_run(run_id)
+ assert run["state"] == "completed", f"Runner failed: {run['error']}"
+ assert manager.dispatched == [
+ ("jarvis_agent", "bring the window to the front", True)
+ ]
+ assert run["steps"][0]["output"] == "window focused"