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>
This commit is contained in:
2026-07-14 12:47:49 +08:00
co-authored by Claude Opus 4.6
parent c049c3c1b1
commit ec261d57c2
59 changed files with 3801 additions and 122 deletions
+98 -17
View File
@@ -8,7 +8,6 @@ from core.errors import TaskFailedError
from core.models import Bounds, Scene, SceneElement
from runtime.ai_planner import AIPlanner
from runtime.context import TaskContext
from runtime.planner import PlannedStep
from runtime.planner_config import PlannerConfig
from runtime.tool_calling_client import ToolCallDecision
from runtime.tool_specs import ALL_TOOL_SPECS
@@ -44,7 +43,11 @@ def _scene() -> Scene:
return Scene(
width=10,
height=20,
elements=[SceneElement(id="send", type="button", text="Send", bounds=Bounds(1, 2, 3, 4))],
elements=[
SceneElement(
id="send", type="button", text="Send", bounds=Bounds(1, 2, 3, 4)
)
],
)
@@ -53,23 +56,25 @@ def _context() -> TaskContext:
def test_ai_planner_returns_single_planned_step_for_action_decision() -> None:
client = FakeToolCallingClient(ToolCallDecision(tool_name="tap", arguments={"x": 1, "y": 2}))
client = FakeToolCallingClient(
ToolCallDecision(tool_name="tap", arguments={"x": 1, "y": 2})
)
planner = AIPlanner(client=client)
steps = planner.plan(goal="send a message", scene=_scene(), context=_context())
assert steps == [
PlannedStep(
action="tap",
description="AI planner: tap({'x': 1, 'y': 2})",
args={"x": 1, "y": 2},
)
]
assert len(steps) == 1
step = steps[0]
assert step.action == "tap"
assert step.description == "AI planner: tap({'x': 1, 'y': 2})"
assert step.args == {"x": 1, "y": 2}
def test_ai_planner_finish_task_success_returns_empty_plan() -> None:
client = FakeToolCallingClient(
ToolCallDecision(tool_name="finish_task", arguments={"success": True, "reason": "done"})
ToolCallDecision(
tool_name="finish_task", arguments={"success": True, "reason": "done"}
)
)
planner = AIPlanner(client=client)
@@ -80,7 +85,10 @@ def test_ai_planner_finish_task_success_returns_empty_plan() -> None:
def test_ai_planner_finish_task_failure_raises_task_failed_error_with_reason() -> None:
client = FakeToolCallingClient(
ToolCallDecision(tool_name="finish_task", arguments={"success": False, "reason": "stuck on login"})
ToolCallDecision(
tool_name="finish_task",
arguments={"success": False, "reason": "stuck on login"},
)
)
planner = AIPlanner(client=client)
@@ -89,7 +97,9 @@ def test_ai_planner_finish_task_failure_raises_task_failed_error_with_reason() -
def test_ai_planner_finish_task_failure_without_reason_uses_default_message() -> None:
client = FakeToolCallingClient(ToolCallDecision(tool_name="finish_task", arguments={"success": False}))
client = FakeToolCallingClient(
ToolCallDecision(tool_name="finish_task", arguments={"success": False})
)
planner = AIPlanner(client=client)
with pytest.raises(TaskFailedError, match="task failed"):
@@ -97,20 +107,91 @@ def test_ai_planner_finish_task_failure_without_reason_uses_default_message() ->
def test_ai_planner_goal_reached_is_always_false() -> None:
client = FakeToolCallingClient(ToolCallDecision(tool_name="tap", arguments={"x": 1, "y": 2}))
client = FakeToolCallingClient(
ToolCallDecision(tool_name="tap", arguments={"x": 1, "y": 2})
)
planner = AIPlanner(client=client)
assert planner.goal_reached(goal="anything", scene=_scene(), context=_context()) is False
assert (
planner.goal_reached(goal="anything", scene=_scene(), context=_context())
is False
)
def test_ai_planner_forwards_tools_screenshot_and_timeout_to_client() -> None:
client = FakeToolCallingClient(ToolCallDecision(tool_name="tap", arguments={"x": 1, "y": 2}))
client = FakeToolCallingClient(
ToolCallDecision(tool_name="tap", arguments={"x": 1, "y": 2})
)
planner = AIPlanner(client=client, config=PlannerConfig(timeout=12.5))
planner.plan(goal="send a message", scene=_scene(), context=_context(), screenshot=b"fake-bytes")
planner.plan(
goal="send a message",
scene=_scene(),
context=_context(),
screenshot=b"fake-bytes",
)
call = client.calls[0]
assert call["tools"] == ALL_TOOL_SPECS
assert call["screenshot"] == b"fake-bytes"
assert call["timeout"] == 12.5
assert "send a message" in call["user_prompt"]
def test_ai_planner_populates_step_prompt_from_user_prompt() -> None:
"""PlannedStep.prompt should carry the actual user prompt sent to the LLM,
not the bare task goal."""
client = FakeToolCallingClient(
ToolCallDecision(tool_name="tap", arguments={"x": 1, "y": 2})
)
planner = AIPlanner(client=client)
steps = planner.plan(goal="send a message", scene=_scene(), context=_context())
assert len(steps) == 1
assert steps[0].prompt is not None
# The per-step prompt contains the goal but also scene JSON and instruction text
assert "send a message" in steps[0].prompt
assert "Current Scene (JSON)" in steps[0].prompt
assert "Call exactly one tool" in steps[0].prompt
def test_ai_planner_step_prompt_reflects_scene_changes() -> None:
"""Per-step prompts differ when the scene changes, proving they are not
just the repeated task goal."""
from runtime.context import TaskContext
client = FakeToolCallingClient(
ToolCallDecision(tool_name="tap", arguments={"x": 1, "y": 2})
)
planner = AIPlanner(client=client)
scene_a = Scene(
width=10,
height=20,
elements=[
SceneElement(
id="btn_a", type="button", text="Alpha", bounds=Bounds(1, 2, 3, 4)
)
],
)
scene_b = Scene(
width=10,
height=20,
elements=[
SceneElement(
id="btn_b", type="button", text="Beta", bounds=Bounds(5, 6, 7, 8)
)
],
)
steps_a = planner.plan(
goal="test", scene=scene_a, context=TaskContext(task_id="t", goal="test")
)
steps_b = planner.plan(
goal="test", scene=scene_b, context=TaskContext(task_id="t", goal="test")
)
assert steps_a[0].prompt != steps_b[0].prompt
assert "Alpha" in steps_a[0].prompt
assert "Beta" in steps_b[0].prompt