feat(app): features screen with tool switches and MCP servers; v2 drops host file and screen tools
- Settings `features` (weather, webSearch, meals) and `mcpServers` (name, command, args, env names, enabled), edited on the new 기능 screen. The tools of a feature that is off go into the brain's `disabled_tools`; only enabled MCP servers go into its `mcps`. - MCP environment values (API keys) live only in the encrypted secrets (`mcp:<server>:<NAME>`), shown as stored or not, masked in logs, removed with their server, and reach the worker only in `JARVIS_MCP_ENV`, which the brain takes out of its environment before giving each server its own. - `enabled_builtin_tools(cfg)` is the one list the router, toolSearchTool and the executor use, so a turned-off tool is neither offered nor run, also when the model names it. - The v2 brain never offers v1's `localFiles` (home folder read/write/delete) and `screenshot`: anyone in the voice or chat channels could ask for them. Screen viewing comes in M7. - The brain connects MCP servers on its own thread and logs each outcome without debug logging. - Stored secrets are masked in the log hub as soon as the data folder is found. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@ import sys
|
||||
import json
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, Optional
|
||||
from typing import Any, Dict, Optional, Tuple
|
||||
from dotenv import load_dotenv
|
||||
|
||||
|
||||
@@ -272,6 +272,9 @@ class Settings:
|
||||
# MCP Integration
|
||||
mcps: Dict[str, Any]
|
||||
|
||||
# Built-in tools that are neither offered nor run (v2 feature switches).
|
||||
disabled_tools: Tuple[str, ...] = ()
|
||||
|
||||
|
||||
|
||||
def default_config_path() -> Path:
|
||||
@@ -563,6 +566,8 @@ def get_default_config() -> Dict[str, Any]:
|
||||
|
||||
# MCP Integration (external servers Jarvis can use). No defaults.
|
||||
"mcps": {},
|
||||
# Built-in tools that are neither offered nor run.
|
||||
"disabled_tools": [],
|
||||
}
|
||||
|
||||
|
||||
@@ -766,6 +771,8 @@ def load_settings() -> Settings:
|
||||
raw_dict = merged.get("dictation_custom_dictionary", [])
|
||||
dictation_custom_dictionary = list(raw_dict) if isinstance(raw_dict, list) else []
|
||||
mcps = _ensure_dict(merged.get("mcps"))
|
||||
_disabled_raw = merged.get("disabled_tools") or []
|
||||
disabled_tools = tuple(str(t) for t in _disabled_raw) if isinstance(_disabled_raw, list) else ()
|
||||
whisper_min_confidence = float(merged.get("whisper_min_confidence", 0.4))
|
||||
whisper_no_speech_threshold = float(merged.get("whisper_no_speech_threshold", 0.5))
|
||||
whisper_min_audio_duration = float(merged.get("whisper_min_audio_duration", 0.3))
|
||||
@@ -913,4 +920,5 @@ def load_settings() -> Settings:
|
||||
|
||||
# MCP Integration
|
||||
mcps=mcps,
|
||||
disabled_tools=disabled_tools,
|
||||
)
|
||||
|
||||
@@ -17,7 +17,7 @@ from ..system_prompt import (
|
||||
reply_language_directive,
|
||||
tool_honesty_reminder,
|
||||
)
|
||||
from ..tools.registry import run_tool_with_retries, generate_tools_description, generate_tools_json_schema, BUILTIN_TOOLS
|
||||
from ..tools.registry import run_tool_with_retries, generate_tools_description, generate_tools_json_schema, BUILTIN_TOOLS, enabled_builtin_tools
|
||||
from ..tools.builtin.stop import STOP_SIGNAL
|
||||
from ..debug import debug_log
|
||||
from ..llm import chat_with_messages, extract_text_from_response, ToolsNotSupportedError
|
||||
@@ -1051,18 +1051,10 @@ def _recent_messages(cfg, dialogue_memory) -> list:
|
||||
return dialogue_memory.get_recent_messages()
|
||||
|
||||
|
||||
# The on-screen browser tools work only in screen-share mode (cfg.stream_browser); without it they
|
||||
# only refuse, and offered anyway the router picked them for unrelated asks (field run 2026-11-12,
|
||||
# v2: "피곤하다" routed to browseAndPlay).
|
||||
_SCREEN_SHARE_TOOLS = ("controlBrowser", "browseAndPlay", "setBroadcast")
|
||||
|
||||
|
||||
def _offered_builtins(cfg, chat_available: bool) -> dict:
|
||||
"""The built-in tools this turn can offer: chatChannels only with a chat backend
|
||||
(chat_channels.spec.md), the screen-share tools only in screen-share mode."""
|
||||
stream = getattr(cfg, "stream_browser", True)
|
||||
return {k: v for k, v in BUILTIN_TOOLS.items()
|
||||
if (k != "chatChannels" or chat_available) and (stream or k not in _SCREEN_SHARE_TOOLS)}
|
||||
"""The built-in tools this turn can offer: the enabled ones (``enabled_builtin_tools``), and
|
||||
chatChannels only with a chat backend (chat_channels.spec.md)."""
|
||||
return {k: v for k, v in enabled_builtin_tools(cfg).items() if k != "chatChannels" or chat_available}
|
||||
|
||||
|
||||
def _route_tools(cfg, redacted: str, builtin_tools: dict, mcp_tools: dict, recent_messages: list):
|
||||
|
||||
@@ -306,7 +306,7 @@ Turn 4: LLM → {content: "Here's a comprehensive comparison of the iPhone 15 mo
|
||||
- `memory_digest_enabled` (default `null` = auto-on for SMALL models ≤7B, off for LARGE) distils the combined diary + graph dump into a short relevance-filtered note via a cheap LLM pass before injecting into the system prompt. See **Memory Digest for Small Models** below.
|
||||
- `tool_result_digest_enabled` (default `null` = auto-on for SMALL models ≤7B) distils raw tool-result payloads (especially webSearch UNTRUSTED WEB EXTRACT blocks and fetch_web_page responses) into a short attributed fact note before appending as a tool-role message. Auto-on for small models mitigates large payloads (fetch_web_page truncates at 50,000 chars) blowing the 8192 num_ctx window. Set to `true` to force on, `false` to force off. See **Tool-Result Digest for Small Models** below.
|
||||
- Tools and MCP:
|
||||
- All builtin tools are always available; MCP servers added from `cfg.mcps`.
|
||||
- Every builtin tool is available except those in `cfg.disabled_tools` (default none) and, outside screen-share mode (`cfg.stream_browser`), the screen-share tools (`controlBrowser`, `browseAndPlay`, `setBroadcast`). `enabled_builtin_tools(cfg)` (`src/jarvis/tools/registry.py`) is the one list the router, the planner's catalogue, `toolSearchTool` and the executor use: a tool outside it is neither offered nor run, also when the model names it (the executor answers that the tool is turned off). MCP servers are added from `cfg.mcps`.
|
||||
- Agentic loop:
|
||||
- `agentic_max_turns` maximum turns in the agentic loop (default 8)
|
||||
- `tool_search_max_calls` (default 3) caps `toolSearchTool` invocations per reply. Extra calls return a tool-error nudging the model to decide with what is already available.
|
||||
|
||||
@@ -76,7 +76,7 @@ class ToolSearchTool(Tool):
|
||||
|
||||
cfg = context.cfg
|
||||
# Local imports to avoid circulars at module load time.
|
||||
from ..registry import BUILTIN_TOOLS, get_cached_mcp_tools
|
||||
from ..registry import BUILTIN_TOOLS, enabled_builtin_tools, get_cached_mcp_tools
|
||||
|
||||
try:
|
||||
strategy = ToolSelectionStrategy(getattr(cfg, "tool_selection_strategy", "llm"))
|
||||
@@ -92,7 +92,7 @@ class ToolSearchTool(Tool):
|
||||
try:
|
||||
selected = select_tools(
|
||||
query=query,
|
||||
builtin_tools=BUILTIN_TOOLS,
|
||||
builtin_tools=enabled_builtin_tools(cfg),
|
||||
mcp_tools=mcp_tools,
|
||||
strategy=strategy,
|
||||
llm_base_url=getattr(cfg, "ollama_base_url", ""),
|
||||
|
||||
@@ -16,7 +16,7 @@ Before each reply, `select_tools` runs once outside the loop and narrows the too
|
||||
allow-list = <router's picks> + stop + toolSearchTool
|
||||
```
|
||||
|
||||
When the model invokes `toolSearchTool(query=...)`, the tool re-runs the same routing logic (`select_tools` from `src/jarvis/tools/selection.py`) against the new query, and the returned tool names are merged into the loop's allow-list for subsequent turns. `stop` and `toolSearchTool` itself always remain in the allow-list.
|
||||
When the model invokes `toolSearchTool(query=...)`, the tool re-runs the same routing logic (`select_tools` from `src/jarvis/tools/selection.py`) against the new query over the enabled built-in tools (`enabled_builtin_tools(cfg)`: none in `cfg.disabled_tools`, no screen-share tools outside screen-share mode; reply.spec.md, "Tools and MCP") and the MCP tools, and the returned tool names are merged into the loop's allow-list for subsequent turns. `stop` and `toolSearchTool` itself always remain in the allow-list.
|
||||
|
||||
### Contract
|
||||
|
||||
|
||||
@@ -49,6 +49,23 @@ BUILTIN_TOOLS = {
|
||||
"chatChannels": ChatChannelsTool(),
|
||||
}
|
||||
|
||||
# The on-screen browser tools work only in screen-share mode (cfg.stream_browser); without it they
|
||||
# only refuse, and offered anyway the router picked them for unrelated asks (field run 2026-11-12,
|
||||
# v2: "피곤하다" routed to browseAndPlay).
|
||||
_SCREEN_SHARE_TOOLS = ("controlBrowser", "browseAndPlay", "setBroadcast")
|
||||
|
||||
|
||||
def enabled_builtin_tools(cfg) -> Dict[str, Any]:
|
||||
"""The built-in tools this configuration allows: none in ``cfg.disabled_tools``, and the
|
||||
screen-share tools only in screen-share mode. The router, toolSearchTool and the executor all
|
||||
use this, so a turned-off tool is neither offered nor run."""
|
||||
disabled = getattr(cfg, "disabled_tools", ())
|
||||
disabled = set(disabled) if isinstance(disabled, (list, tuple, set, frozenset)) else set()
|
||||
stream = getattr(cfg, "stream_browser", True)
|
||||
return {k: v for k, v in BUILTIN_TOOLS.items()
|
||||
if k not in disabled and (stream or k not in _SCREEN_SHARE_TOOLS)}
|
||||
|
||||
|
||||
# Global MCP tools cache
|
||||
_mcp_tools_cache: Dict[str, "ToolSpec"] = {}
|
||||
_mcp_tools_cache_lock = threading.Lock()
|
||||
@@ -356,6 +373,10 @@ def run_tool_with_retries(
|
||||
pass
|
||||
|
||||
# Check builtin tools first
|
||||
if name in BUILTIN_TOOLS and name not in enabled_builtin_tools(cfg):
|
||||
debug_log(f"turned-off tool requested: {name}", "tools")
|
||||
return ToolExecutionResult(success=False, reply_text=None,
|
||||
error_message=f"The {name} tool is turned off.")
|
||||
if name in BUILTIN_TOOLS:
|
||||
tool = BUILTIN_TOOLS[name]
|
||||
return tool.execute(
|
||||
|
||||
Reference in New Issue
Block a user