Xinfan Chen
2026-05-26 3d8770b5de4d73ce2dbbd0a25cde0244320330af
feat: add global visual style prompt injection
8 files added
9 files modified
89 ■■■■■ changed files
video-claw/video-claw/backend/core/agents/base_agent.py 10 ●●●●● patch | view | raw | blame | history
video-claw/video-claw/backend/core/agents/character_agent.py 5 ●●●●● patch | view | raw | blame | history
video-claw/video-claw/backend/core/agents/reference_agent.py 3 ●●●●● patch | view | raw | blame | history
video-claw/video-claw/backend/core/agents/script_agent.py 11 ●●●●● patch | view | raw | blame | history
video-claw/video-claw/backend/core/agents/video_agent.py 33 ●●●●● patch | view | raw | blame | history
video-claw/video-claw/backend/prompts/character/character_zh.txt 3 ●●●●● patch | view | raw | blame | history
video-claw/video-claw/backend/prompts/script/meta_extract_zh.txt 12 ●●●●● patch | view | raw | blame | history
video-claw/video-claw/backend/prompts/setting/setting_zh.txt 2 ●●●●● patch | view | raw | blame | history
video-claw/video-claw/backend/prompts/storyboard/shot_zh.txt 2 ●●●●● patch | view | raw | blame | history
video-claw/video-claw/backend/prompts/style/3d-disney.txt 1 ●●●●● patch | view | raw | blame | history
video-claw/video-claw/backend/prompts/style/anime.txt 1 ●●●●● patch | view | raw | blame | history
video-claw/video-claw/backend/prompts/style/cartoon.txt 1 ●●●●● patch | view | raw | blame | history
video-claw/video-claw/backend/prompts/style/chinese-ink.txt 1 ●●●●● patch | view | raw | blame | history
video-claw/video-claw/backend/prompts/style/comic-book.txt 1 ●●●●● patch | view | raw | blame | history
video-claw/video-claw/backend/prompts/style/cyberpunk.txt 1 ●●●●● patch | view | raw | blame | history
video-claw/video-claw/backend/prompts/style/oil-painting.txt 1 ●●●●● patch | view | raw | blame | history
video-claw/video-claw/backend/prompts/style/realistic.txt 1 ●●●●● patch | view | raw | blame | history
video-claw/video-claw/backend/core/agents/base_agent.py
@@ -85,6 +85,16 @@
        self._check_cancel()
        return result
    def _get_style_prompt(self, style_name: str) -> str:
        """从 prompts/style/{style_name}.txt 读取对应的视觉提示词"""
        import os
        style_file = os.path.join('prompts', 'style', f"{style_name}.txt")
        if os.path.exists(style_file):
            with open(style_file, 'r', encoding='utf-8') as f:
                return f.read().strip()
        # Fallback to English style name if file doesn't exist
        return style_name + " style"
    # -------- 抽象方法 --------
    @abstractmethod
video-claw/video-claw/backend/core/agents/character_agent.py
@@ -132,10 +132,11 @@
        self._check_cancel()
        # 初始提示词
        style_prompt = self._get_style_prompt(style)
        if asset_type == 'characters':
            base_prompt = self._char_prompt(name, desc, style, species)
            base_prompt = self._char_prompt(name, desc, style_prompt, species)
        else:
            base_prompt = self._setting_prompt(name, desc, style)
            base_prompt = self._setting_prompt(name, desc, style_prompt)
        video_ratio = "16:9"
        resolution = "2K"
video-claw/video-claw/backend/core/agents/reference_agent.py
@@ -251,8 +251,9 @@
        for version in range(max_versions):
            self._check_cancel()
            style_prompt = self._get_style_prompt(style)
            full_prompt = (
                f"{style} style, masterpiece, cinematic composition, "
                f"{style_prompt}, masterpiece, cinematic composition, "
                f"best quality, high resolution, "
                f"{first_frame_prompt}"
            )
video-claw/video-claw/backend/core/agents/script_agent.py
@@ -91,14 +91,11 @@
                new_settings = final_data.get("new_settings", [])
                new_ep_list = final_data.get("new_episodes", [])
                
                # 1. 更新第一阶段剧本数据 (内存)
                # 更新第一阶段剧本数据 (内存)
                final_data.setdefault("episodes", []).extend(new_ep_list)
                final_data.setdefault("characters", []).extend(new_chars)
                final_data.setdefault("settings", []).extend(new_settings)
                # 2. 【优化】移除显式的 _save_result 调用,编排器会根据 payload 自动保存
                # 3. 同步更新跨阶段 artifacts
                # 创建一个包含增量信息的返回结果,供 Orchestrator 钩子使用
                result_payload = copy.deepcopy(final_data)
                result_payload["new_characters"] = new_chars
