feat: screen viewing, Jarvis sees the whole screen, a monitor or a window for registered people

- screenView tool (screen_view.spec.md): whole screen, monitor by number, window by part of its
  title or program, or the list of monitors and windows; fast, normal or detailed pictures.
- The app captures with Windows Graphics Capture (app/src/screen.rs, admin.spec.md "Screen
  viewing"), decides for the asker (only people registered for PC control), never picks, lists
  or shows excluded programs (pcControl.screenExclude, password managers by default), refuses
  minimised windows and black pictures, and records screen.view in the activity log.
- Pictures ride on the tool message (ToolExecutionResult.images); llm.py sends them to
  OpenAI-compatible servers as image parts after the tool messages. They stay in that reply only:
  not in the tool carryover, logs or prompt dumps.
- The LLM reads pictures only when screen viewing is available (--vision gpu normally, cpu in a
  game), measured apart for the placement; otherwise screenView is a disabled tool.
- Worker: screen_action / screen_action_result, 4 MiB messages.
- Eval evals/test_screen_view_tool.py; Windows check tests/screen_windows.rs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-15 17:02:59 +09:00
parent bd7b69d4f4
commit 53bccb620d
39 changed files with 1844 additions and 68 deletions

View File

@@ -1067,15 +1067,23 @@ def _recent_messages(cfg, dialogue_memory) -> list:
return dialogue_memory.get_recent_messages()
def _attach_images(message: dict, result) -> None:
"""Put a tool result's pictures on its message for the next LLM call (reply.spec.md,
"Pictures from tools")."""
images = getattr(result, "images", None)
if isinstance(images, list) and images and all(isinstance(i, str) for i in images):
message["images"] = list(images)
def _offered_builtins(cfg, chat_available: bool, schedule_available: bool = False,
notes_available: bool = False) -> dict:
notes_available: bool = False, screen_available: bool = False) -> dict:
"""The built-in tools this turn can offer: the enabled ones (``enabled_builtin_tools``),
chatChannels only with a chat backend (chat_channels.spec.md), schedule only with a
schedule backend (schedule.spec.md) and personalNotes only with a notes backend
(personal_notes.spec.md)."""
schedule backend (schedule.spec.md), personalNotes only with a notes backend
(personal_notes.spec.md) and screenView only with a screen backend (screen_view.spec.md)."""
return {k: v for k, v in enabled_builtin_tools(cfg).items()
if (k != "chatChannels" or chat_available) and (k != "schedule" or schedule_available)
and (k != "personalNotes" or notes_available)}
and (k != "personalNotes" or notes_available) and (k != "screenView" or screen_available)}
def _route_tools(cfg, redacted: str, builtin_tools: dict, mcp_tools: dict, recent_messages: list):
@@ -1099,13 +1107,15 @@ def _route_tools(cfg, redacted: str, builtin_tools: dict, mcp_tools: dict, recen
def prepare_intent(cfg, text: str, dialogue_memory, chat_available: bool,
schedule_available: bool = False, notes_available: bool = False) -> Optional[list]:
schedule_available: bool = False, notes_available: bool = False,
screen_available: bool = False) -> Optional[list]:
"""Run the intent judge (the tool router) for ``text`` ahead of its reply (v2: on a partial
transcript while the user still speaks), with the inputs ``run_reply_engine(intent_judge=True)``
would give it, so its pick can be passed back as ``prepared_tools``. None when the router gave
up (its fall-open to the whole catalogue is not a pick). ``chat_available``: the reply will
have a chat backend (the chatChannels tool is in the catalogue); ``schedule_available``: a
schedule backend (the schedule tool is); ``notes_available``: a notes backend."""
schedule backend (the schedule tool is); ``notes_available``: a notes backend;
``screen_available``: a screen backend."""
mcp_tools: dict = {}
if getattr(cfg, "mcps", {}):
try:
@@ -1113,7 +1123,7 @@ def prepare_intent(cfg, text: str, dialogue_memory, chat_available: bool,
mcp_tools = get_cached_mcp_tools()
except Exception:
mcp_tools = {}
builtin = _offered_builtins(cfg, chat_available, schedule_available, notes_available)
builtin = _offered_builtins(cfg, chat_available, schedule_available, notes_available, screen_available)
try:
routed = _route_tools(cfg, redact(text), builtin, mcp_tools, _recent_messages(cfg, dialogue_memory))
except Exception as exc: # pragma: no cover — defensive
@@ -1254,10 +1264,11 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
# needed. Both cases are preserved for the engine to distinguish.
# chatChannels exists only when the v2 brain gave this turn a chat backend
# (chat_channels.spec.md); otherwise it is not in the catalogue at all.
from .turn_state import get_chat as _get_chat, get_schedule as _get_schedule, get_notes as _get_notes
from .turn_state import get_chat as _get_chat, get_schedule as _get_schedule, get_notes as _get_notes, \
get_screen as _get_screen
_chat_backend = _get_chat()
_builtin_tools = _offered_builtins(cfg, _chat_backend is not None, _get_schedule() is not None,
_get_notes() is not None)
_get_notes() is not None, _get_screen() is not None)
_all_builtin_names = list(_builtin_tools.keys())
_all_mcp_names = list(mcp_tools.keys())
_full_catalog_names = _all_builtin_names + _all_mcp_names
@@ -2427,6 +2438,7 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
"content": f"{_plan_text}{_plan_hint}",
"tool_failed": not _plan_result.success,
})
_attach_images(messages[-1], _plan_result)
recent_tool_signatures.append(_cand_sig)
if len(recent_tool_signatures) > 5:
recent_tool_signatures = (
@@ -2892,7 +2904,9 @@ def run_reply_engine(db: "Database", cfg, tts: Optional[Any],
"content": effective_result,
"tool_failed": not result.success,
})
debug_log(f" ✅ tool result appended ({len(effective_result)} chars)", "planning")
_attach_images(messages[-1], result)
debug_log(f" ✅ tool result appended ({len(effective_result)} chars, "
f"{len(messages[-1].get('images') or [])} picture(s))", "planning")
# Note: We don't add a guidance system message here because adding system messages
# after the conversation starts breaks native tool calling in models like Llama 3.2.