refactor: task_logs, task_service, run CLI; remove platform_playwright

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-10 10:00:37 +08:00
parent 4730cd527d
commit f3f59278b4
14 changed files with 240 additions and 192 deletions

View File

@@ -1,10 +0,0 @@
"""后台自动化占位模块模板。"""
from __future__ import annotations
from typing import Any, Dict
async def publish(account: Dict[str, Any], article: Dict[str, Any], account_id: str) -> str:
_ = (account, article, account_id)
return "ERROR:NOT_IMPLEMENTED 请复制模板后将本文件改名为具体平台模块并实现后台自动化逻辑"

View File

@@ -1,4 +1,8 @@
"""兄弟技能 CLI 调用模板。"""
"""兄弟技能 CLI 调用模板。
通用工具:通过子进程调用同级其他 skill 的 main.py并解析 JSON 输出。
具体调用哪些兄弟技能,由具体业务 skill 决定(在 task_service.py 中按需 import 调用)。
"""
from __future__ import annotations
@@ -12,7 +16,19 @@ from util.logging_config import subprocess_env_with_trace
from util.runtime_paths import get_skills_root
def _call_json_script(script_path: str, args: List[str]) -> Optional[Dict[str, Any]]:
def call_sibling_json(skill_slug: str, args: List[str]) -> Optional[Dict[str, Any]]:
"""通用兄弟技能调用器。
Args:
skill_slug: 兄弟技能的 slug即同级目录名
args: 传给 main.py 的命令行参数列表。
Returns:
若兄弟技能输出可解析的 JSON 对象则返回 dict否则返回 None。
"""
script_path = os.path.join(get_skills_root(), skill_slug, "scripts", "main.py")
if not os.path.isfile(script_path):
return None
proc = subprocess.run(
[sys.executable, script_path, *args],
capture_output=True,
@@ -31,9 +47,19 @@ def _call_json_script(script_path: str, args: List[str]) -> Optional[Dict[str, A
return data if isinstance(data, dict) else None
def get_account_manager_main_path() -> str:
return os.path.join(get_skills_root(), "account-manager", "scripts", "main.py")
def get_sibling_main_path(skill_slug: str) -> str:
"""获取兄弟技能的 main.py 绝对路径。
使用示例(在你的 task_service.py 中):
from service.sibling_bridge import get_sibling_main_path, call_sibling_json
# 调用名为 account-manager 的兄弟技能:
result = call_sibling_json("account-manager", ["list", "--limit", "10"])
"""
return os.path.join(get_skills_root(), skill_slug, "scripts", "main.py")
def get_content_manager_main_path() -> str:
return os.path.join(get_skills_root(), "content-manager", "scripts", "main.py")
# ============================================================
# 复制本模板后,按需在你自己的 task_service.py 中调用上面的工具。
# 不要在本文件中硬编码具体兄弟技能函数(如 get_account_manager_main_path
# 那是发布类技能的特定需求,不属于通用模板。
# ============================================================

View File

@@ -1,4 +1,8 @@
"""发布编排、日志查询模板。"""
"""任务编排、日志查询模板。
通用业务编排层负责参数校验鉴权调用具体业务实现写入任务日志
复制后在 cmd_run 中实现真正的业务逻辑
"""
from __future__ import annotations
@@ -6,39 +10,47 @@ import json
import sys
from typing import Optional
from db import publish_logs_repository as plr
from db import task_logs_repository as tlr
from service.entitlement_service import check_entitlement
from util.constants import SKILL_SLUG, SKILL_VERSION
from util.timeutil import unix_to_iso
def cmd_publish(account_id: Optional[str] = None, article_id: Optional[str] = None) -> int:
_ = (account_id, article_id)
def cmd_run(target: Optional[str] = None, input_id: Optional[str] = None) -> int:
"""通用任务执行入口模板。复制后请实现真实业务逻辑。"""
_ = (target, input_id)
ok, reason = check_entitlement(SKILL_SLUG)
if not ok:
print(f"{reason}")
return 1
print("❌ 这是模板仓库,请复制后在 scripts/service/ 中实现真正的发布逻辑。")
print("❌ 这是模板仓库,请复制后在 scripts/service/task_service.py 中实现 cmd_run 的真实业务逻辑。")
return 1
def cmd_logs(limit: int = 10, status: Optional[str] = None, account_id: Optional[str] = None) -> int:
def cmd_logs(
limit: int = 10,
status: Optional[str] = None,
task_type: Optional[str] = None,
target_id: Optional[str] = None,
) -> int:
if limit <= 0:
limit = 10
rows = plr.list_publish_logs(limit, status, account_id)
rows = tlr.list_task_logs(limit, status, task_type, target_id)
if not rows:
print("暂无发布记录")
print("暂无任务日志")
return 0
sep_line = "_" * 39
for idx, r in enumerate(rows):
rid, aid, arid, title, st, err, cat, uat = r
rid, ttype, tid, iid, ititle, st, err, rsum, cat, uat = r
print(f"id{rid}")
print(f"account_id{aid or ''}")
print(f"article_id{arid}")
print(f"article_title{title or ''}")
print(f"task_type{ttype or ''}")
print(f"target_id{tid or ''}")
print(f"input_id{iid or ''}")
print(f"input_title{ititle or ''}")
print(f"status{st or ''}")
print(f"error_msg{err or ''}")
print(f"result_summary{rsum or ''}")
print(f"created_at{unix_to_iso(cat) or str(cat or '')}")
print(f"updated_at{unix_to_iso(uat) or str(uat or '')}")
if idx != len(rows) - 1:
@@ -51,20 +63,22 @@ def cmd_log_get(log_id: str) -> int:
if not str(log_id).isdigit():
print("❌ log_id 必须是数字")
return 1
row = plr.get_publish_log_by_id(int(log_id))
row = tlr.get_task_log_by_id(int(log_id))
if not row:
print("❌ 没有这条发布记录")
print("❌ 没有这条任务日志")
return 1
rid, aid, arid, title, st, err, cat, uat = row
rid, ttype, tid, iid, ititle, st, err, rsum, cat, uat = row
print(
json.dumps(
{
"id": int(rid),
"account_id": aid,
"article_id": int(arid),
"article_title": title,
"task_type": ttype,
"target_id": tid,
"input_id": iid,
"input_title": ititle,
"status": st,
"error_msg": err,
"result_summary": rsum,
"created_at": unix_to_iso(cat),
"updated_at": unix_to_iso(uat),
},