zizi 061010ba1b 框架: 共享运行时装成可安装包,切断 Skill 之间的 sys.path 互指
被多个 Skill 或看板消费的连接、模型、嵌入、Claude 运行时与声音账入口
各只保留一份实现;Skill 只留 CLI/落库,看板只读 muse-db,门禁锁死跨域注入。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-20 00:45:20 +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()