feat(b0): 注入透明可控版后端 — PUT override(pin/排除/recent_n) + 选择函数加参 + draft 同读

- selection.select_relevant_entities 加 pinned/excluded frozenset 入参;新理由 author_pin(末位)
- assemble 加 override 关键字参(recent_n 覆盖回看章数 + pin/排除);GET/PUT/draft 同读同一覆盖(不变量 #6 作者兜底)
- 新 domain/injection_repo.py(InjectionOverride/EntityRef/SqlInjectionOverrideRepo,upsert 只 flush)
- 新表 chapter_injection(迁移 ad2c4c663daf,唯一 project_id+chapter_no;复用 outline 行已否决)
- PUT/GET injection 端点 + InjectionOverrideRequest/回显 pinned/excluded;recent_n 1..20 校验 422
- 单测:selection pin/排除/exclude>pin + assemble override + 端点 PUT/404/422;regen TS 客户端
- 门禁绿:ruff/format · mypy 163 · alembic 无漂移 · pytest 476

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Yaojia Wang
2026-06-20 11:56:54 +02:00
parent e8cccf7389
commit 0d473e726e
16 changed files with 681 additions and 41 deletions

View File

@@ -152,6 +152,24 @@ class Chapter(UuidPk, CreatedAt, Base):
version: Mapped[int] = mapped_column(Integer, nullable=False, server_default=text("1"))
class ChapterInjection(UuidPk, TimestampedMixin, Base):
"""本章注入覆盖B0 可控版):作者对确定性自动选择的微调,每章一行。
与 `outline.beats` 分表存放(复用 outline 行会污染 beats/prompt已否决
pinned/excluded 为 JSONB list[{kind,name}]recent_n 覆盖近况回看章数NULL=用默认)。
"""
__tablename__ = "chapter_injection"
__table_args__ = (UniqueConstraint("project_id", "chapter_no"),)
project_id: Mapped[uuid.UUID] = mapped_column(
ForeignKey("projects.id", ondelete="CASCADE"), nullable=False, index=True
)
chapter_no: Mapped[int] = mapped_column(Integer, nullable=False)
pinned: Mapped[list[Any]] = mapped_column(JSONB, server_default=text("'[]'"))
excluded: Mapped[list[Any]] = mapped_column(JSONB, server_default=text("'[]'"))
recent_n: Mapped[int | None] = mapped_column(Integer)
class ChapterReview(UuidPk, CreatedAt, Base):
__tablename__ = "chapter_reviews"
project_id: Mapped[uuid.UUID] = mapped_column(