feat: introduce MCP server, cross-platform runtime, and Showcase UI reorganization

- Showcase UI Reorganization:
  * Move web UI dashboard from root directory into apps/showcase_ui/ for cleaner project structure
  * Add 'artemis ui' CLI command (artemis/interfaces/cli/commands/ui.py) and launcher scripts for the interactive showcase console
- Standalone MCP Server & Notifiers (mcp_server/):
  * Implement dedicated MCP server package with mobile automation tools (device_state, inspect_trace, task_manager, task_runner)
  * Add multi-channel notifiers (AgentAPI, Desktop notifications, Webhooks, File output, and Composite routing)
  * Introduce background task runner and trace store for autonomous mobile execution monitoring
- Cross-Platform Runtime & Toolchain Support:
  * Add artemis/platform/ with OS-specific implementations for Linux, macOS (Darwin), and Windows
  * Add artemis/runtime/supervisor.py for resilient process and agent runtime supervision
  * Add artemis/toolchain/ with dependency resolution and SDK descriptors
  * Add cross-platform launcher scripts (start.sh, start.bat) and installer scripts (scripts/install_deps.*)
- Core Enhancements & Diagnostics:
  * Enhance coordinate normalization, OCR API fallback, and perception pipeline
  * Add credential validation (credentials_validator.py) and system diagnostics
  * Update bilingual documentation (README.md, README_CN.md) and architecture diagrams
- Test Suite Expansion:
  * Add integration tests for cloud gateway, remote ADB, and Artemis login
  * Add unit tests covering core diagnostics, platform detection, toolchain, credentials validator, optional OCR, and MCP tools
