Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
"""TaskAutoApprover — unattended pre-authorization for scheduled-task tools.
A scheduled "agent" task pre-authorizes specific plugins at creation time by
toggling them with a ``write``/``full`` permission scope. While that task's
turn runs, an ask-tier tool call (e.g. "post a tweet", "send an email")
would normally block at ``ApprovalWorkflow.wait()`` because no human is
present to confirm. This bridge answers that gate programmatically — but
only for tools the task was explicitly granted, and only for that task's
own ``trace_id``.
Design (Option B from the integration analysis):
- The runner ``arm()``s the bridge with the turn's ``trace_id`` and the
set of pre-authorized plugin ids before running the turn, then
``disarm()``s in a finally.
- The bridge listens for ``ActionApprovalRequired``. On a match (same trace_id +
the proposed tool belongs to a granted plugin) it publishes
``ActionApproved`` straight onto the bus, which resolves the executor's
``wait()``. The full audit trail (Proposed -> Approved -> Executed) is
preserved — this answers the gate, it does not bypass it.
- An armed task explicitly denies consequential calls outside its write
grants, including read-only grants. Unarmed traces use the executor's
app-wide policy.
Concurrency-safe: a persistent ``ActionApprovalRequired`` subscriber plus a
``trace_id -> grant`` map, so several tasks can run at once without a
per-turn subscribe/unsubscribe race.
"""
from __future__ import annotations
from collections.abc import Iterable
from uuid import UUID
from dodaios.core.bus import EventBus
from dodaios.core.events import ActionApprovalRequired, ActionApproved, ActionDenied
class TaskAutoApprover:
"""Programmatically approves pre-authorized ask-tier tools per task turn."""
def __init__(self, bus: EventBus) -> None:
self._bus = bus
# trace_id -> (granted plugin ids, audit label)
self._active: dict[UUID, tuple[frozenset[str], str]] = {}
bus.subscribe(ActionApprovalRequired, self._on_approval_required)
def arm(self, trace_id: UUID, plugin_ids: Iterable[str], *, approved_by: str) -> None:
"""Pre-authorize ``plugin_ids`` for the turn identified by ``trace_id``.
An empty ``plugin_ids`` is a read-only task: it registers the trace
and denies consequential calls until disarmed.
"""
self._active[trace_id] = (frozenset(plugin_ids), approved_by)
def disarm(self, trace_id: UUID) -> None:
self._active.pop(trace_id, None)
async def _on_approval_required(self, event: ActionApprovalRequired) -> None:
ctx = self._active.get(event.trace_id)
if ctx is None:
return
granted, approved_by = ctx
if not self._tool_is_granted(event.tool_name, granted):
await self._bus.publish(
ActionDenied(
trace_id=event.trace_id,
tool_name=event.tool_name,
reason="Scheduled task has no write grant for this tool",
)
)
return
await self._bus.publish(
ActionApproved(
trace_id=event.trace_id,
tool_name=event.tool_name,
approved_by=approved_by,
)
)
@staticmethod
def _tool_is_granted(tool_name: str, granted: frozenset[str]) -> bool:
"""A tool is covered if its name (native tool) or its plugin prefix
(MCP tools are namespaced ``plugin/tool``) is in the grant set — the
same rule the brain's tool allowlist uses (``grant_matches``), so a
tool the turn can SEE is exactly a tool the grant can pre-authorize.
"""
from dodaios.tasks.grants import grant_matches # noqa: PLC0415
return any(grant_matches(grant, tool_name) for grant in granted)