feat(runtime): capture step evidence in console
Tests / Test passed: 862

This commit is contained in:
2026-07-15 10:12:09 +08:00
parent 8d5b02e37f
commit ccde30e378
20 changed files with 594 additions and 53 deletions
+30 -7
View File
@@ -20,21 +20,36 @@ class ArtifactStore:
*,
task_id: str,
index: int,
screenshot: bytes | None,
before_screenshot: bytes | None,
after_screenshot: bytes | None,
record: dict[str, Any],
) -> dict[str, str | None]:
task_dir = self.task_dir(task_id)
task_dir.mkdir(parents=True, exist_ok=True)
stem = f"{index:03d}"
screenshot_path: Path | None = None
if screenshot is not None:
screenshot_path = task_dir / f"{stem}.png"
screenshot_path.write_bytes(screenshot)
before_screenshot_path: Path | None = None
after_screenshot_path: Path | None = None
if before_screenshot is not None:
before_screenshot_path = task_dir / f"{stem}-before.png"
before_screenshot_path.write_bytes(before_screenshot)
if after_screenshot is not None:
# Preserve the original filename as the compatibility alias for the
# screenshot captured after a step.
after_screenshot_path = task_dir / f"{stem}.png"
after_screenshot_path.write_bytes(after_screenshot)
json_path = task_dir / f"{stem}.json"
payload = {
**record,
"screenshot_path": str(screenshot_path) if screenshot_path else None,
"before_screenshot_path": (
str(before_screenshot_path) if before_screenshot_path else None
),
"after_screenshot_path": (
str(after_screenshot_path) if after_screenshot_path else None
),
"screenshot_path": (
str(after_screenshot_path) if after_screenshot_path else None
),
}
json_path.write_text(
json.dumps(_jsonable(payload), ensure_ascii=False, indent=2),
@@ -42,7 +57,15 @@ class ArtifactStore:
)
return {
"json_path": str(json_path),
"screenshot_path": str(screenshot_path) if screenshot_path else None,
"before_screenshot_path": (
str(before_screenshot_path) if before_screenshot_path else None
),
"after_screenshot_path": (
str(after_screenshot_path) if after_screenshot_path else None
),
"screenshot_path": (
str(after_screenshot_path) if after_screenshot_path else None
),
}
def read_steps(self, task_id: str) -> list[dict[str, Any]]:
+17 -2
View File
@@ -1,6 +1,6 @@
from __future__ import annotations
from dataclasses import dataclass
from dataclasses import dataclass, field
from datetime import datetime
from typing import Any
@@ -17,6 +17,9 @@ class TimelineRecord:
tool_call: dict[str, Any]
result: dict[str, Any]
timestamp: str
ocr_results: list[dict[str, Any]] = field(default_factory=list)
before_screenshot_path: str | None = None
after_screenshot_path: str | None = None
screenshot_path: str | None = None
@@ -33,20 +36,29 @@ class Timeline:
tool_call: dict[str, Any],
result: dict[str, Any],
screenshot: bytes | None = None,
before_screenshot: bytes | None = None,
after_screenshot: bytes | None = None,
ocr_results: list[dict[str, Any]] | None = None,
) -> TimelineRecord:
index = len(self.read(task_id)) + 1
resolved_after_screenshot = (
after_screenshot if after_screenshot is not None else screenshot
)
resolved_ocr_results = list(ocr_results or [])
record = {
"index": index,
"scene": scene,
"prompt": prompt,
"tool_call": tool_call,
"result": result,
"ocr_results": resolved_ocr_results,
"timestamp": datetime.now().astimezone().isoformat(),
}
paths = self.artifact_store.write_step(
task_id=task_id,
index=index,
screenshot=screenshot,
before_screenshot=before_screenshot,
after_screenshot=resolved_after_screenshot,
record=record,
)
return TimelineRecord(
@@ -56,6 +68,9 @@ class Timeline:
tool_call=tool_call,
result=result,
timestamp=record["timestamp"],
ocr_results=resolved_ocr_results,
before_screenshot_path=paths["before_screenshot_path"],
after_screenshot_path=paths["after_screenshot_path"],
screenshot_path=paths["screenshot_path"],
)