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/04-analysis-orchestration/04-03-PLAN.md
T

7.9 KiB

phase, plan, type, wave, depends_on, files_modified, autonomous, requirements, user_setup, must_haves
phase plan type wave depends_on files_modified autonomous requirements user_setup must_haves
04-analysis-orchestration 03 execute 3
04-01
04-02
kb_pipeline/processors/analyze.py
kb_pipeline/schemas.py
tests/test_processors/test_analyze.py
true
MNT-01
truths artifacts key_links
AnalyzeProcessor generates AI analysis reports
Analysis reports are saved as Markdown files
AnalyzeProcessor wraps existing DeepAnalyzer
path provides contains min_lines
kb_pipeline/processors/analyze.py AnalyzeProcessor implementation class AnalyzeProcessor 100
path provides contains
kb_pipeline/schemas.py AnalyzeInput/AnalyzeOutput schemas class AnalyzeInput
path provides contains
tests/test_processors/test_analyze.py Comprehensive test suite test_analyze_processor
from to via pattern
kb_pipeline/processors/analyze.py kb-deep-analyzer/deep_analyzer.py DeepAnalyzer class import from.*deep_analyzer.*import
from to via pattern
kb_pipeline/processors/analyze.py kb_pipeline/state.py WorkflowStateManager 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.

<execution_context> @/home/starmen1265/.claude/get-shit-done/workflows/execute-plan.md @/home/starmen1265/.claude/get-shit-done/templates/summary.md </execution_context>

@.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:

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):

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):

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:

---
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.
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

<success_criteria>

  • 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 </success_criteria>
After completion, create `.planning/phases/04-analysis-orchestration/04-03-SUMMARY.md`