Install and update artemis-use with task diagnostics and plugin guidance. Preserve cross-device file receipts, review canonical reports, guard stage transitions and reduce small history summaries. Improve exploration lifecycle, request recovery and browser live connections.
44 lines
1.8 KiB
Python
44 lines
1.8 KiB
Python
"""Apply evidence-cited Checker edits to one canonical Flash report."""
|
|
|
|
import re
|
|
|
|
from artemis.utils.notes import read_note_content, save_verified_note
|
|
|
|
|
|
def apply_report_review(directory, execution_report: dict, corrections) -> dict | None:
|
|
if not corrections:
|
|
return None
|
|
original = execution_report.get("explanation")
|
|
if not isinstance(original, str) or not original.strip():
|
|
return {"applied": False, "reason": "无可复核的报告正文"}
|
|
revised = original
|
|
for change in corrections:
|
|
if revised.count(change.original) != 1:
|
|
return {"applied": False, "reason": "复核引用未唯一匹配原文,保留原报告"}
|
|
revised = revised.replace(change.original, change.replacement, 1)
|
|
# Keep the executor's exact original for diagnosis; report edits do not
|
|
# alter device history, execution status, or the product test verdict.
|
|
before = save_verified_note(directory, "output_before_review", original)
|
|
receipt = save_verified_note(directory, "output", revised)
|
|
execution_report["explanation"] = revised
|
|
review = {
|
|
"applied": True,
|
|
"original": before,
|
|
"report": receipt,
|
|
"corrections": [change.model_dump() for change in corrections],
|
|
}
|
|
key = execution_report.get("report_note_key")
|
|
if (
|
|
isinstance(key, str)
|
|
and re.fullmatch(r"[\w-]{1,128}", key)
|
|
and key not in {"output", "output_before_review"}
|
|
):
|
|
try:
|
|
if read_note_content(directory, key) == original:
|
|
review["source_report"] = save_verified_note(directory, key, revised)
|
|
else:
|
|
review["source_report_error"] = "原报告已变更,未覆盖"
|
|
except (OSError, ValueError) as exc:
|
|
review["source_report_error"] = str(exc)
|
|
return review
|