This repository has been archived on 2026-08-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
kb-skills/.planning/phases/13-llm/13-06-PLAN.md
T

208 lines
6.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
phase: 13
plan: 06
type: execute
wave: 2
depends_on:
- 13-01
- 13-02
- 13-03
- 13-04
- 13-05
files_modified:
- kb_workflow/srt/semantic_engine.py
- tests/test_semantic_engine.py
autonomous: true
requirements:
- STRAT-01
- STRAT-02
- STRAT-03
must_haves:
truths:
- "系统提供可扩展的分段策略架构"
- "Phase 13 实现统一策略(用户决策:无类型区分)"
- "策略架构支持未来添加新策略(扩展性)"
artifacts:
- path: "kb_workflow/srt/semantic_engine.py"
provides: "可扩展的策略架构(Strategy Pattern 预留)"
min_lines: 300
exports: ["SemanticSegmentationEngine", "SegmentationStrategy"]
- path: "tests/test_semantic_engine.py"
provides: "策略扩展性测试"
min_lines: 50
key_links:
- from: "SegmentationStrategy"
to: "SemanticSegmentationEngine"
via: "策略模式架构"
pattern: "class.*Strategy.*segment"
- from: "tests"
to: "SegmentationStrategy"
via: "验证策略可扩展性"
pattern: "test.*strategy.*extensibility"
---
<objective>
实现可扩展的分段策略架构
目的:提供策略架构支持未来扩展(Phase 13 实现统一策略,遵守用户决策)
输出:SegmentationStrategy 接口,统一策略实现
</objective>
<execution_context>
@/home/starmen1265/.claude/get-shit-done/workflows/execute-plan.md
@/home/starmen1265/.claude/get-shit-done/templates/summary.md
</execution_context>
<context>
@.planning/phases/13-llm/13-CONTEXT.md
@.planning/phases/13-llm/13-RESEARCH.md
# User Decision (Locked)
- **视频类型策略**: 无类型区分 — 使用统一的分段 Prompt,不针对不同视频类型(知识类/故事类/教程类)设计不同策略
# Research Document
Open Question 3: STRAT-01/STRAT-02/STRAT-03 需求的边界
Recommendation: 在代码结构上预留策略扩展接口(Strategy Pattern),但 Phase 13 只实现统一策略
</context>
<feature>
<name>分段策略架构</name>
<files>kb_workflow/srt/semantic_engine.py, tests/test_semantic_engine.py</files>
<behavior>
架构设计(研究文档建议):
- 预留 Strategy Pattern 接口(SegmentationStrategy)
- Phase 13 实现统一策略(UnifiedSegmentationStrategy)
- 支持未来添加知识类/故事类等特定策略
Phase 13 实现(遵守用户决策):
- 统一策略适用于所有视频类型
- 视频类型仅用于 Prompt 上下文,不改变分段策略
测试验证:
- 策略接口可扩展
- 统一策略适用于所有视频类型
</behavior>
<implementation>
在 semantic_engine.py 中:
1. 定义 SegmentationStrategy Protocol(接口)
2. 实现 UnifiedSegmentationStrategy(统一策略)
3. SemanticSegmentationEngine 使用策略接口
测试:
1. test_strategy_selection() - 验证策略选择
2. test_strategy_extensibility() - 验证策略可扩展性
</implementation>
</feature>
<tasks>
<task type="auto">
<name>Task 1: 实现可扩展策略架构</name>
<files>kb_workflow/srt/semantic_engine.py, tests/test_semantic_engine.py</files>
<action>
在 semantic_engine.py 中实现策略架构:
1. 定义 SegmentationStrategy Protocol:
```python
from typing import Protocol, List
from kb_workflow.srt.parser import Segment
class SegmentationStrategy(Protocol):
"""分段策略接口"""
def segment(
self,
segments: List[Segment],
metadata: dict
) -> List[str]:
"""对字幕分段进行语义分段
Args:
segments: 字幕分段列表
metadata: 视频元数据
Returns:
段落文本列表
"""
...
```
2. 实现 UnifiedSegmentationStrategy(统一策略):
```python
class UnifiedSegmentationStrategy:
"""统一分段策略
适用于所有视频类型(知识类、故事类、访谈类等)。
视频类型仅用于 Prompt 上下文,不改变分段策略。
遵守用户决策:无类型区分,使用统一 Prompt。
"""
def __init__(self, ai_client: Optional[AIClientProtocol] = None):
self.ai_client = ai_client
# Lazy initialization...
def segment(
self,
segments: List[Segment],
metadata: dict
) -> List[str]:
# 调用 LLM 进行语义分段
# 使用统一的 SEGMENTATION_PROMPT
...
```
3. 更新 SemanticSegmentationEngine:
```python
class SemanticSegmentationEngine:
def __init__(
self,
strategy: Optional[SegmentationStrategy] = None,
fallback_segmenter: Optional['SemanticSegmenter'] = None
):
# 默认使用统一策略
self.strategy = strategy or UnifiedSegmentationStrategy()
self.fallback_segmenter = fallback_segmenter or SemanticSegmenter()
def segment(
self,
segments: List[Segment],
metadata: dict
) -> List[str]:
return self.strategy.segment(segments, metadata)
```
测试验证:
- 策略接口可扩展(可实现新策略)
- 统一策略适用于所有视频类型
- 策略切换不影响功能
</action>
<verify>
<automated>pytest tests/test_semantic_engine.py::test_strategy_extensibility -x</automated>
</verify>
<done>
- SegmentationStrategy Protocol 定义完成
- UnifiedSegmentationStrategy 实现完成
- SemanticSegmentationEngine 使用策略接口
- 测试验证策略可扩展性
</done>
</task>
</tasks>
<verification>
- pytest tests/test_semantic_engine.py -v 相关测试通过
- 策略接口清晰(Protocol 定义)
- 统一策略符合用户决策(无类型区分)
- 架构支持未来扩展
</verification>
<success_criteria>
1. SegmentationStrategy Protocol 定义完成
2. UnifiedSegmentationStrategy 实现完成
3. SemanticSegmentationEngine 使用策略接口
4. 测试验证策略可扩展性
</success_criteria>
<output>
After completion, create `.planning/phases/13-llm/13-06-SUMMARY.md`
</output>