Files
agentic-mobile-control/packages/cloud-platform/cloud/schema.py
T
q792602257andClaude Opus 4.6 ec261d57c2 feat: surface task execution progress across Host Agent and Cloud
Host Agent now persists step-level execution detail locally (via a real
TaskMetadataStore/Timeline wired into TaskRunner) and reports a bounded
in-progress snapshot piggybacked on lease renewal. Cloud persists that
snapshot per active assignment and exposes it through the existing task
list/detail query path; Cloud Console renders it as a live badge. Host
Agent's local console gains authenticated, read-only task list and
detail/timeline pages (same-origin, server-rendered) with inlined
screenshots.

Also fixes a pre-existing gap in the shared Timeline: the actual
per-step LLM prompt is now recorded instead of the task goal, benefiting
both Runtime and Host Agent consoles. When a host uses the cloud planner
transport, each decide call's prompt and resulting tool decision are
durably logged in a new planner_decision_log table (with bounded
retention) and browsable from Cloud Console; direct-transport hosts
explicitly surface a "not reported" state.

Includes Alembic migrations 0008 (progress columns on scheduled_tasks)
and 0009 (planner_decision_log), bounded Host-Agent-local retention,
dual-backend repository parity, and Vitest + pytest coverage. Task 6.5
(manual end-to-end device verification) remains.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-07-14 12:47:49 +08:00

59 lines
1.8 KiB
Python

from __future__ import annotations
from pathlib import Path
from alembic import command
from alembic.config import Config
from alembic.runtime.migration import MigrationContext
from cloud.database import create_database_engine, normalize_database_url
HEAD_REVISION = "0009_planner_decision_log"
class SchemaVersionError(RuntimeError):
"""Raised when the database schema is not at the required revision."""
def upgrade_database(database_url: str, revision: str = "head") -> None:
command.upgrade(_alembic_config(database_url), revision)
def downgrade_database(database_url: str, revision: str = "base") -> None:
command.downgrade(_alembic_config(database_url), revision)
def current_revision(database_url: str) -> str | None:
engine = create_database_engine(database_url)
try:
with engine.connect() as connection:
context = MigrationContext.configure(connection)
return context.get_current_revision()
finally:
engine.dispose()
def is_schema_current(database_url: str) -> bool:
return current_revision(database_url) == HEAD_REVISION
def require_current_schema(database_url: str) -> None:
revision = current_revision(database_url)
if revision != HEAD_REVISION:
raise SchemaVersionError(
f"cloud database schema is {revision or 'unversioned'}; "
f"required revision is {HEAD_REVISION}"
)
def _alembic_config(database_url: str) -> Config:
migrations_dir = Path(__file__).resolve().parent / "migrations"
config = Config(str(migrations_dir / "alembic.ini"))
config.set_main_option("script_location", str(migrations_dir))
config.set_main_option(
"sqlalchemy.url",
normalize_database_url(database_url).replace("%", "%%"),
)
return config