AI 漫剧流水线技能完整落地:文件驱动、可校验、单镜可重做。 七阶段:基线资产 → 策划叙事 → 分镜中枢 → 配音先行 → 出图/出视频 → 缝合 → 审片归档。 - scripts/: manju.py 编排、submit_t2i/submit_i2v 提交、cleanup_comfyui 清理 - assets/comfyui-manju-cleanup/: ComfyUI 清理扩展,归属校验 fail-closed - references/: models.md 模型节点图全表、workflow/director/storyboard/pitfalls - .gitignore: 排除 __pycache__ 与运行产物
276 lines
8.9 KiB
Python
276 lines
8.9 KiB
Python
#!/usr/bin/env python3
|
||
"""manju 工作空间命令行入口 —— 零第三方依赖。
|
||
|
||
setup 初始化工作空间(建目录/配置/复制脚本,仅从技能包运行)
|
||
validate <30_shots.json> 校验分镜清单(ERROR 退出 1)
|
||
hash <text> 计算提示词 sha256 前 8 位
|
||
hash-file <path> 计算提示词文件 sha256 前 8 位
|
||
manifest <30_shots.json> 生成/更新 50_manifest.json,保留已有 attempts
|
||
init <EPxx> 新建一集目录骨架
|
||
|
||
用法:先在工作空间根用技能包的 manju.py 运行 setup,之后一律用 tools/manju.py。
|
||
"""
|
||
|
||
import json
|
||
import sys
|
||
from datetime import datetime
|
||
from pathlib import Path
|
||
|
||
def _find_root():
|
||
"""工作空间根:MANJU_ROOT > cwd 向上找 config/pipeline.json > 脚本上级。"""
|
||
import os as _os
|
||
env = _os.environ.get("MANJU_ROOT")
|
||
if env:
|
||
return Path(env).expanduser().absolute()
|
||
d = Path.cwd().absolute()
|
||
for p in (d, *d.parents):
|
||
if (p / "config" / "pipeline.json").is_file():
|
||
return p
|
||
return Path(__file__).absolute().parent.parent
|
||
|
||
|
||
ROOT = _find_root()
|
||
sys.path.insert(0, str(Path(__file__).absolute().parent))
|
||
from validate_shots import validate, shot_hash # noqa: E402
|
||
|
||
|
||
def cmd_validate(args):
|
||
if len(args) != 1:
|
||
return "用法: xv.py validate <30_shots.json>"
|
||
errors, warns, summary = validate(args[0])
|
||
print(f"[{summary.get('episode', '?')}] {summary['shots']} 镜 / {summary['total']}s "
|
||
f"(目标 {summary['target']}s) ERROR={summary['errors']} WARN={summary['warns']}")
|
||
for item in errors:
|
||
print(f" ERROR {item}")
|
||
for item in warns:
|
||
print(f" WARN {item}")
|
||
if not errors:
|
||
print(" 校验通过(WARN 需在生成前逐条确认)")
|
||
return 1 if errors else 0
|
||
|
||
|
||
def cmd_hash(args):
|
||
if not args:
|
||
return "用法: xv.py hash <提示词原文>"
|
||
print(shot_hash(" ".join(args)))
|
||
return 0
|
||
|
||
|
||
def cmd_hash_file(args):
|
||
if len(args) != 1:
|
||
return "用法: xv.py hash-file <path>"
|
||
print(shot_hash(Path(args[0]).read_text(encoding="utf-8")))
|
||
return 0
|
||
|
||
|
||
def cmd_manifest(args):
|
||
if len(args) != 1:
|
||
return "用法: xv.py manifest <30_shots.json>"
|
||
src = Path(args[0]).resolve()
|
||
data = json.loads(src.read_text(encoding="utf-8"))
|
||
out = src.parent / "50_manifest.json"
|
||
old = {}
|
||
if out.exists():
|
||
try:
|
||
old = {r["shotId"]: r for r in json.loads(out.read_text(encoding="utf-8")).get("shots", [])}
|
||
except Exception as exc:
|
||
return f"已有 manifest 无法解析,未覆盖:{exc}"
|
||
|
||
records = []
|
||
for s in data["shots"]:
|
||
sid = s["shotId"]
|
||
rec = old.get(sid, {"shotId": sid, "attempts": []})
|
||
prompt_hash = s.get("promptHash") or ""
|
||
pf = s.get("promptFile")
|
||
if pf:
|
||
fp = src.parent / pf
|
||
if fp.exists():
|
||
actual = shot_hash(fp.read_text(encoding="utf-8"))
|
||
if prompt_hash and prompt_hash != actual:
|
||
return f"{sid}: promptHash 与 {pf} 不符,请先修正再生成 manifest"
|
||
prompt_hash = actual
|
||
rec.update({
|
||
"promptFile": pf or "",
|
||
"promptHash": prompt_hash,
|
||
"status": s.get("status", "planned"),
|
||
"duration": s.get("duration"),
|
||
"refs": s.get("refs", []),
|
||
})
|
||
rec.setdefault("attempts", [])
|
||
records.append(rec)
|
||
|
||
doc = {
|
||
"episode": data.get("episode"),
|
||
"source": "30_shots.json",
|
||
"updatedAt": datetime.now().isoformat(timespec="seconds"),
|
||
"note": "attempts 只追加不覆盖:每次提交记录提示词快照、完整参数、参考、返回与实际文件",
|
||
"shots": records,
|
||
}
|
||
out.write_text(json.dumps(doc, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
||
print(f"已写入 {out.relative_to(ROOT)}({len(records)} 镜,保留历史 attempts)")
|
||
return 0
|
||
|
||
|
||
BRIEF = """# EP{ep} 任务卡
|
||
|
||
项目:
|
||
时长:
|
||
镜头数:
|
||
核心冲突:
|
||
角色:
|
||
画风:
|
||
禁忌:(按本项目 policy 清单填写,必填)
|
||
|
||
> 禁忌栏必写。重编不是缩写;每镜必须能回溯到 10_events.md 的 E##。
|
||
"""
|
||
|
||
EVENTS = """# EP{ep} 源节拍账本
|
||
|
||
一行一个 E##,30–60 字,只写影响主线的动作,不复述整段对话。
|
||
每个会改变剧情状态的提示词句子都必须映射回这里的 E##。
|
||
|
||
- E01|待填写:谁做了什么 → 造成什么结果 → 情绪 → 预估秒数
|
||
"""
|
||
|
||
SCRIPT = """# EP{ep} 剧本 / 旁白
|
||
|
||
待填写。旁白全文逐字写入 `30_shots.json` 的 `line`,配音阶段按实测时长回填 `duration`。
|
||
"""
|
||
|
||
SHOTS = """{{
|
||
"episode": "{ep}",
|
||
"brief": "00_brief.md",
|
||
"targetDuration": 5.06,
|
||
"tolerance": 3.0,
|
||
"shots": [
|
||
{{
|
||
"shotId": "S01",
|
||
"eventIds": ["E01"],
|
||
"scene": "待填写",
|
||
"shotType": "中景",
|
||
"subject": "待填写",
|
||
"angle": "正面",
|
||
"visual": "待填写:可见画面,不写抽象情绪",
|
||
"line": "",
|
||
"duration": 5.06,
|
||
"characters": [],
|
||
"refs": [],
|
||
"motion": "轻微呼吸 + 单一缓推",
|
||
"promptFile": "40_prompts/S01.md",
|
||
"continuity": {{ "relation": "reset", "initialState": "待填写:本段绝对初始状态" }},
|
||
"status": "planned"
|
||
}}
|
||
]
|
||
}}
|
||
"""
|
||
|
||
PROMPT = """S01|E01|时长:5.06s|模型:wan2.2-i2v-a14b|432x768 / 81帧 / 16fps / 4-step
|
||
|
||
[首帧锚]
|
||
待填写
|
||
|
||
[首帧锁定]
|
||
待填写
|
||
|
||
[画面]
|
||
待填写
|
||
|
||
[轻运动]
|
||
待填写
|
||
|
||
[正向锁]
|
||
待填写
|
||
|
||
[文字锁]
|
||
无字幕、无额外屏幕文字、无后期叠字、无水印;实体文字保持参考资产,不新增、不改写、不重绘
|
||
|
||
[Avoid]
|
||
待填写
|
||
"""
|
||
|
||
|
||
def cmd_setup(args):
|
||
"""在工作空间根建骨架;必须从技能包目录的 manju.py 运行(需要 assets/)。"""
|
||
if args:
|
||
return "用法: manju.py setup(在工作空间根目录运行,无参数)"
|
||
root = Path.cwd().absolute()
|
||
skill = Path(__file__).absolute().parent.parent
|
||
assets = skill / "assets"
|
||
if not (assets / "config.template.json").is_file():
|
||
return ("找不到技能包 assets/config.template.json;"
|
||
"请用技能包内的 scripts/manju.py 运行 setup")
|
||
cfg = root / "config" / "pipeline.json"
|
||
if cfg.exists():
|
||
return f"已存在,未改动:{cfg.relative_to(root)}"
|
||
|
||
for d in ("config", "projects", "work", "renders", "logs",
|
||
"assets/characters", "assets/scenes", "assets/props",
|
||
"assets/style", "assets/overlay", "assets/templates", "tools"):
|
||
(root / d).mkdir(parents=True, exist_ok=True)
|
||
|
||
cfg.write_text((assets / "config.template.json").read_text(encoding="utf-8"),
|
||
encoding="utf-8")
|
||
for name in ("policy.template.md", "brief.template.md", "events.template.md",
|
||
"script.template.md", "prompts.template.md", "shot.schema.json"):
|
||
src = assets / name
|
||
if src.is_file():
|
||
(root / "assets" / "templates" / name).write_text(
|
||
src.read_text(encoding="utf-8"), encoding="utf-8")
|
||
|
||
copied = []
|
||
for src in sorted((skill / "scripts").glob("*.py")):
|
||
dst = root / "tools" / src.name
|
||
if not dst.exists():
|
||
dst.write_text(src.read_text(encoding="utf-8"), encoding="utf-8")
|
||
copied.append(dst.name)
|
||
|
||
print(f"已初始化 {root}")
|
||
print(f" 配置:{cfg.relative_to(root)}(请填 workspace / videoModel.endpoint)")
|
||
print(f" 脚本:{len(copied)} 个已复制到 tools/")
|
||
print(" 下一步:编辑 config/pipeline.json,然后 python3 tools/manju.py init EPxx")
|
||
return 0
|
||
|
||
|
||
def cmd_init(args):
|
||
if len(args) != 1:
|
||
return "用法: manju.py init <EPxx>"
|
||
ep = args[0]
|
||
if not ep.startswith("EP") or len(ep) != 4:
|
||
return "集号需为 EPxx,例如 EP02"
|
||
target = ROOT / "projects" / ep
|
||
if target.exists():
|
||
return f"已存在,未改动:{target}"
|
||
(target / "40_prompts").mkdir(parents=True)
|
||
(target / "00_brief.md").write_text(BRIEF.format(ep=ep), encoding="utf-8")
|
||
(target / "10_events.md").write_text(EVENTS.format(ep=ep), encoding="utf-8")
|
||
(target / "20_script.md").write_text(SCRIPT.format(ep=ep), encoding="utf-8")
|
||
(target / "30_shots.json").write_text(SHOTS.format(ep=ep), encoding="utf-8")
|
||
(target / "40_prompts/S01.md").write_text(PROMPT, encoding="utf-8")
|
||
print(f"已创建 {target.relative_to(ROOT)},运行 tools/manju.py validate projects/{ep}/30_shots.json 校验")
|
||
return 0
|
||
|
||
|
||
COMMANDS = {
|
||
"setup": cmd_setup,
|
||
"validate": cmd_validate,
|
||
"hash": cmd_hash,
|
||
"hash-file": cmd_hash_file,
|
||
"manifest": cmd_manifest,
|
||
"init": cmd_init,
|
||
}
|
||
|
||
|
||
def main(argv):
|
||
if len(argv) < 2 or argv[1] not in COMMANDS:
|
||
print(__doc__)
|
||
return 2
|
||
result = COMMANDS[argv[1]](argv[2:])
|
||
if isinstance(result, str):
|
||
print(result, file=sys.stderr)
|
||
return 2
|
||
return result
|
||
|
||
|
||
if __name__ == "__main__":
|
||
sys.exit(main(sys.argv))
|