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

256 lines
7.9 KiB
Markdown

---
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\\."
---
<objective>
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.
</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/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
<interfaces>
<!-- Key types from existing code. Executor should use these directly. -->
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
```
</interfaces>
</context>
<tasks>
<task type="auto" tdd="true">
<name>Task 1: Define Analyze Schemas</name>
<files>kb_pipeline/schemas.py, tests/test_processors/test_analyze.py</files>
<behavior>
- Test 1: AnalyzeInput validates required fields
- Test 2: AnalyzeOutput validates required fields
- Test 3: AnalyzeOutput handles both video and article content types
</behavior>
<action>
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.
</action>
<verify>
<automated>pytest tests/test_processors/test_analyze.py -v -x -k "test_schema"</automated>
</verify>
<done>AnalyzeInput/AnalyzeOutput schemas defined and validated</done>
</task>
<task type="auto" tdd="true">
<name>Task 2: Create AnalyzeProcessor with DeepAnalyzer integration</name>
<files>kb_pipeline/processors/analyze.py, tests/test_processors/test_analyze.py</files>
<behavior>
- 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
</behavior>
<action>
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.
</action>
<verify>
<automated>pytest tests/test_processors/test_analyze.py -v -x</automated>
</verify>
<done>AnalyzeProcessor generates analysis reports using DeepAnalyzer</done>
</task>
<task type="auto">
<name>Task 3: Update processors __init__.py</name>
<files>kb_pipeline/processors/__init__.py</files>
<action>
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"]
```
</action>
<verify>
<automated>python -c "from kb_pipeline.processors import AnalyzeProcessor; print('OK')"</automated>
</verify>
<done>AnalyzeProcessor exported from processors module</done>
</task>
</tasks>
<verification>
- 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
</verification>
<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>
<output>
After completion, create `.planning/phases/04-analysis-orchestration/04-03-SUMMARY.md`
</output>