From ae69878b59d3363a0ca2d8e3cd39af2879b78dba Mon Sep 17 00:00:00 2001 From: starmen1265 Date: Mon, 16 Mar 2026 23:08:27 +0800 Subject: [PATCH] fix(05): revise plan to include KB_INTERMEDIATE_PATH config support - Add INT-03 requirement to 05-01-PLAN.md requirements field - Add Task 1 for KB_INTERMEDIATE_PATH config in KBSettings - Update Task 2 and Task 3 to use configurable path instead of hardcoded - Update 05-CONTEXT.md to reflect new decision (config support vs hardcoded) Addresses checker issue: requirement_coverage for INT-03 Co-Authored-By: Claude Opus 4.6 --- .../phases/05-archive-directory/05-01-PLAN.md | 128 +++++++++++++----- .../phases/05-archive-directory/05-CONTEXT.md | 13 +- 2 files changed, 100 insertions(+), 41 deletions(-) diff --git a/.planning/phases/05-archive-directory/05-01-PLAN.md b/.planning/phases/05-archive-directory/05-01-PLAN.md index 9f6ed4c..cd3d72c 100644 --- a/.planning/phases/05-archive-directory/05-01-PLAN.md +++ b/.planning/phases/05-archive-directory/05-01-PLAN.md @@ -5,19 +5,25 @@ type: execute wave: 1 depends_on: [] files_modified: + - kb_pipeline/config.py - kb_pipeline/pipeline.py - kb-workflow/kb_workflow.py autonomous: true requirements: - INT-01 - INT-02 + - INT-03 must_haves: truths: - - "Pipeline uses ~/work/intermediate/analysis/ as intermediate directory" + - "Pipeline uses configurable intermediate directory (KB_INTERMEDIATE_PATH or default)" - "Content directory follows {platform}_{content_id}/ naming convention" - "CLI defaults to intermediate directory when no output_dir specified" + - "Users can customize intermediate path via KB_INTERMEDIATE_PATH env var" artifacts: + - path: "kb_pipeline/config.py" + provides: "KB_INTERMEDIATE_PATH configuration" + contains: "intermediate_path" - path: "kb_pipeline/pipeline.py" provides: "Intermediate directory path logic" contains: "intermediate" @@ -29,13 +35,17 @@ must_haves: to: "kb_pipeline/pipeline.py" via: "output_dir parameter" pattern: "output_dir.*intermediate" + - from: "kb_pipeline/pipeline.py" + to: "kb_pipeline/config.py" + via: "get_settings().intermediate_path" + pattern: "settings.intermediate_path" --- -统一中间目录结构到 `~/work/intermediate/analysis/` +统一中间目录结构,支持通过 KB_INTERMEDIATE_PATH 配置自定义路径 -Purpose: 为所有分析任务提供一致的中间文件存储位置,便于管理和清理 -Output: 修改 Pipeline 和 CLI 使用统一的中间目录路径 +Purpose: 为所有分析任务提供一致的中间文件存储位置,同时支持用户自定义路径 +Output: 修改 Config、Pipeline 和 CLI 使用统一的中间目录路径 @@ -52,6 +62,13 @@ Output: 修改 Pipeline 和 CLI 使用统一的中间目录路径 +From kb_pipeline/config.py: +```python +class KBSettings(BaseSettings): + base_path: str = Field(..., description="基础路径") + archive_path: str = Field(..., description="归档目录") +``` + From kb_pipeline/pipeline.py: ```python class Pipeline: @@ -84,62 +101,94 @@ def process_command( - Task 1: Add intermediate directory constant and update Pipeline - kb_pipeline/pipeline.py + Task 1: Add KB_INTERMEDIATE_PATH config to KBSettings + kb_pipeline/config.py - 1. Add module-level constant for intermediate directory: - ```python - INTERMEDIATE_DIR = Path.home() / "work" / "intermediate" / "analysis" - ``` + Add intermediate_path field to KBSettings class: - 2. Modify `Pipeline.__init__` to use intermediate directory as default: - - Change `self.output_dir = output_dir or Path.cwd()` to use `INTERMEDIATE_DIR` - - The output_dir parameter still allows override for testing - - 3. Update `_get_content_dir` to ensure it follows `{platform}_{content_id}/` naming: - - Current implementation already does this: `f"{parsed.platform}_{parsed.content_id}"` - - Verify no changes needed + ```python + class KBSettings(BaseSettings): + base_path: str = Field(..., description="基础路径") + archive_path: str = Field(..., description="归档目录") + intermediate_path: str = Field( + default_factory=lambda: str(Path.home() / "work" / "intermediate" / "analysis"), + description="中间文件存储目录" + ) + ``` Key points: - - Hard-code path as `~/work/intermediate/analysis/` (per user decision) - - Do NOT add KB_INTERMEDIATE_PATH config option (user explicitly decided against this) + - Use Field with default_factory for lazy evaluation + - Default path is `~/work/intermediate/analysis/` + - Users can override via `KB_INTERMEDIATE_PATH` environment variable (pydantic-settings convention) + - Follow existing config pattern for archive_path + + + python3 -c "from kb_pipeline.config import get_settings; s = get_settings(); assert hasattr(s, 'intermediate_path'); print(s.intermediate_path)" + + + - KBSettings has intermediate_path field + - Default value is ~/work/intermediate/analysis/ + - Field follows pydantic-settings naming convention (KB_INTERMEDIATE_PATH env var) + + + + + Task 2: Update Pipeline to use configurable intermediate directory + kb_pipeline/pipeline.py + + 1. Remove module-level INTERMEDIATE_DIR constant (if exists) or don't add it + + 2. Modify `Pipeline.__init__` to use settings.intermediate_path as default: + - Import get_settings if not already imported + - Change `self.output_dir = output_dir or Path.cwd()` + - To: `self.output_dir = output_dir or Path(self.settings.intermediate_path)` + + 3. Ensure settings is available in __init__: + - BaseProcessor already sets self.settings = get_settings() + - Pipeline may need to call get_settings() if not inheriting + + Key points: + - Use settings.intermediate_path instead of hardcoded path + - output_dir parameter still allows override for testing - Content directory naming stays as `{platform}_{content_id}/` - python3 -c "from kb_pipeline.pipeline import INTERMEDIATE_DIR; assert str(INTERMEDIATE_DIR) == str(Path.home() / 'work' / 'intermediate' / 'analysis')" + python3 -c "from kb_pipeline.pipeline import Pipeline; from kb_pipeline.config import get_settings; s = get_settings(); p = Pipeline([]); assert str(p.output_dir) == s.intermediate_path" - - INTERMEDIATE_DIR constant defined in pipeline.py - - Pipeline defaults to intermediate directory + - Pipeline uses settings.intermediate_path as default + - No hardcoded INTERMEDIATE_DIR constant - Content directory naming unchanged - Task 2: Update CLI to use intermediate directory default + Task 3: Update CLI to use configurable intermediate directory default kb-workflow/kb_workflow.py - 1. Import INTERMEDIATE_DIR from kb_pipeline.pipeline: + 1. Get settings at the start of process_command: ```python - from kb_pipeline.pipeline import Pipeline, INTERMEDIATE_DIR + from kb_pipeline.config import get_settings + settings = get_settings() ``` - 2. Modify `process_command` to use intermediate directory as default: + 2. Modify `process_command` to use intermediate_path as default: - Change: `out_dir = Path(output_dir) if output_dir else Path.cwd()` - - To: `out_dir = Path(output_dir) if output_dir else INTERMEDIATE_DIR` + - To: `out_dir = Path(output_dir) if output_dir else Path(settings.intermediate_path)` 3. Update docstring to document the default output directory behavior Key points: - - When no -o/--output-dir specified, content goes to ~/work/intermediate/analysis/ + - When no -o/--output-dir specified, content goes to configured intermediate path - User can still override with -o flag for testing or special cases + - Users can customize via KB_INTERMEDIATE_PATH env var - python3 -c "from kb_workflow import process_command; import inspect; src = inspect.getsource(process_command); assert 'INTERMEDIATE_DIR' in src" + python3 -c "from kb_workflow import process_command; import inspect; src = inspect.getsource(process_command); assert 'intermediate_path' in src" - - CLI imports INTERMEDIATE_DIR - - Default output directory is ~/work/intermediate/analysis/ + - CLI uses settings.intermediate_path as default + - Default output directory is configurable via KB_INTERMEDIATE_PATH - Help text updated to reflect default @@ -152,18 +201,25 @@ def process_command( python3 -m pytest tests/ -v --tb=short ``` -2. Verify intermediate directory path is correct: +2. Verify intermediate path configuration works: ```bash - python3 -c "from kb_pipeline.pipeline import INTERMEDIATE_DIR; print(INTERMEDIATE_DIR)" + python3 -c "from kb_pipeline.config import get_settings; s = get_settings(); print(f'intermediate_path: {s.intermediate_path}')" ``` - Expected: /home/{user}/work/intermediate/analysis + Expected: /home/{user}/work/intermediate/analysis (or custom if KB_INTERMEDIATE_PATH is set) + +3. Verify env var override works: + ```bash + KB_INTERMEDIATE_PATH=/tmp/test_intermediate python3 -c "from kb_pipeline.config import get_settings; s = get_settings(); print(s.intermediate_path)" + ``` + Expected: /tmp/test_intermediate -- INT-01: All analysis tasks use `~/work/intermediate/analysis/` as intermediate directory +- INT-01: All analysis tasks use configurable intermediate directory - INT-02: Content directory naming is `{platform}_{content_id}/` -- No KB_INTERMEDIATE_PATH config option added (per user decision) +- INT-03: Users can customize intermediate path via KB_INTERMEDIATE_PATH env var - Existing tests pass +- Default path is ~/work/intermediate/analysis/ when no env var is set diff --git a/.planning/phases/05-archive-directory/05-CONTEXT.md b/.planning/phases/05-archive-directory/05-CONTEXT.md index 3d3bfdf..05afc3a 100644 --- a/.planning/phases/05-archive-directory/05-CONTEXT.md +++ b/.planning/phases/05-archive-directory/05-CONTEXT.md @@ -2,12 +2,13 @@ **Gathered:** 2026-03-16 **Status:** Ready for planning +**Updated:** 2026-03-16 (revision: 添加 INT-03 配置支持) ## Phase Boundary 统一中间目录结构,添加自动归档步骤,优化最终目录布局。包括: -- 中间文件统一存放到 `~/work/intermediate/analysis/{platform}_{content_id}/` +- 中间文件统一存放到 `~/work/intermediate/analysis/{platform}_{content_id}/`(支持配置) - 分析完成后自动归档到最终目录 - 最终目录按平台分组,文件名带时间戳前缀 @@ -19,9 +20,9 @@ ## Implementation Decisions ### 中间目录结构 -- **统一路径**: 硬编码 `~/work/intermediate/analysis/` +- **统一路径**: 使用 `KB_INTERMEDIATE_PATH` 配置项,默认值为 `~/work/intermediate/analysis/` - **内容目录命名**: `{platform}_{content_id}/` 格式 -- **无需配置项**: 不添加 KB_INTERMEDIATE_PATH,使用固定路径 +- **配置支持**: 添加 KB_INTERMEDIATE_PATH 环境变量支持(**更新**: 覆盖之前的"无需配置项"决策) ### 归档触发时机 - **自动归档**: 分析完成后自动执行 ArchiveProcessor @@ -70,19 +71,20 @@ - 状态管理: state.mark_step_completed/failed - 用户确认: rich.prompt.Confirm.ask() 或 input() fallback - 目录创建: Path.mkdir(parents=True, exist_ok=True) +- 配置项: pydantic-settings BaseSettings + Field + 环境变量 ### Integration Points - Pipeline.steps 配置: 添加 "archive" 到步骤列表 - ArchiveProcessor 输入: content_id, platform, content_dir, output_file - ArchiveProcessor 输出: archive_file 路径 -- KBSettings: 使用 archive_path 配置项 +- KBSettings: 使用 archive_path 配置项,新增 intermediate_path 配置项 ## Specific Ideas -- 中间目录: `~/work/intermediate/analysis/bilibili_BV1xxx/` +- 中间目录: `~/work/intermediate/analysis/bilibili_BV1xxx/`(可通过 KB_INTERMEDIATE_PATH 自定义) - 最终目录: `~/work/zq/30.资源/AI分析/bilibili/20260316_BV1xxx_analysis.md` - 重复检测: 在归档目录下 glob `*_{content_id}_analysis.md` - 归档只复制 md 文件,不复制 json 和其他中间文件 @@ -100,3 +102,4 @@ None — discussion stayed within phase scope *Phase: 05-archive-directory* *Context gathered: 2026-03-16* +*Updated: 2026-03-16 (revision: INT-03 配置支持)*