zizi 091b66a9bb 重构: 收敛 Agent/Skill 运行时与创作质量闭环
将角色与 Skill 从 .claude 迁入 .agent,移除 Claude CLI 运行时并接入固定 Opus 角色 profile、完整 schema、预算 deadline、raw 与回执证据链。

同步拆分 Skill 职责、复利 lesson、Gate 回放、Dashboard 人审入口、数据库登记和机械门禁;候选设计正文不包含在本提交中。
2026-08-22 02:12:32 +08:00

62 lines
2.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""按 Canonical 章节/正文重算作品聚合指标。
用于修复历史接受通道未回写的 ``muse_content_work.chapter_count`` 与
``word_count``;正式接受路径已在 ``write_canonical.accept`` 内同步维护。
"""
import argparse
import json
from muse_db import connect
TENANT = 1
ACTOR = "metrics-reconcile"
def reconcile_work(work_id, *, updater=ACTOR, dry_run=False):
with connect() as conn:
try:
row = conn.execute(
"""SELECT COUNT(DISTINCT c.id)::bigint,
COALESCE(SUM(b.word_count),0)::bigint
FROM muse_content_chapter c
LEFT JOIN muse_content_block b
ON b.chapter_id=c.id AND b.deleted=false
WHERE c.work_id=%s AND c.deleted=false""",
(work_id,),
).fetchone()
updated = conn.execute(
"UPDATE muse_content_work SET chapter_count=%s,word_count=%s,"
"revision=revision+1,updater=%s WHERE id=%s AND deleted=false "
"RETURNING chapter_count,word_count,revision",
(row[0], row[1], updater, work_id),
).fetchone()
if not updated:
raise ValueError(f"作品不存在或已删除:work_id={work_id}")
result = {"work_id": work_id, "chapter_count": int(updated[0]),
"word_count": int(updated[1]), "revision": updated[2]}
if dry_run:
conn.rollback()
result["status"] = "dry_run_ok"
result["note"] = "试跑已回滚,未落库"
return result
conn.commit()
result["status"] = "reconciled"
return result
except Exception:
conn.rollback()
raise
def main():
parser = argparse.ArgumentParser(description="重算作品 Canonical 聚合指标")
parser.add_argument("--work-id", type=int, required=True)
parser.add_argument("--dry-run", action="store_true")
args = parser.parse_args()
print(json.dumps(reconcile_work(args.work_id, dry_run=args.dry_run), ensure_ascii=False))
if __name__ == "__main__":
main()