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