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

59 lines
2.1 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
"""embed-knowledge Skill CLI。库实现安装为 muse_embed,这里只做入参与出错的壳。"""
import pathlib
import sys
import click
import psycopg
import requests
from muse_db import connect
from muse_embed import EmbeddingOwnershipConflict, _run_bulk, _session, embed_texts
_EVIDENCE = pathlib.Path(__file__).resolve().parents[2] / "record-run-evidence" / "scripts"
if str(_EVIDENCE) not in sys.path:
sys.path.insert(0, str(_EVIDENCE))
@click.command()
@click.option("--work-id", type=int, help="限定作品/拆书批次;拆书默认按 source_id,章后抽卡按 draft.work_id")
@click.option("--source-type", type=str, help="来源类型;chapter_extract 按作品的 draft.work_id 筛选")
@click.option("--limit", type=click.IntRange(min=0), default=0, help="最多处理条数(0=不限)")
@click.option("--probe", help="自由文本试嵌(打印维度与前 5 维,不落库)")
def main(work_id, source_type, limit, probe):
sess = _session()
if probe:
vecs, bad = embed_texts(sess, [probe])
if bad:
raise click.ClickException("试嵌失败")
v = vecs[0]
click.echo(f"维度={len(v)} 前5维={[round(x, 4) for x in v[:5]]}")
return
with connect() as conn:
_run_bulk(conn, sess, work_id, limit, source_type)
from lesson_registry import propose_lesson_dedup # noqa: WPS433
run_id = f"embed-{work_id or 0}-{source_type or 'all'}-{limit}"
lesson = propose_lesson_dedup(
kind="win",
title="知识草稿嵌入批次完成",
detail={
"skill": "embed-knowledge",
"work_id": work_id,
"source_type": source_type,
"limit": limit,
},
work_id=work_id if isinstance(work_id, int) else None,
run_id=run_id,
creator="embed-knowledge",
)
click.echo(f"嵌入完成 lesson={lesson.get('lesson_id')}")
if __name__ == "__main__":
try:
main()
except (EmbeddingOwnershipConflict, psycopg.Error, requests.RequestException) as e:
click.echo(f"[错误] {type(e).__name__}: {e}", err=True)
sys.exit(1)