Stop naming filler syllables in tags (they conditioned the model); default prefer_lean_tags; hard-fail intro_filler in QC; add plugins/ hook bus as thin microkernel extension point. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
# plugins — 扩展目录(微内核外挂)
|
||||
|
||||
| 路径 | 用途 |
|
||||
|------|------|
|
||||
| `plugins/hooks.py` | 钩子总线(内核只 `emit`,不 import 业务插件) |
|
||||
| `plugins/builtin/` | 内置插件(随仓发布) |
|
||||
| `plugins/<name>.py` | 单文件插件 |
|
||||
| `plugins/<name>/plugin.py` | 包式插件入口 |
|
||||
|
||||
## 钩子
|
||||
|
||||
- `before_build_tags`
|
||||
- `after_assemble`(可返回 `{"tags","lyrics"}`)
|
||||
- `before_qc_judge` / `after_qc_judge`(QC 子进程侧另见 qc_worker)
|
||||
|
||||
内核层:`core/`(引擎/路径/workflow)、`rules/`(铁律)、`cli/`(命令)。
|
||||
业务扩展优先写插件,少改内核。
|
||||
@@ -0,0 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""songforge 插件层(微内核扩展点)。
|
||||
|
||||
核心(kernel)在 core/ + rules/ + cli/;本目录只放可插拔扩展。
|
||||
内置插件见 plugins/builtin/;第三方放 plugins/<name>/plugin.py。
|
||||
"""
|
||||
from .hooks import bus, load_plugins
|
||||
|
||||
__all__ = ["bus", "load_plugins"]
|
||||
@@ -0,0 +1,2 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""内置插件包。"""
|
||||
@@ -0,0 +1,17 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""开曲衬词守卫:在 tags 组装后做一次音节点名扫描(双保险)。"""
|
||||
from ..hooks import bus
|
||||
from ...core.errors import RuleViolation
|
||||
|
||||
_BAD = ("mm mm", "ooh ooh", "oh oh syllables", "wu wu wu",
|
||||
"en en", "ng ng", "woo woo")
|
||||
|
||||
|
||||
@bus.on("after_assemble")
|
||||
def _guard_syllable_names(tags, lyrics, **_kw):
|
||||
low = (tags or "").lower()
|
||||
hits = [b for b in _BAD if b in low]
|
||||
if hits:
|
||||
raise RuleViolation(
|
||||
"tags 点名衬词音节 %s(会诱发开曲衬词)" % ", ".join(hits))
|
||||
return None
|
||||
@@ -0,0 +1,94 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""薄钩子总线:内核不知道插件细节,只按名字广播。
|
||||
|
||||
钩子约定(均可选):
|
||||
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_qc_judge kwargs: verdict, why, result
|
||||
|
||||
插件目录:
|
||||
plugins/builtin/*.py 内置,默认加载
|
||||
plugins/<name>/plugin.py 第三方包式
|
||||
plugins/<name>.py 单文件(非 hooks/__init__)
|
||||
"""
|
||||
import importlib
|
||||
import os
|
||||
import pkgutil
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
_HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
_LOADED = False
|
||||
|
||||
|
||||
class HookBus(object):
|
||||
def __init__(self):
|
||||
self._handlers = {}
|
||||
|
||||
def on(self, name):
|
||||
def deco(fn):
|
||||
self._handlers.setdefault(name, []).append(fn)
|
||||
return fn
|
||||
return deco
|
||||
|
||||
def emit(self, name, **kwargs):
|
||||
last = None
|
||||
for fn in self._handlers.get(name, []):
|
||||
try:
|
||||
ret = fn(**kwargs)
|
||||
if ret is not None:
|
||||
last = ret
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
return last
|
||||
|
||||
|
||||
bus = HookBus()
|
||||
|
||||
|
||||
def load_plugins(extra_dirs=None):
|
||||
"""发现并 import 插件(幂等)。"""
|
||||
global _LOADED
|
||||
if _LOADED:
|
||||
return
|
||||
_LOADED = True
|
||||
roots = [_HERE]
|
||||
if extra_dirs:
|
||||
roots.extend(extra_dirs)
|
||||
# 保证 songforge.plugins 可被 import
|
||||
parent = os.path.dirname(_HERE)
|
||||
if parent not in sys.path:
|
||||
sys.path.insert(0, parent)
|
||||
# builtin
|
||||
builtin = os.path.join(_HERE, "builtin")
|
||||
if os.path.isdir(builtin):
|
||||
for info in pkgutil.iter_modules([builtin]):
|
||||
if info.name.startswith("_"):
|
||||
continue
|
||||
try:
|
||||
importlib.import_module(
|
||||
"songforge.plugins.builtin.%s" % info.name)
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
# 顶层单文件 / 子包 plugin.py
|
||||
for name in sorted(os.listdir(_HERE)):
|
||||
if name.startswith("_") or name in ("builtin", "hooks.py",
|
||||
"__init__.py", "README.md"):
|
||||
continue
|
||||
path = os.path.join(_HERE, name)
|
||||
try:
|
||||
if name.endswith(".py"):
|
||||
mod = "songforge.plugins.%s" % name[:-3]
|
||||
importlib.import_module(mod)
|
||||
elif os.path.isdir(path) and os.path.isfile(
|
||||
os.path.join(path, "plugin.py")):
|
||||
importlib.import_module(
|
||||
"songforge.plugins.%s.plugin" % name)
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
|
||||
|
||||
# 首次 import hooks 时加载内置插件
|
||||
load_plugins()
|
||||
Reference in New Issue
Block a user