Add align/recheck/compare, plugins, and refresh Agent docs.
selftest / selftest (push) Canceled after 0s
selftest / selftest (push) Canceled after 0s
Wire deliver_report/listen_pack/retry hooks; gen --auto-retry and intro light check; make AGENTS_MIN the up-to-date agent entry with full command map. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+31
-9
@@ -1,17 +1,39 @@
|
||||
# plugins — 扩展目录(微内核外挂)
|
||||
|
||||
Agent / 开发者:**新能力优先写插件**,少改 `core/` / `rules/` / `cli/`。
|
||||
|
||||
| 路径 | 用途 |
|
||||
|------|------|
|
||||
| `plugins/hooks.py` | 钩子总线(内核只 `emit`,不 import 业务插件) |
|
||||
| `plugins/builtin/` | 内置插件(随仓发布) |
|
||||
| `plugins/<name>.py` | 单文件插件 |
|
||||
| `plugins/<name>/plugin.py` | 包式插件入口 |
|
||||
| `hooks.py` | 钩子总线(内核只 `emit`) |
|
||||
| `builtin/` | 随仓内置(如 `intro_guard`) |
|
||||
| `<name>/plugin.py` | 包式插件(推荐) |
|
||||
| `<name>.py` | 单文件插件 |
|
||||
|
||||
## 钩子
|
||||
|
||||
- `before_build_tags`
|
||||
- `after_assemble`(可返回 `{"tags","lyrics"}`)
|
||||
- `before_qc_judge` / `after_qc_judge`(QC 子进程侧另见 qc_worker)
|
||||
| 钩子 | 何时 | 典型用途 |
|
||||
|------|------|----------|
|
||||
| `before_build_tags` | assemble 前 | 改风格参数 |
|
||||
| `after_assemble` | tags/歌词就绪 | 守卫、改写 |
|
||||
| `after_gen` | gen/dry-run 写完 manifest | `deliver_report` |
|
||||
| `after_qc` | qc 渲染结束 | `deliver_report` / `listen_pack` / `retry_on_intro_fail` |
|
||||
|
||||
内核层:`core/`(引擎/路径/workflow)、`rules/`(铁律)、`cli/`(命令)。
|
||||
业务扩展优先写插件,少改内核。
|
||||
## 当前插件
|
||||
|
||||
| 插件 | 作用 |
|
||||
|------|------|
|
||||
| `builtin/intro_guard` | tags 禁止点名衬词音节 |
|
||||
| `deliver_report` | 写 `data/runs/.../report.md` |
|
||||
| `listen_pack` | QC PASS 后截 `listen/intro.wav` + `chorus_approx.wav` |
|
||||
| `retry_on_intro_fail` | 写 `retry_hint.json`;配合 `gen --auto-retry` |
|
||||
|
||||
## 最小插件示例
|
||||
|
||||
```python
|
||||
# plugins/hello/plugin.py
|
||||
from ..hooks import bus
|
||||
|
||||
@bus.on("after_gen")
|
||||
def _hi(run_dir=None, **kw):
|
||||
print("[hello]", run_dir)
|
||||
```
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
# package plugin
|
||||
@@ -0,0 +1,84 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""生歌结束后按 AGENTS_MIN 模板写 report.md。"""
|
||||
import json
|
||||
import os
|
||||
|
||||
from ..hooks import bus
|
||||
|
||||
|
||||
def _write_report(rundir, man, qc=None, intro=None):
|
||||
if not rundir:
|
||||
return
|
||||
rows = []
|
||||
verd = "-"
|
||||
if qc:
|
||||
rows = [r for r in (qc.get("rows") or []) if r.get("group") != "baseline"]
|
||||
vs = qc.get("verdicts") or []
|
||||
if vs:
|
||||
verd = vs[0].get("verdict") or "-"
|
||||
r0 = rows[0] if rows else {}
|
||||
audio = "-"
|
||||
for r in man.get("results") or []:
|
||||
files = r.get("files") or []
|
||||
if files:
|
||||
audio = files[0]
|
||||
break
|
||||
intro_line = "-"
|
||||
if intro:
|
||||
intro_line = "ok=%s n=%s ratio=%s" % (
|
||||
intro.get("ok"), intro.get("intro_filler_n"),
|
||||
intro.get("intro_filler_ratio"))
|
||||
elif r0:
|
||||
intro_line = "n=%s ratio=%s" % (
|
||||
r0.get("intro_filler_n"), r0.get("intro_filler_ratio"))
|
||||
body = "\n".join([
|
||||
"## 生歌报告",
|
||||
"- 结论:%s" % (verd if verd != "-" else (man.get("qc_verdict") or "—")),
|
||||
"- 歌名 / 风格 / BPM / 设定时长:%s / %s / %s / %s" % (
|
||||
man.get("title") or "—", man.get("style") or "—",
|
||||
man.get("bpm") or "—", man.get("duration") or "—"),
|
||||
"- run_id:%s" % (man.get("run_id") or os.path.basename(rundir)),
|
||||
"- 音频路径:%s" % audio,
|
||||
"- 歌词:见本目录 lyrics.txt;密度见 manifest.density",
|
||||
"- QC:verdict=%s;voice_nn=%s sim=%s;开曲衬词 %s;filler_ratio=%s" % (
|
||||
verd, r0.get("voice_nn") or "—", r0.get("voice_nn_sim") or "—",
|
||||
intro_line, r0.get("filler_ratio") if r0 else "—"),
|
||||
"- 弱参考:style_fam=%s style_conf=%s" % (
|
||||
r0.get("style_fam") or "—", r0.get("style_conf") or "—"),
|
||||
"- 模型/采样:见 manifest.model / sampler / encode",
|
||||
"- 种子:%s" % (
|
||||
", ".join(str(x.get("seed")) for x in (man.get("results") or [])
|
||||
if x.get("seed") is not None) or "—"),
|
||||
"- 建议:先听 listen/ 前奏与副歌片段;FAIL 则改词或换 seed 重 gen",
|
||||
"",
|
||||
])
|
||||
path = os.path.join(rundir, "report.md")
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
f.write(body)
|
||||
return path
|
||||
|
||||
|
||||
@bus.on("after_gen")
|
||||
def _on_gen(run_dir=None, manifest=None, **_kw):
|
||||
if not run_dir or not manifest:
|
||||
return None
|
||||
path = _write_report(run_dir, manifest)
|
||||
return dict(report=path) if path else None
|
||||
|
||||
|
||||
@bus.on("after_qc")
|
||||
def _on_qc(run_dir=None, report=None, **_kw):
|
||||
if not run_dir:
|
||||
return None
|
||||
man = {}
|
||||
mp = os.path.join(run_dir, "manifest.json")
|
||||
if os.path.isfile(mp):
|
||||
with open(mp, encoding="utf-8") as f:
|
||||
man = json.load(f)
|
||||
intro = None
|
||||
ip = os.path.join(run_dir, "intro_check.json")
|
||||
if os.path.isfile(ip):
|
||||
with open(ip, encoding="utf-8") as f:
|
||||
intro = json.load(f)
|
||||
path = _write_report(run_dir, man, qc=report, intro=intro)
|
||||
return dict(report=path) if path else None
|
||||
+3
-1
@@ -5,7 +5,9 @@
|
||||
before_build_tags kwargs: args, cfg, style, chill, instrumental, lean
|
||||
after_assemble kwargs: tags, lyrics, args, cfg, style, lean
|
||||
-> 可返回 {"tags":..., "lyrics":...} 覆盖
|
||||
before_qc_judge kwargs: result, expect, soft -> 可追加 why 列表
|
||||
after_gen kwargs: run_dir, manifest, cfg, args
|
||||
after_qc kwargs: run_dir, report, verd, rows, cfg, args
|
||||
before_qc_judge kwargs: result, expect, soft (qc_worker 子进程内,可选)
|
||||
after_qc_judge kwargs: verdict, why, result
|
||||
|
||||
插件目录:
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
# package plugin
|
||||
@@ -0,0 +1,60 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""PASS 后截取前奏 + 副歌附近听感片段到 run/listen/。"""
|
||||
import json
|
||||
import os
|
||||
|
||||
from ..hooks import bus
|
||||
|
||||
|
||||
def _clip(cfg, src, start, dur, out):
|
||||
from ...cli.media import _run
|
||||
code, blob = _run(dict(
|
||||
op="clip", file=os.path.abspath(src),
|
||||
start=float(start), dur=float(dur), out=os.path.abspath(out)))
|
||||
return code == 0 and blob and not blob.get("error")
|
||||
|
||||
|
||||
def _audio_from(cfg, man, rundir):
|
||||
from ...cli.extras import _first_audio
|
||||
return _first_audio(cfg, man or {}, rundir)
|
||||
|
||||
|
||||
@bus.on("after_qc")
|
||||
def _pack(run_dir=None, report=None, cfg=None, **_kw):
|
||||
if not run_dir or not report or not cfg:
|
||||
return None
|
||||
verd = report.get("verdicts") or []
|
||||
rows = report.get("rows") or []
|
||||
new_names = {r.get("file") for r in rows if r.get("group") != "old"}
|
||||
new_v = [v for v in verd if v.get("file") in new_names] or [
|
||||
v for v in verd if v.get("verdict")]
|
||||
if not new_v or any(v.get("verdict") != "PASS" for v in new_v):
|
||||
return None
|
||||
man = {}
|
||||
mp = os.path.join(run_dir, "manifest.json")
|
||||
if os.path.isfile(mp):
|
||||
with open(mp, encoding="utf-8") as f:
|
||||
man = json.load(f)
|
||||
src = _audio_from(cfg, man, run_dir)
|
||||
if not src or not os.path.isfile(src):
|
||||
return None
|
||||
bpm = float(man.get("bpm") or 104)
|
||||
bars = int(man.get("intro_bars") or 8)
|
||||
intro_sec = bars * 60.0 / bpm * 4.0
|
||||
listen = os.path.join(run_dir, "listen")
|
||||
os.makedirs(listen, exist_ok=True)
|
||||
outs = []
|
||||
a = os.path.join(listen, "intro.wav")
|
||||
if _clip(cfg, src, 0.0, intro_sec, a):
|
||||
outs.append(a)
|
||||
# 副歌附近:约在 40% 时长处截 15s
|
||||
dur = float(man.get("duration") or 180)
|
||||
chorus_t = max(intro_sec + 1.0, dur * 0.40)
|
||||
b = os.path.join(listen, "chorus_approx.wav")
|
||||
if _clip(cfg, src, chorus_t, 15.0, b):
|
||||
outs.append(b)
|
||||
meta = dict(source=src, clips=outs, intro_sec=intro_sec,
|
||||
chorus_start=chorus_t)
|
||||
with open(os.path.join(listen, "pack.json"), "w", encoding="utf-8") as f:
|
||||
json.dump(meta, f, ensure_ascii=False, indent=1)
|
||||
return dict(listen=listen, clips=outs)
|
||||
@@ -0,0 +1 @@
|
||||
# package plugin
|
||||
@@ -0,0 +1,54 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""开曲衬词 FAIL 时给出重试建议;供 gen --auto-retry 读取。"""
|
||||
import json
|
||||
import os
|
||||
|
||||
from ..hooks import bus
|
||||
|
||||
# 判定文案关键字(与 qc_worker judge 一致)
|
||||
_INTRO_KEYS = ("开曲衬词", "前 2s 就已唱出", "人声在")
|
||||
|
||||
|
||||
def is_intro_fail(why_list):
|
||||
text = " ".join(why_list or [])
|
||||
return any(k in text for k in _INTRO_KEYS)
|
||||
|
||||
|
||||
@bus.on("after_qc")
|
||||
def _hint(run_dir=None, report=None, **_kw):
|
||||
if not run_dir or not report:
|
||||
return None
|
||||
verd = report.get("verdicts") or []
|
||||
reasons = []
|
||||
for v in verd:
|
||||
if v.get("verdict") == "FAIL":
|
||||
reasons.extend(v.get("why") or [])
|
||||
if not is_intro_fail(reasons):
|
||||
# 也看 intro_check.json
|
||||
ip = os.path.join(run_dir, "intro_check.json")
|
||||
if os.path.isfile(ip):
|
||||
with open(ip, encoding="utf-8") as f:
|
||||
blob = json.load(f)
|
||||
if blob.get("fail") or blob.get("ok") is False:
|
||||
reasons.append("intro_check fail")
|
||||
else:
|
||||
return None
|
||||
else:
|
||||
return None
|
||||
hint = dict(
|
||||
retry=True,
|
||||
reason="intro_filler_or_early_vocal",
|
||||
why=reasons[:8],
|
||||
suggest="换 seed 重 gen,或 songforge recheck --run <id> 后再决定",
|
||||
)
|
||||
path = os.path.join(run_dir, "retry_hint.json")
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
json.dump(hint, f, ensure_ascii=False, indent=1)
|
||||
return hint
|
||||
|
||||
|
||||
def should_retry_intro_blob(blob):
|
||||
"""给 gen --auto-retry 用:intro_check blob 是否应换 seed。"""
|
||||
if not blob or blob.get("error"):
|
||||
return False
|
||||
return bool(blob.get("fail") or blob.get("ok") is False)
|
||||
Reference in New Issue
Block a user