feat(console): add Artemis Admin & Trace Console backend and management plane

Introduces the comprehensive developer/administrator control plane and trace
inspection console backend for the ARTEMIS mobile automation platform.

Key Features & Backend Architecture:
- Core Server & Modular Routing:
  * FastAPI modular architecture with dedicated routers for sessions, steps, tasks, media, stream, and replay.
  * Multi-layer repository pattern with SQLite persistence for sessions, traces, and step data.
- Task Control & Queue Management:
  * FIFO asynchronous task queue service with support for single/batch goal execution and profile selection (Flash / Pro).
  * Session lifecycle controls (run, pause, resume, stop, clear queue).
  * Startup orphan cleanup and automatic older replay archiving.
- Live Telemetry & IPC Communication:
  * High-performance IPC server for streaming real-time execution logs, agent thoughts, and tool invocations.
  * Server-Sent Events (SSE) /api/stream/{session_id} endpoint for live UI updates.
- Real-Time Device Streaming:
  * Live ADB screen capture and MJPEG frame generator (/api/stream/device-live).
  * Device connectivity and state inspection endpoint (/api/stream/device-state).
- Trace Inspection & Step Replay Engine:
  * Hierarchical call tree inspection, pre/post step screenshots, and action overlay metadata.
  * Isolated single-step replay manager (/api/replay) for interactive debugging and validation.
This commit is contained in:
Weilin Liu committed 2026-08-13 12:11:10 -07:00
1 parent 2fd70465e6
commit c1803fcb86
29 files changed
+8889

No files matched your search

+1
View File
@@ -0,0 +1 @@
# Copyright 2026 Google LLC
+68
View File
@@ -0,0 +1,68 @@
# 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.
import os
from pathlib import Path
import sys
# Automatically write ANTIGRAVITY_LS_ADDRESS to shared synchronization file on startup
# to allow decoupled background processes to communicate with Jetski
def init_ls_address():
ls_addr = os.environ.get("ANTIGRAVITY_LS_ADDRESS")
if ls_addr:
try:
from artemis.config import write_ls_address
write_ls_address(ls_addr)
except Exception as e:
sys.stderr.write(f"Failed to write .jetski_ls_address on startup: {e}\n")
# Compute real WORKSPACE_ROOT (find repo root containing pyproject.toml or artemis)
_current_p = Path(__file__).resolve().parent
while _current_p != _current_p.parent:
if (_current_p / "pyproject.toml").exists() or (_current_p / "artemis").is_dir():
WORKSPACE_ROOT = _current_p
break
_current_p = _current_p.parent
else:
WORKSPACE_ROOT = Path(__file__).resolve().parent.parent.parent.parent
_apps_dir = WORKSPACE_ROOT / "apps"
_admin_console_dir = _apps_dir / "admin_console"
_cloud_service_dir = _apps_dir / "cloud_service"
for _p in (str(WORKSPACE_ROOT), str(_apps_dir), str(_admin_console_dir), str(_cloud_service_dir)):
if _p not in sys.path:
sys.path.insert(0, _p)
# Try to import settings from artemis
try:
from artemis.config import settings
TRACES_PATH = Path(settings.TRACES_PATH)
DB_PATH = Path(settings.DATA_ENGINE_DB_PATH)
except ImportError:
# Fallback to default path if run outside project environment or imports fail
TRACES_PATH = WORKSPACE_ROOT / "traces"
DB_PATH = TRACES_PATH / "data_engine.db"
# Step Replay Directories (Stored within traces/replay to avoid workspace clutter)
REPLAY_BASE_DIR = TRACES_PATH / "replay"
TEST_DATA_DIR = REPLAY_BASE_DIR / "data"
TEST_OUTPUTS_DIR = REPLAY_BASE_DIR / "outputs"
IMAGES_DIR = TRACES_PATH / "images"
PAUSE_FILE = WORKSPACE_ROOT / ".artemis_paused"
+82
View File
@@ -0,0 +1,82 @@
# 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.
import asyncio
from collections.abc import Callable
from typing import Any
try:
from admin_console.core.config import PAUSE_FILE
except ImportError:
from apps.admin_console.core.config import PAUSE_FILE
class ServerState:
"""Encapsulates all runtime states of the debug server."""
def __init__(self):
self.ipc_subscribers: list[Callable[[str, Any], None]] = []
self.ipc_server: asyncio.Server | None = None
self.ipc_port: int | None = None
self.current_process: asyncio.subprocess.Process | None = None
self.current_goal: str | None = None
self.current_profile: str | None = None
self.active_connections: dict[str, dict[str, Any]] = {}
self.active_session_id: str | None = None
self.was_stopped_manually: bool = False
# FIFO Task queue
self.task_queue: asyncio.Queue = asyncio.Queue()
self.queue_tasks: list[dict[str, Any]] = []
self.worker_task: asyncio.Task | None = None
@property
def queue_goals(self) -> list[str]:
"""Backward compatibility helper for queue goals."""
return [t.get("goal", "") for t in self.queue_tasks if isinstance(t, dict)]
@queue_goals.setter
def queue_goals(self, val: list[Any]):
# Allow setting if legacy code updates it
pass
@property
def is_running(self) -> bool:
return self.current_process is not None and self.current_process.returncode is None
@property
def is_paused(self) -> bool:
return PAUSE_FILE.exists()
def add_subscriber(self, callback: Callable[[str, Any], None]):
if callback not in self.ipc_subscribers:
self.ipc_subscribers.append(callback)
def remove_subscriber(self, callback: Callable[[str, Any], None]):
if callback in self.ipc_subscribers:
self.ipc_subscribers.remove(callback)
def clear_queue(self):
while not self.task_queue.empty():
try:
self.task_queue.get_nowait()
self.task_queue.task_done()
except (asyncio.QueueEmpty, ValueError):
break
self.queue_tasks.clear()
# Global shared instance
state = ServerState()