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
feat(agent-chat): the folder tools are Jarvis tools for the turn — through ToolExecutor, with risk tiers
rubenluetke10-beepe4f96a3c959f
diff --git a/jarvis/agent_chat/folder_tools.py b/jarvis/agent_chat/folder_tools.pynew file mode 100644index 0000000000..2e9fc00e98--- /dev/null+++ b/jarvis/agent_chat/folder_tools.py@@ -0,0 +1,110 @@+"""The chat's folder tools as Jarvis tools — one safety path, not two.++The typed chat has a working folder (the composer's folder chip), and in it+Jarvis gets hands a voice turn does not have: ``Read`` / ``Write`` / ``Edit``+/ ``Ls`` / ``Glob`` / ``Grep`` / ``RunCommand``, the file and shell tools of+:mod:`jarvis.agent_chat.tools`, scoped to that folder. On the Jarvis surface+they are not run by a private loop with its own approval card (the API+runner's way); they are wrapped as :class:`jarvis.core.protocols.Tool`+objects and merged into the brain turn's tool surface, so every call goes+through ``ToolExecutor`` like any other Jarvis tool — risk tiers, blacklist,+whitelist, the audit log and the approval workflow apply exactly as they do+on the voice path (AP-3: only the executor is authorized).++Tiers: the read-only four are ``safe``; ``Write``, ``Edit`` and+``RunCommand`` are ``ask``. What "ask" means for a given chat is decided by+its permission stance in :mod:`jarvis.agent_chat.approval_bridge` (an+``accept-edits`` chat waves ``Write``/``Edit`` through, a ``bypass`` chat+everything, an ``ask`` chat shows the card). The ``[safety.blacklist]``+patterns match ``"RunCommand <command>"`` and the bare command, so the+shipped blacklist protects the chat shell too — in every stance.++Names stay CamelCase, as the coding agents spell them: they do not collide+with any Jarvis tool (the router's set is hyphenated and lower-case), and+the tool-use loop resolves exact names first.+"""++from __future__ import annotations++from pathlib import Path+from typing import Any, Final++from jarvis.agent_chat import tools as folder+from jarvis.core.protocols import ExecutionContext, RiskTier, Tool, ToolResult++#: The stance ids of the Jarvis ladder this module reads (permissions.py).+PLAN_STANCE: Final[str] = "plan"++FOLDER_RISK_TIERS: Final[dict[str, RiskTier]] = {+ "Read": "safe",+ "Ls": "safe",+ "Glob": "safe",+ "Grep": "safe",+ "Write": "ask",+ "Edit": "ask",+ "RunCommand": "ask",+}+++class FolderTool:+ """One folder tool as a Jarvis ``Tool``: the spec from ``tools.py``, a cwd, a tier."""++ def __init__(self, spec: dict[str, Any], cwd: Path, risk_tier: RiskTier) -> None:+ self.name: str = str(spec["name"])+ self.description: str = str(spec.get("description") or self.name)+ self.schema: dict[str, Any] = dict(spec.get("input_schema") or {"type": "object"})+ self.risk_tier: RiskTier = risk_tier+ self._cwd = cwd++ @property+ def cwd(self) -> Path:+ return self._cwd++ async def execute(self, args: dict[str, Any], ctx: ExecutionContext) -> ToolResult:+ output, is_error = await folder.execute_tool(self.name, dict(args or {}), cwd=self._cwd)+ return ToolResult(+ success=not is_error,+ output=output,+ error=output if is_error else None,+ )++ def describe_args(self, args: dict[str, Any]) -> dict[str, str]:+ """The one-line summary the approval card and the timeline show."""+ summary = folder.summarize_call(self.name, dict(args or {}))+ return {"summary": summary} if summary else {}++ def __repr__(self) -> str: # pragma: no cover — debugging aid+ return f"FolderTool({self.name!r}, cwd={str(self._cwd)!r}, tier={self.risk_tier!r})"+++def folder_tools(cwd: Path, *, stance: str = "ask") -> dict[str, Tool]:+ """The folder tools for one chat turn, keyed by name.++ In ``plan`` only the read-only tools are offered at all — a plan-mode+ chat gets no writing hands, rather than hands that are refused later.+ """+ read_only = stance == PLAN_STANCE+ out: dict[str, Tool] = {}+ for spec in folder.TOOL_SPECS:+ name = str(spec["name"])+ if read_only and name not in folder.READ_ONLY_TOOLS:+ continue+ out[name] = FolderTool(spec, cwd, FOLDER_RISK_TIERS.get(name, "ask"))+ return out+++def plan_filter(tools: dict[str, Tool]) -> dict[str, Tool]:+ """Plan mode's tool surface: whatever only reads.++ Keeps a tool whose static tier is ``safe`` — reads, lookups, recall —+ and drops everything that acts (``monitor`` and up). A tool with a+ per-call tier hook (``risk_tier_for_args``) is treated by its static+ tier: a mixed tool whose default is a read stays, one whose default is+ an action goes.+ """+ return {+ name: tool for name, tool in tools.items() if getattr(tool, "risk_tier", None) == "safe"+ }+++__all__ = ["FOLDER_RISK_TIERS", "PLAN_STANCE", "FolderTool", "folder_tools", "plan_filter"]diff --git a/tests/unit/agent_chat/test_folder_tools.py b/tests/unit/agent_chat/test_folder_tools.pynew file mode 100644index 0000000000..8a2f92d757--- /dev/null+++ b/tests/unit/agent_chat/test_folder_tools.py@@ -0,0 +1,80 @@+"""The folder tools as Jarvis tools: tiers, plan mode, and the executor path."""++from __future__ import annotations++from pathlib import Path+from uuid import uuid4++from jarvis.agent_chat import folder_tools as ft+from jarvis.agent_chat.tools import READ_ONLY_TOOLS, TOOL_SPECS+from jarvis.core.protocols import ExecutionContext, ToolResult+++def _ctx() -> ExecutionContext:+ return ExecutionContext(trace_id=uuid4(), user_utterance="", config={}, memory_read=None)+++def test_every_folder_tool_has_a_tier_and_reads_are_safe():+ names = {str(spec["name"]) for spec in TOOL_SPECS}+ assert set(ft.FOLDER_RISK_TIERS) == names+ for name in READ_ONLY_TOOLS:+ assert ft.FOLDER_RISK_TIERS[name] == "safe"+ for name in ("Write", "Edit", "RunCommand"):+ assert ft.FOLDER_RISK_TIERS[name] == "ask"+++def test_folder_tools_are_tool_objects_scoped_to_the_folder(tmp_path: Path):+ tools = ft.folder_tools(tmp_path)+ assert set(tools) == {str(spec["name"]) for spec in TOOL_SPECS}+ read = tools["Read"]+ assert read.name == "Read" and read.risk_tier == "safe"+ assert isinstance(read.schema, dict) and read.schema.get("type") == "object"+ assert read.description+ assert read.cwd == tmp_path # type: ignore[attr-defined]+++async def test_execute_returns_a_tool_result_through_the_folder_code(tmp_path: Path):+ (tmp_path / "hello.txt").write_text("hi there\n", encoding="utf-8")+ tools = ft.folder_tools(tmp_path)+ result = await tools["Read"].execute({"file_path": "hello.txt"}, _ctx())+ assert isinstance(result, ToolResult)+ assert result.success and "hi there" in str(result.output)++ missing = await tools["Read"].execute({"file_path": "nope.txt"}, _ctx())+ assert not missing.success and missing.error++ written = await tools["Write"].execute({"file_path": "out.txt", "content": "x"}, _ctx())+ assert written.success and (tmp_path / "out.txt").read_text(encoding="utf-8") == "x"+++def test_describe_args_is_the_card_summary(tmp_path: Path):+ tools = ft.folder_tools(tmp_path)+ assert tools["Write"].describe_args({"file_path": "a.txt", "content": "x"}) == { # type: ignore[attr-defined]+ "summary": "a.txt"+ }+ assert tools["RunCommand"].describe_args({"command": "ls -la\nrm x"}) == { # type: ignore[attr-defined]+ "summary": "ls -la"+ }+ assert tools["Ls"].describe_args({}) == {"summary": "."} # type: ignore[attr-defined]+++def test_plan_stance_offers_only_the_reading_hands(tmp_path: Path):+ assert set(ft.folder_tools(tmp_path, stance="plan")) == set(READ_ONLY_TOOLS)+ assert set(ft.folder_tools(tmp_path, stance="accept-edits")) == set(ft.FOLDER_RISK_TIERS)+++def test_plan_filter_keeps_safe_tools_only(tmp_path: Path):+ class _Jarvis:+ def __init__(self, name: str, tier: str) -> None:+ self.name = name+ self.risk_tier = tier++ surface = {+ **ft.folder_tools(tmp_path),+ "wiki-recall": _Jarvis("wiki-recall", "safe"),+ "run-shell": _Jarvis("run-shell", "ask"),+ "open-app": _Jarvis("open-app", "monitor"),+ "no-tier": object(),+ }+ kept = ft.plan_filter(surface) # type: ignore[arg-type]+ assert set(kept) == set(READ_ONLY_TOOLS) | {"wiki-recall"}