@@ -108,8 +105,7 @@
                logger.info(f"[ScriptWriter] Confirmed continuation. Providing incremental data to Orchestrator.")
                return {"payload": result_payload, "requires_intervention": False, "stage_completed": True}
            # 处理 delete_continue
            # 【优化】移除显式的 _save_result 调用,仅返回清理后的数据
            # 处理 delete_continue 的情况,直接丢弃新增内容,保持原有剧本数据不变
            for key in ["new_episodes", "new_characters", "new_settings", "sequel_idea"]:
                final_data.pop(key, None)
            return {"payload": final_data, "requires_intervention": False, "stage_completed": True}
@@ -335,9 +331,6 @@
            }
            
            self._save_result(final_json, sid, is_zh)
            # 【优化】不再需要显式的 _save_result。Orchestrator 会处理 session 的保存。
            # 如果确实需要一份独立的 script 存档,可以保留最后一次 save_result,
            # 但为了架构统一,这里我们仅返回 final_json
            _log_progress(100, "剧本结构化解析完成!")
            return final_json
video-claw/video-claw/backend/core/agents/video_agent.py
@@ -101,13 +101,13 @@
    # ─── 提示词组装 ───
    def _assemble_prompt(self, segment: dict, style: str) -> str:
    def _assemble_prompt(self, segment: dict, style_prompt: str) -> str:
        """组装视频提示词
        格式:
        风格控制:用户选择的风格, 电影质感
        风格控制:用户选择的风格提示词, 电影质感
        分镜列表:分镜1:[时长] content... 分镜2:[时长] content...
        """
        prompt = f"风格控制:{style}风格, 电影质感\n"
        prompt = f"风格控制:{style_prompt}\n"
        prompt += "分镜列表:"
        
        shots = segment.get("shots", [])
@@ -153,7 +153,7 @@
    # ─── 预览 / Payload ───
    def _build_preview(self, sid: str, segments: list, scene_map: dict, style_name: str = "") -> list:
    def _build_preview(self, sid: str, segments: list, scene_map: dict, style_prompt: str = "") -> list:
        preview = []
        for idx, seg in enumerate(segments, 1):
            segment_id = seg["segment_id"]
@@ -165,7 +165,7 @@
                "name": f"第{ep_n}集-片段{seg_n}",
                "episode": ep_n,
                "index": seg_n,
                "description": self._assemble_prompt(seg, style_name),
                "description": self._assemble_prompt(seg, style_prompt),
                "duration": seg.get('total_duration', 10),
                "selected": versions[-1] if versions else "",
                "versions": versions,
@@ -173,7 +173,7 @@
            })
        return preview
    def _build_payload(self, sid: str, segments: list, style_name: str = "") -> dict:
    def _build_payload(self, sid: str, segments: list, style_prompt: str = "") -> dict:
        clips = []
        for idx, seg in enumerate(segments, 1):
            segment_id = seg["segment_id"]
@@ -185,7 +185,7 @@
                "name": f"第{ep_n}集-片段{seg_n}",
                "episode": ep_n,
                "index": seg_n,
                "description": self._assemble_prompt(seg, style_name),
                "description": self._assemble_prompt(seg, style_prompt),
                "duration": seg.get('total_duration', 10),
                "selected": versions[-1] if versions else "",
                "versions": versions,
@@ -199,7 +199,7 @@
            "stage_completed": True,
        }
    def _update_session_video_data(self, sid: str, segments: list, style_name: str) -> None:
    def _update_session_video_data(self, sid: str, segments: list, style_prompt: str) -> None:
        """同步视频生成结果到 session.json 的 artifacts 中,适配前端读取"""
        session_path = os.path.join('code/data/sessions', f'{sid}.json')
        if not os.path.exists(session_path):
