Skip to content

V3 Phase 2: Content Guard + Story Engine + audience profiles#11

Merged
maxazure merged 1 commit into
mainfrom
v3-phase-2-content-guard
May 16, 2026
Merged

V3 Phase 2: Content Guard + Story Engine + audience profiles#11
maxazure merged 1 commit into
mainfrom
v3-phase-2-content-guard

Conversation

@maxazure

Copy link
Copy Markdown
Owner

Closes part of #10.

Summary

Three new subsystems land in this PR. They're independent enough to ship
together but each is fully self-contained.

1. Content Guard (scripts/content_guard.py)

Xiaohongshu/RED platform-rule lint. 80+ regex covering:

  • 广告法极限词 (最 / 第一 / 唯一 / 万能 / 顶级 / 全网最低 / 遥遥领先 ...)
  • Off-platform diversion (微信 / VX / wx / 加微 / QQ / phone / 抖音 / 外站 URL / 二维码 ...)
  • 医美/医疗 (治愈 / 祛斑 / 水光针 / 医生同款 / 三甲推荐 ...)
  • 财富诱导 (年入 X 万 / 躺赚 / 财富自由 / 稳赚不赔 / 零成本 / 包过 / 暴利 ...)

Two violation levels: HARD (refuse export) / SOFT (warn). Wired into
render_final.py so the render aborts before any expensive work if the
title or chapters trip a hard rule. Override with --no-content-guard.

2. Story Engine (scripts/rewrite_script.py)

LLM-driven script rewriter. Doesn't ship an LLM client — produces a
structured prompt the user pipes into Claude/ChatGPT, then validates
the JSON the LLM returns and materialises it into clean_script.md.

  • 8 hook templates (scripts/prompts/hook_templates.yaml): 反常识 /
    痛点 / 数字 / 悬念 / 身份 / 反差 / 利益 / 场景
  • 5 CTA templates (scripts/prompts/cta_templates.yaml) weighted by
    小红书 CES (关注 8 > 评论/分享 4 > 收藏/点赞 1)
  • 3 structures: pain_solve / story_reversal / listicle

3. Audience profiles (scripts/profiles/)

  • tech_pro.yaml — AI/创业/effort vertical
  • lifestyle.yaml — vlog/穿搭/家居

Each encodes default duration, cut frequency, subtitle density, font
preference, BGM gain, target aspect ratio. Loaded by
load_profile(name). render_final.py --profile tech_pro overlays
defaults onto fields the user didn't pass via CLI.

PyYAML-optional reader so fresh installs don't need extra deps.

Tests

+56 new (38 content-guard, 5 profiles, 10 story-engine, 3 integration).
Full suite: 82 passing.

Test plan

  • pytest tests/ green
  • python3 scripts/content_guard.py --title "全网最低价" returns 1
  • python3 scripts/content_guard.py --title "AI 失业焦虑?我看到机会" returns 0
  • python3 scripts/render_final.py --help shows --profile, --no-content-guard
  • Smoke: try rendering with title=加微信 wx123 → hard-block exit code 2

CONTENT GUARD (scripts/content_guard.py)
- 80+ regex rules covering 5 hard-block categories:
  - 广告法极限词 (最/第一/唯一/万能/顶级 …)
  - Off-platform diversion (微信/VX/wx/QQ/phone/外站 URL/二维码 …)
  - 医美/医疗功效 (治愈/祛斑/水光针/医生同款 …)
  - 财富诱导 (年入/月入/躺赚/财富自由 …)
- Soft-warn rules: title>20 chars, !!! runs, emoji density >30 %, caption>800
- enforce() raises HardBlock / SoftWarn; scan_text() returns Violation list
- CLI: `python3 scripts/content_guard.py --title T --script S --strict`
- Wired into render_final.py: HARD violations halt export with exit 2,
  --no-content-guard escape hatch for emergencies

STORY ENGINE (scripts/rewrite_script.py + prompts/)
- 8 hook templates in prompts/hook_templates.yaml (反常识/痛点/数字/悬念/
  身份/反差/利益/场景)
- 5 CTA templates in prompts/cta_templates.yaml weighted by Xiaohongshu
  CES score (关注 8 > 评论/分享 4 > 收藏/点赞 1)
- 3 structures: pain_solve / story_reversal / listicle
- emit_prompt() produces a structured LLM prompt; validate_llm_output()
  enforces the 5-field schema (hook/pain/turn/value[]/cta) and hooks the
  content guard before materialising the clean_script.md

AUDIENCE PROFILES (scripts/profiles/)
- tech_pro.yaml — AI/创业/efficiency vertical: 90s default, -16dB BGM,
  64px subtitles, Heavy fonts, 3:4 Xiaohongshu / 9:16 抖音 export
- lifestyle.yaml — vlog/穿搭/家居: 60s default, -10dB BGM, slower pacing
- profiles.__init__ provides load_profile() + list_profiles() with a
  PyYAML-optional reader (zero new hard deps)
- render_final.py `--profile tech_pro` flag overlays defaults onto fields
  the user didn't pass

Tests: +56 (38 content guard, 5 profiles, 10 story engine, 3 render
integration). Full suite 82 passing.
Copilot AI review requested due to automatic review settings May 16, 2026 23:28
@maxazure maxazure merged commit a6db39f into main May 16, 2026
@maxazure maxazure deleted the v3-phase-2-content-guard branch May 16, 2026 23:28
@maxazure maxazure removed the request for review from Copilot May 16, 2026 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant