diff --git a/src/cli/blackboard.py b/src/cli/blackboard.py index 8c1aa9d..44512be 100644 --- a/src/cli/blackboard.py +++ b/src/cli/blackboard.py @@ -9,32 +9,13 @@ from pathlib import Path from typing import List, Optional from src.blackboard.operations import Blackboard -from src.blackboard.models import Task, Comment, Output, Decision, Observation, Review, Experience +from src.utils import get_data_root, Comment, Output, Decision, Observation, Review, Experience from src.blackboard.queries import Queries from src.blackboard.registry import ProjectRegistry def _find_project_root() -> Path: - """从环境变量、配置文件或默认路径找项目根目录""" - import os - # 1. 环境变量最高优先级 - root = os.environ.get("BLACKBOARD_ROOT") - if root: - return Path(root) - # 2. 从 config/default.yaml 读取 - try: - import yaml - config_path = Path(__file__).parent.parent / "config" / "default.yaml" - if config_path.exists(): - with open(config_path) as f: - cfg = yaml.safe_load(f) or {} - data_root = cfg.get("data_root") - if data_root: - return Path(data_root).expanduser() - except Exception: - pass - # 3. 相对于源码目录的 data/ - return Path(__file__).parent.parent / "data" + return get_data_root() def _get_bb(project_id: str) -> Blackboard: diff --git a/src/main.py b/src/main.py index 1577a6b..f55258c 100644 --- a/src/main.py +++ b/src/main.py @@ -14,6 +14,7 @@ from fastapi.staticfiles import StaticFiles from src.blackboard.registry import ProjectRegistry from src.daemon.ticker import Ticker +from src.utils import get_data_root logger = logging.getLogger("moziplus-v2") @@ -38,7 +39,7 @@ config = load_config() # 全局组件 # --------------------------------------------------------------------------- -DATA_ROOT = Path(config.get("data_root", Path(__file__).parent.parent / "data")) +DATA_ROOT = get_data_root() ticker: Optional[Ticker] = None