@@ -209,7 +209,7 @@
            with open(session_path, 'r', encoding='utf-8') as f:
                data = json.load(f)
            
            payload = self._build_payload(sid, segments, style_name)
            payload = self._build_payload(sid, segments, style_prompt)
            data.setdefault("artifacts", {})["video_generation"] = payload["payload"]
            
            # 同时保留一份给后端的 scene2video (如果需要)
@@ -297,6 +297,7 @@
            "cyberpunk": "赛博朋克"
        }
        style_name = style_map_zh.get(style_zh, style_zh)
        style_prompt = self._get_style_prompt(style_zh)
        # ═══ 介入:重新生成指定片段 ═══
        if intervention:
@@ -312,7 +313,7 @@
                        for seg_id in regen_ids:
                            seg = segment_map.get(seg_id)
                            if not seg: continue
                            prompt = self._assemble_prompt(seg, style_name)
                            prompt = self._assemble_prompt(seg, style_prompt)
                            img_path = self._get_reference_image(sid, seg_id, scene_map)
                            duration = seg.get("total_duration", 10)
                            fut = executor.submit(
@@ -352,13 +353,13 @@
                await loop.run_in_executor(None, regen_run)
                
                # 同步到 session artifacts
                self._update_session_video_data(sid, segments, style_name)
                self._update_session_video_data(sid, segments, style_prompt)
                
                return self._build_payload(sid, segments, style_name)
                return self._build_payload(sid, segments, style_prompt)
        # ═══ 正常流程:全量生成 ═══
        self._report_progress("视频生成", "正在准备数据...", 2)
        preview = self._build_preview(sid, segments, scene_map, style_name)
        preview = self._build_preview(sid, segments, scene_map, style_prompt)
        self._report_progress("视频生成", "加载视频列表", 5, data={"assets_preview": {"clips": preview}})
        def run():
@@ -367,7 +368,7 @@
                seg_id = seg["segment_id"]
                existing = self._list_versions(sid, seg_id)
                if existing: continue
                prompt = self._assemble_prompt(seg, style_name)
                prompt = self._assemble_prompt(seg, style_prompt)
                img_path = self._get_reference_image(sid, seg_id, scene_map)
                duration = seg.get("total_duration", 10)
                tasks.append((seg_id, prompt, img_path, duration))
@@ -426,7 +427,7 @@
        await loop.run_in_executor(None, run)
        
        # 同步到 session artifacts
        self._update_session_video_data(sid, segments, style_name)
        self._update_session_video_data(sid, segments, style_prompt)
        
        self._report_progress("视频生成", "完成", 100)
        return self._build_payload(sid, segments, style_name)
        return self._build_payload(sid, segments, style_prompt)
video-claw/video-claw/backend/prompts/character/character_zh.txt
@@ -1,4 +1,4 @@
角色设计参考图,{style} 风格,纯白背景。杰作,高画质。
角色设计参考图,{style},纯白背景。
角色名称:{name}
角色描述: {desc}
在同一排从左至右排列同一角色的 4 个视角:
@@ -6,5 +6,6 @@
2) 正面全身照,
3) 侧面全身照,
4) 背面全身照。
人物形象保持干净自然,脸上和身上绝对不要有任何特殊的标记、疤痕、胎记或纹身。
所有视角必须展示同一个角色,外貌、发型、肤色和服装保持高度一致。
画面纯净,绝对禁止出现任何文字、标签、标注、注释、说明或水印。
video-claw/video-claw/backend/prompts/script/meta_extract_zh.txt
@@ -18,15 +18,17 @@
1. **输出格式**:必须且仅能输出一个纯净的 JSON 对象。严禁包含任何 Markdown 格式(如 ```json 代码块)、解释性文字、开场白或结尾。
2. 提取所有在剧本中出现的、有台词或重要动作的【角色】(不仅仅是主角),但是注意不要提取群体角色(如:若干员工、一些顾客)。
3. 提取所有在剧本中具体描述过的、不同地理位置的【场景】(不仅仅是概括性的)。
4. 角色描述:
   - 采用“年龄+性别+发型/首饰+服装+体型+面部特征/神态”的概括性写法。
4. 角色描述(用于生成静态肖像):
   - 采用“年龄+性别+发型/首饰+服装+体型+面部特征”的概括性写法。
   - 核心特征:必须包含发型、体型、服装颜色和款式等视觉特征。
   - 严格限制:绝不能涉及神态、表情、性格,只描写纯粹的客观外貌;不要描写人物的任何动作;不要描写前后的状态变化,必须是一个固定的、静态的形象描述;人物身上不要有任何特殊的标记(如疤痕、胎记、纹身、奇怪的面妆等)。
   - 严禁加入科幻或幻想元素,外貌必须正常。
   - 风格要求:30-50字,语言平实直接,禁止使用比喻或文学化修辞。
5. 场地布置:
   - 采用“空间类型+光效方向与颜色+核心陈设(质感/材质)+环境氛围”的概括性写法。
   - 示例:“现代简约办公室,清冷的月光从落地窗洒入,办公桌为冷色实木,空气透着宁静与严肃。”
   - 风格要求:30-50字,描述具体且具备可拍摄感。
   - 采用“空间类型+光照情况+核心陈设(质感/材质)”的概括性写法。
   - 严格限制:光线不能太暗(保持充足照明),绝不能有任何文学性、情感化的主观描述。
   - 示例:“现代简约办公室,明亮的自然光从落地窗洒入,中心摆放着一张冷色实木办公桌和黑色皮椅。”
   - 风格要求:30-50字,描述客观、具体且具备可拍摄感。
---
video-claw/video-claw/backend/prompts/setting/setting_zh.txt
@@ -1,3 +1,3 @@
全景远景,平视广角镜头,{style} 风格,电影级构图,杰作,高画质。
全景远景,平视广角镜头,{style},电影级构图,杰作,高画质。
场景描述: {name} — {desc}
画面主体区域禁止出现人物、动物或其他活体,确保环境布景完整、构图平衡。
video-claw/video-claw/backend/prompts/storyboard/shot_zh.txt
@@ -9,7 +9,7 @@
1. **输出格式**:必须且仅能输出一个纯净的 JSON 数组。严谨包含 ```json 代码块或其他引导性文字。
2. **片段时长控制**:每个拍摄片段(total_duration)严格限制在 **5~15秒** 之间。
3. **数学校验**:`total_duration` 必须等于该片段下所有分镜 `duration` 之和。
4. **景别规范**:仅选:特写、近景、过肩近景、中景、远景。
4. **景别规范**:仅选:近景(半身)、过肩近景、中景(全身)、全景。
5. **内容规范**:
   - 包含景别、机位、动作、完整台词、详细音色(如:20多岁男性,音质清亮稳健,带自嘲语调)。
   - 视觉风格:符合 {style}。
video-claw/video-claw/backend/prompts/style/3d-disney.txt
New file
@@ -0,0 +1 @@
3D CGI animation, Disney Pixar style, smooth textures, soft volumetric lighting, highly detailed 3D render, octane render, unreal engine 5
video-claw/video-claw/backend/prompts/style/anime.txt
New file
@@ -0,0 +1 @@
anime style, high quality, vibrant colors, clean lines, detailed backgrounds, masterpiece, studio ghibli or makoto shinkai aesthetic, 2d animation
video-claw/video-claw/backend/prompts/style/cartoon.txt
New file
@@ -0,0 +1 @@
cartoon style, 2D animation look, thick outlines, bold colors, flat shading, vector art style, exaggerated proportions
video-claw/video-claw/backend/prompts/style/chinese-ink.txt
New file
@@ -0,0 +1 @@
traditional Chinese ink wash painting, delicate soft strokes, monochrome and minimal colors, artistic, ethereal, atmospheric, sumi-e
video-claw/video-claw/backend/prompts/style/comic-book.txt
New file
@@ -0,0 +1 @@
Western comic book style, Marvel DC style, dramatic bold ink lines, halftone patterns, dynamic lighting, pop art colors, graphic graphic novel
video-claw/video-claw/backend/prompts/style/cyberpunk.txt
New file
@@ -0,0 +1 @@
cyberpunk aesthetic, neon lighting, dark moody atmosphere, futuristic, highly detailed, dystopian sci-fi environment, synthwave colors
video-claw/video-claw/backend/prompts/style/oil-painting.txt
New file
@@ -0,0 +1 @@
classical oil painting, artistic brushstrokes, rich textures, impasto style, rembrandt lighting, museum quality masterpiece, traditional art
video-claw/video-claw/backend/prompts/style/realistic.txt
New file
@@ -0,0 +1 @@
photorealistic, cinematic lighting, 8k resolution, high-detail textures, ultra realistic, professional photography, natural lighting, masterpiece