2521690 2c7714268f feat: 补强 demo 后端任务指标与 edge-agent 执行骨架
- 新增 task_report 任务级聚合指标 task_metrics
- 补充创建任务幂等与失败路径/冲突测试
- 将后端测试基线提升到 20 passed
- 新增 edge-agent 初始化代码、启动脚本与打包脚本
- 新增 http_health_check、check_port、check_process、grep_log 执行器
- 补充 edge-agent 基础测试并提升基线到 10 passed
- 同步更新 backend README 与当前进度总结
2026-04-09 10:51:19 +08:00

44 lines
1.5 KiB
Python

from __future__ import annotations
from pathlib import Path
from typing import Any
class GrepLogExecutor:
def execute(self, params: dict[str, Any]) -> tuple[bool, str, dict[str, Any], dict[str, Any]]:
path = Path(str(params["path"]))
keyword = str(params["keyword"])
limit = int(params.get("limit", 100))
encoding = str(params.get("encoding", "utf-8"))
case_sensitive = bool(params.get("case_sensitive", False))
if not path.exists():
return False, f"log file not found: {path}", {}, {}
keyword_cmp = keyword if case_sensitive else keyword.lower()
matches: list[dict[str, Any]] = []
with path.open("r", encoding=encoding, errors="ignore") as handle:
for line_number, line in enumerate(handle, start=1):
text = line.rstrip("\n")
text_cmp = text if case_sensitive else text.lower()
if keyword_cmp in text_cmp:
matches.append({"line_number": line_number, "content": text})
if len(matches) >= limit:
break
success = len(matches) > 0
message = "keyword matched" if success else "keyword not found"
return (
success,
message,
{
"path": str(path),
"keyword": keyword,
"matched_count": len(matches),
},
{
"matches": matches,
},
)