--- phase: 04-analysis-orchestration plan: 03 type: execute wave: 3 depends_on: [04-01, 04-02] files_modified: - kb_pipeline/processors/analyze.py - kb_pipeline/schemas.py - tests/test_processors/test_analyze.py autonomous: true requirements: [MNT-01] user_setup: [] must_haves: truths: - "AnalyzeProcessor generates AI analysis reports" - "Analysis reports are saved as Markdown files" - "AnalyzeProcessor wraps existing DeepAnalyzer" artifacts: - path: "kb_pipeline/processors/analyze.py" provides: "AnalyzeProcessor implementation" contains: "class AnalyzeProcessor" min_lines: 100 - path: "kb_pipeline/schemas.py" provides: "AnalyzeInput/AnalyzeOutput schemas" contains: "class AnalyzeInput" - path: "tests/test_processors/test_analyze.py" provides: "Comprehensive test suite" contains: "test_analyze_processor" key_links: - from: "kb_pipeline/processors/analyze.py" to: "kb-deep-analyzer/deep_analyzer.py" via: "DeepAnalyzer class import" pattern: "from.*deep_analyzer.*import" - from: "kb_pipeline/processors/analyze.py" to: "kb_pipeline/state.py" via: "WorkflowStateManager" pattern: "state_manager\\." --- Create AnalyzeProcessor to wrap existing DeepAnalyzer and integrate it into the unified processor pipeline. Purpose: Provide AI-powered content analysis that generates structured reports as Markdown files. Output: AnalyzeProcessor implementation with DeepAnalyzer integration. @/home/starmen1265/.claude/get-shit-done/workflows/execute-plan.md @/home/starmen1265/.claude/get-shit-done/templates/summary.md @.planning/PROJECT.md @.planning/ROADMAP.md @.planning/STATE.md @.planning/phases/04-analysis-orchestration/04-CONTEXT.md @.planning/phases/04-analysis-orchestration/04-RESEARCH.md @.planning/phases/04-analysis-orchestration/04-01-SUMMARY.md @.planning/phases/04-analysis-orchestration/04-02-SUMMARY.md From kb-deep-analyzer/deep_analyzer.py: ```python class SimpleAIClient: def __init__(self, api_key: str = None, provider: str = None, model: str = None, base_url: str = None): ... def generate(self, prompt: str, max_tokens: int = 16000) -> str: ... class DeepAnalyzer: def __init__(self, ai_client: SimpleAIClient = None): ... def analyze(self, metadata: Dict[str, Any], content: Dict[str, Any], content_type: str = "video") -> AnalysisResult: ... @dataclass class AnalysisResult: summary: str = "" main_topics: List[str] = field(default_factory=list) key_insights: List[str] = field(default_factory=list) recommended_tags: List[str] = field(default_factory=list) full_analysis: str = "" original_text: str = "" def generate_frontmatter(metadata: Dict, result: AnalysisResult, content_type: str = "video") -> str: ... ``` From kb_pipeline/schemas.py (after 04-01 and 04-02): ```python class StepInput(BaseModel): content_id: str platform: Literal["bilibili", "zhihu"] class StepOutput(BaseModel): success: bool error_message: Optional[str] completed_at: datetime ``` From kb_pipeline/processors/base.py (from 04-01): ```python class BaseProcessor(ABC): STEP_NAME: str async def process(self, input_data: StepInput) -> StepOutput ``` Task 1: Define Analyze Schemas kb_pipeline/schemas.py, tests/test_processors/test_analyze.py - Test 1: AnalyzeInput validates required fields - Test 2: AnalyzeOutput validates required fields - Test 3: AnalyzeOutput handles both video and article content types Add AnalyzeInput and AnalyzeOutput schemas to kb_pipeline/schemas.py. **AnalyzeInput fields (extends StepInput):** - metadata_file: str - Path to metadata JSON file - content_file: str - Path to content file (subtitle JSON or article content) - content_type: str - Type of content (video or article) - output_file: str - Path to output analysis Markdown file **AnalyzeOutput fields (extends StepOutput):** - analysis_file: str - Path to generated analysis report - summary: str - Content summary - main_topics: List[str] - Main topics extracted - key_insights: List[str] - Key insights - tags: List[str] - Recommended tags - stats: Dict[str, Any] - Statistics about analysis Create test file with schema validation tests. pytest tests/test_processors/test_analyze.py -v -x -k "test_schema" AnalyzeInput/AnalyzeOutput schemas defined and validated Task 2: Create AnalyzeProcessor with DeepAnalyzer integration kb_pipeline/processors/analyze.py, tests/test_processors/test_analyze.py - Test 1: AnalyzeProcessor loads metadata and content from files - Test 2: AnalyzeProcessor calls DeepAnalyzer.analyze() with correct parameters - Test 3: AnalyzeProcessor saves analysis report as Markdown - Test 4: AnalyzeProcessor records state on success - Test 5: AnalyzeProcessor records state on failure Create `kb_pipeline/processors/analyze.py` with AnalyzeProcessor class. **Implementation:** 1. Import BaseProcessor from .base 2. Import DeepAnalyzer, SimpleAIClient, AnalysisResult, generate_frontmatter from kb_deep_analyzer 3. Import AnalyzeInput, AnalyzeOutput from ..schemas 4. Create AnalyzeProcessor(BaseProcessor): - STEP_NAME = "analyze" - __init__ with state_manager, settings (initialize AI client lazily) - process() method that: a. Checks if step already completed (skip if done) b. Loads metadata JSON file c. Loads content JSON/text file d. Initializes SimpleAIClient with settings e. Creates DeepAnalyzer instance f. Calls analyzer.analyze(metadata, content, content_type) g. Generates frontmatter using generate_frontmatter() h. Writes analysis report as Markdown i. Records state on success/failure **Output file format:** ```markdown --- title: "..." date: ... author: ... tags: [...] --- ## 标题 ... ## 摘要 ... ## 主要主题 ... ## 关键见解 ... ## 时间轴 (for video only) ... ``` Create comprehensive tests with mocked DeepAnalyzer. pytest tests/test_processors/test_analyze.py -v -x AnalyzeProcessor generates analysis reports using DeepAnalyzer Task 3: Update processors __init__.py kb_pipeline/processors/__init__.py Update `kb_pipeline/processors/__init__.py` to export AnalyzeProcessor. ```python from .base import BaseProcessor from .parse import ParseProcessor from .download import DownloadProcessor from .asr import ASRProcessor from .analyze import AnalyzeProcessor __all__ = ["BaseProcessor", "ParseProcessor", "DownloadProcessor", "ASRProcessor", "AnalyzeProcessor"] ``` python -c "from kb_pipeline.processors import AnalyzeProcessor; print('OK')" AnalyzeProcessor exported from processors module - All tests pass: `pytest tests/test_processors/test_analyze.py -v` - AnalyzeProcessor correctly wraps DeepAnalyzer - Analysis reports are saved as Markdown files - Frontmatter is generated correctly - State recording works for both success and failure cases - AnalyzeProcessor inherits from BaseProcessor - AnalyzeInput/AnalyzeOutput schemas exist and validate - DeepAnalyzer is integrated correctly (no modifications to existing code) - Analysis reports are saved with proper frontmatter - All tests pass After completion, create `.planning/phases/04-analysis-orchestration/04-03-SUMMARY.md`