feat(gui): Add Path Configuration panel to Context Hub
This commit is contained in:
57
src/paths.py
57
src/paths.py
@@ -45,7 +45,7 @@ See Also:
|
||||
from pathlib import Path
|
||||
import os
|
||||
import tomllib
|
||||
from typing import Optional
|
||||
from typing import Optional, Any
|
||||
|
||||
_RESOLVED: dict[str, Path] = {}
|
||||
|
||||
@@ -105,20 +105,42 @@ def _get_project_conductor_dir_from_toml(project_root: Path) -> Optional[Path]:
|
||||
if c_dir:
|
||||
p = Path(c_dir)
|
||||
if not p.is_absolute(): p = project_root / p
|
||||
return p
|
||||
return p.resolve()
|
||||
except: pass
|
||||
return None
|
||||
|
||||
def get_conductor_dir(project_path: Optional[str] = None) -> Path:
|
||||
if project_path:
|
||||
project_root = Path(project_path)
|
||||
project_root = Path(project_path).resolve()
|
||||
p = _get_project_conductor_dir_from_toml(project_root)
|
||||
if p: return p
|
||||
return project_root / 'conductor'
|
||||
|
||||
if "conductor_dir" not in _RESOLVED:
|
||||
_RESOLVED["conductor_dir"] = _resolve_path("SLOP_CONDUCTOR_DIR", "conductor_dir", "conductor")
|
||||
return _RESOLVED["conductor_dir"]
|
||||
# Check env and config
|
||||
root_dir = Path(__file__).resolve().parent.parent
|
||||
env_val = os.environ.get("SLOP_CONDUCTOR_DIR")
|
||||
if env_val:
|
||||
p = Path(env_val)
|
||||
if not p.is_absolute(): p = root_dir / p
|
||||
_RESOLVED["conductor_dir"] = p.resolve()
|
||||
else:
|
||||
try:
|
||||
with open(get_config_path(), "rb") as f:
|
||||
cfg = tomllib.load(f)
|
||||
if "paths" in cfg and "conductor_dir" in cfg["paths"]:
|
||||
p = Path(cfg["paths"]["conductor_dir"])
|
||||
if not p.is_absolute(): p = root_dir / p
|
||||
_RESOLVED["conductor_dir"] = p.resolve()
|
||||
except: pass
|
||||
|
||||
if "conductor_dir" in _RESOLVED:
|
||||
return _RESOLVED["conductor_dir"]
|
||||
|
||||
if project_path:
|
||||
return (Path(project_path).resolve() / "conductor").resolve()
|
||||
|
||||
root_dir = Path(__file__).resolve().parent.parent
|
||||
return (root_dir / "conductor").resolve()
|
||||
|
||||
def get_logs_dir() -> Path:
|
||||
if "logs_dir" not in _RESOLVED:
|
||||
@@ -139,6 +161,29 @@ def get_track_state_dir(track_id: str, project_path: Optional[str] = None) -> Pa
|
||||
def get_archive_dir(project_path: Optional[str] = None) -> Path:
|
||||
return get_conductor_dir(project_path) / "archive"
|
||||
|
||||
def _resolve_path_info(env_var: str, config_key: str, default: str) -> dict[str, Any]:
|
||||
if env_var in os.environ:
|
||||
return {'path': Path(os.environ[env_var]).resolve(), 'source': f'env:{env_var}'}
|
||||
try:
|
||||
with open(get_config_path(), 'rb') as f:
|
||||
cfg = tomllib.load(f)
|
||||
if 'paths' in cfg and config_key in cfg['paths']:
|
||||
p = Path(cfg['paths'][config_key])
|
||||
if not p.is_absolute():
|
||||
p = (Path(__file__).resolve().parent.parent / p).resolve()
|
||||
return {'path': p, 'source': 'config.toml'}
|
||||
except: pass
|
||||
root_dir = Path(__file__).resolve().parent.parent
|
||||
p = (root_dir / default).resolve()
|
||||
return {'path': p, 'source': 'default'}
|
||||
|
||||
def get_full_path_info() -> dict[str, dict[str, Any]]:
|
||||
return {
|
||||
'conductor_dir': _resolve_path_info('SLOP_CONDUCTOR_DIR', 'conductor_dir', 'conductor'),
|
||||
'logs_dir': _resolve_path_info('SLOP_LOGS_DIR', 'logs_dir', 'logs/sessions'),
|
||||
'scripts_dir': _resolve_path_info('SLOP_SCRIPTS_DIR', 'scripts_dir', 'scripts/generated')
|
||||
}
|
||||
|
||||
def reset_resolved() -> None:
|
||||
"""For testing only - clear cached resolutions."""
|
||||
_RESOLVED.clear()
|
||||
|
||||
Reference in New Issue
Block a user