This commit is contained in:
somew1nd committed 2026-08-18 13:59:27 -07:00
1 parent 78e478f502
commit 9a5aaf99b7
249 files changed
+37226 -9339

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""MCP Server Utilities package."""
+172
View File
@@ -0,0 +1,172 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Device discovery, ADB resolution, and emulator management for MCP workflows."""
import os
import shutil
import subprocess
import sys
import time
def resolve_adb_path() -> str:
"""Resolves the absolute path to the adb binary across platforms."""
# 1. Check if adb is in PATH
which_adb = shutil.which("adb")
if which_adb:
return which_adb
# 2. Check ANDROID_HOME / ANDROID_SDK_ROOT
for env_var in ("ANDROID_HOME", "ANDROID_SDK_ROOT"):
sdk_root = os.getenv(env_var)
if sdk_root:
candidate = os.path.join(
sdk_root, "platform-tools", "adb.exe" if sys.platform == "win32" else "adb"
)
if os.path.exists(candidate):
return candidate
# 3. Check standard OS-specific SDK locations
candidates = []
if sys.platform == "win32":
local_appdata = os.getenv("LOCALAPPDATA", "")
if local_appdata:
candidates.append(
os.path.join(local_appdata, "Android", "Sdk", "platform-tools", "adb.exe")
)
elif sys.platform == "darwin":
candidates.extend(
[
os.path.expanduser("~/Library/Android/sdk/platform-tools/adb"),
"/opt/homebrew/bin/adb",
"/usr/local/bin/adb",
]
)
else: # Linux
candidates.extend(
[
"/usr/bin/adb",
os.path.expanduser("~/Android/Sdk/platform-tools/adb"),
"/usr/local/bin/adb",
]
)
for cand in candidates:
if os.path.exists(cand):
return cand
return "adb"
def resolve_emulator_path() -> str | None:
"""Resolves the path to the Android emulator executable."""
which_emulator = shutil.which("emulator")
if which_emulator:
return which_emulator
candidates = [
os.path.expanduser("~/Android/Sdk/emulator/emulator"),
os.path.expanduser("~/Library/Android/sdk/emulator/emulator"),
]
if sys.platform == "win32":
local_appdata = os.getenv("LOCALAPPDATA", "")
if local_appdata:
candidates.append(
os.path.join(local_appdata, "Android", "Sdk", "emulator", "emulator.exe")
)
for cand in candidates:
if os.path.exists(cand):
return cand
return None
def get_connected_devices(adb_path: str | None = None) -> list[str]:
"""Returns a list of connected and authorized Android device serials."""
adb = adb_path or resolve_adb_path()
try:
res = subprocess.run(
[adb, "devices"],
capture_output=True,
text=True,
timeout=5,
)
devices: list[str] = []
for line in res.stdout.splitlines():
line_str = line.strip()
if line_str and not line_str.startswith("List of devices"):
parts = line_str.split()
if len(parts) >= 2 and parts[1] == "device":
devices.append(parts[0])
return devices
except Exception:
return []
def is_emulator_running(adb_path: str | None = None) -> bool:
"""Checks if an Android emulator (e.g. emulator-5554) is running and accessible."""
adb = adb_path or resolve_adb_path()
devices = get_connected_devices(adb)
return any(d.startswith("emulator-") for d in devices)
def ensure_emulator(
avd_name: str = "AndroidWorldAvd",
adb_path: str | None = None,
emulator_path: str | None = None,
timeout_seconds: int = 90,
) -> bool:
"""Ensures an emulator is running. If not, boots the specified AVD in the background."""
adb = adb_path or resolve_adb_path()
if is_emulator_running(adb):
return True
emu_exe = emulator_path or resolve_emulator_path()
if not emu_exe or not os.path.exists(emu_exe):
return False
popen_kwargs = {"stdout": subprocess.DEVNULL, "stderr": subprocess.DEVNULL}
if sys.platform == "win32":
popen_kwargs["creationflags"] = (
subprocess.CREATE_NEW_PROCESS_GROUP | subprocess.DETACHED_PROCESS # type: ignore[attr-defined]
)
else:
popen_kwargs["start_new_session"] = True
try:
subprocess.Popen(
[emu_exe, "-avd", avd_name, "-no-snapshot", "-grpc", "8554"],
**popen_kwargs,
)
except Exception:
return False
start_time = time.time()
while time.time() - start_time < timeout_seconds:
try:
res = subprocess.run(
[adb, "-s", "emulator-5554", "shell", "getprop", "sys.boot_completed"],
capture_output=True,
text=True,
timeout=3,
)
if "1" in res.stdout:
time.sleep(2) # Stabilization
return True
except Exception:
pass
time.sleep(2)
return False
+61
View File
@@ -0,0 +1,61 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Environment and runtime discovery utilities for MCP."""
import os
import subprocess
import sys
from typing import Any
def get_project_root() -> str:
"""Returns the absolute path to the project root repository."""
try:
from artemis.config.paths import ROOT_DIR
return str(ROOT_DIR)
except Exception:
# mcp_server/utils/env_utils.py -> root is 3 levels up
return os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
def resolve_python_executable(project_root: str | None = None) -> str:
"""Resolves the preferred Python executable (.venv or current sys.executable)."""
root = project_root or get_project_root()
if sys.platform == "win32":
venv_python = os.path.join(root, ".venv", "Scripts", "python.exe")
else:
venv_python = os.path.join(root, ".venv", "bin", "python")
if os.path.exists(venv_python):
return venv_python
return sys.executable
def get_detached_process_kwargs() -> dict[str, Any]:
"""Returns kwargs for subprocess.Popen to run a fully detached background process cross-platform."""
kwargs: dict[str, Any] = {
"stdout": subprocess.DEVNULL,
"stderr": subprocess.DEVNULL,
}
if sys.platform == "win32":
kwargs["creationflags"] = (
subprocess.CREATE_NEW_PROCESS_GROUP | subprocess.DETACHED_PROCESS # type: ignore[attr-defined]
)
else:
kwargs["start_new_session"] = True
return kwargs
+108
View File
@@ -0,0 +1,108 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Trace storage and lifecycle management for MCP background automation tasks."""
import json
import os
import time
from typing import Any
try:
from artemis.config.paths import get_traces_dir
TRACES_DIR = str(get_traces_dir())
except Exception:
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
TRACES_DIR = os.path.join(PROJECT_ROOT, "traces")
def get_trace_dir(trace_id: str) -> str:
"""Returns the absolute path to the directory for a given trace_id."""
return os.path.join(TRACES_DIR, trace_id)
def get_status_path(trace_id: str) -> str:
"""Returns the absolute path to the status.json file for a given trace_id."""
return os.path.join(get_trace_dir(trace_id), "status.json")
def init_trace(
trace_id: str,
task_desc: str,
model: str,
conversation_id: str,
) -> dict[str, Any]:
"""Initializes the trace directory and creates the initial status.json file."""
trace_dir = get_trace_dir(trace_id)
os.makedirs(trace_dir, exist_ok=True)
status_data: dict[str, Any] = {
"trace_id": trace_id,
"task_desc": task_desc,
"model": model,
"conversation_id": conversation_id,
"status": "running",
"start_time": time.time(),
"end_time": None,
"error": None,
"result": None,
}
write_status(trace_id, status_data)
return status_data
def read_status(trace_id: str) -> dict[str, Any] | None:
"""Reads and returns the status.json for a given trace_id, or None if it doesn't exist."""
path = get_status_path(trace_id)
if not os.path.exists(path):
return None
try:
with open(path, encoding="utf-8") as f:
return json.load(f)
except Exception:
return None
def write_status(trace_id: str, data: dict[str, Any]) -> None:
"""Writes the given status dictionary to the trace's status.json."""
path = get_status_path(trace_id)
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, "w", encoding="utf-8") as f:
json.dump(data, f, indent=2, ensure_ascii=False)
def update_trace_status(
trace_id: str,
status: str,
error: str | None = None,
result: Any | None = None,
) -> dict[str, Any] | None:
"""Updates specific fields of the status.json for a given trace_id."""
data = read_status(trace_id)
if not data:
return None
data["status"] = status
if status in ("completed", "failed", "cancelled"):
data["end_time"] = time.time()
if error is not None:
data["error"] = error
if result is not None:
data["result"] = result
write_status(trace_id, data)
return data