fix(paths): module-level default init so subprocess imports don't crash

This commit is contained in:
ed
2026-06-19 10:55:54 -04:00
parent 83722bc0e8
commit e1d4c1dc9d
2 changed files with 58 additions and 3 deletions
+33
View File
@@ -68,6 +68,39 @@ _PATHS_CONFIG: Optional[PathsConfig] = None
_PATHS_LOCK = threading.RLock()
def _default_paths_config() -> PathsConfig:
"""Build the default PathsConfig (no [paths] overrides, just defaults).
Called once at module load to ensure _PATHS_CONFIG is never None for
callers that don't explicitly initialize (e.g., subprocess imports).
[C: src/paths.py:initialize_paths, src/paths.py:_module_init_default]"""
root_dir = Path(__file__).resolve().parent.parent
config_path = root_dir / "config.toml"
cfg = PathsConfig(
config_path = config_path,
presets = root_dir / "presets.toml",
tool_presets = root_dir / "tool_presets.toml",
personas = root_dir / "personas.toml",
themes = root_dir / "themes",
workspace_profiles = root_dir / "workspace_profiles.toml",
credentials = root_dir / "credentials.toml",
logs_dir = root_dir / "logs" / "sessions",
scripts_dir = root_dir / "scripts" / "generated",
)
return cfg
def _module_init_default() -> None:
"""Initialize _PATHS_CONFIG with defaults at module load.
Idempotent. Subsequent calls to initialize_paths(<custom>) override this.
[C: src/paths.py:initialize_paths, src/paths.py:reset_paths]"""
global _PATHS_CONFIG
if _PATHS_CONFIG is None:
_PATHS_CONFIG = _default_paths_config()
_module_init_default()
def _resolve_path(env_var: str, config_key: str, default: Path, config_path: Path) -> Path:
"""Internal: resolve one path from env var -> config [paths] -> default.
Called only from initialize_paths(). Not thread-safe; caller holds lock."""