codebase: cleaning cruft part 1

This commit is contained in:
ed
2026-07-05 13:46:35 -04:00
parent deae250019
commit 27f2c25f1c
22 changed files with 64 additions and 371 deletions
+17 -47
View File
@@ -51,8 +51,7 @@ from typing import Optional, Any
@dataclass(frozen=True)
class PathsConfig:
"""Immutable snapshot of resolved paths. Created ONCE per process.
[C: src/paths.py:initialize_paths, src/paths.py:_cfg]"""
"""Immutable snapshot of resolved paths. Created ONCE per process."""
config_path: Path
presets: Path
tool_presets: Path
@@ -72,8 +71,7 @@ _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]"""
callers that don't explicitly initialize (e.g., subprocess imports)."""
root_dir = Path(__file__).resolve().parent.parent
config_path = root_dir / "config.toml"
cfg = PathsConfig(
@@ -93,8 +91,7 @@ def _default_paths_config() -> PathsConfig:
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]"""
Idempotent. Subsequent calls to initialize_paths(<custom>) override this."""
global _PATHS_CONFIG
if _PATHS_CONFIG is None:
_PATHS_CONFIG = _default_paths_config()
@@ -135,8 +132,7 @@ def initialize_paths(config_path: Optional[Path] = None) -> PathsConfig:
TypeError: if config_path is not a Path
Returns:
The newly installed PathsConfig snapshot.
[C: src/paths.py:_cfg, tests/conftest.py:_setup_test_paths, sloppy.py:main]"""
The newly installed PathsConfig snapshot."""
global _PATHS_CONFIG
if config_path is None:
root_dir = Path(__file__).resolve().parent.parent
@@ -174,89 +170,68 @@ def _cfg() -> PathsConfig:
# === Trivial getters (single source of truth) ===
def get_config_path() -> Path:
"""Active config.toml path. Frozen at initialize_paths() time.
[C: src/app_controller.py:AppController.load_config,
src/app_controller.py:AppController.init_state,
src/models.py:_load_config_from_disk,
tests/test_test_sandbox.py]"""
"""Active config.toml path. Frozen at initialize_paths() time."""
return _cfg().config_path
def get_global_presets_path() -> Path:
"""Global presets file. Frozen at initialize_paths() time.
[C: src/presets.py:PresetManager.__init__, src/presets.py:PresetManager.delete_preset, src/presets.py:PresetManager.get_preset_scope]"""
"""Global presets file. Frozen at initialize_paths() time."""
return _cfg().presets
def get_project_presets_path(project_root: Path) -> Path:
"""Project-specific presets file. Computed from project_root (no cache).
[C: src/presets.py:PresetManager.delete_preset, src/presets.py:PresetManager.get_preset_scope, src/presets.py:PresetManager.project_path]"""
"""Project-specific presets file. Computed from project_root (no cache)."""
return project_root / "project_presets.toml"
def get_global_tool_presets_path() -> Path:
"""Global tool presets file. Frozen at initialize_paths() time.
[C: src/tool_presets.py:ToolPresetManager._get_path, src/tool_presets.py:ToolPresetManager.load_all_bias_profiles, src/tool_presets.py:ToolPresetManager.load_all_presets]"""
"""Global tool presets file. Frozen at initialize_paths() time."""
return _cfg().tool_presets
def get_project_tool_presets_path(project_root: Path) -> Path:
"""[C: src/tool_presets.py:ToolPresetManager._get_path, src/tool_presets.py:ToolPresetManager.load_all_bias_profiles, src/tool_presets.py:ToolPresetManager.load_all_presets]"""
return project_root / "project_tool_presets.toml"
def get_global_personas_path() -> Path:
"""Global personas file. Frozen at initialize_paths() time.
[C: src/personas.py:PersonaManager._get_path, src/personas.py:PersonaManager.get_persona_scope, src/personas.py:PersonaManager.load_all]"""
"""Global personas file. Frozen at initialize_paths() time."""
return _cfg().personas
def get_project_personas_path(project_root: Path) -> Path:
"""[C: src/personas.py:PersonaManager._get_path, src/personas.py:PersonaManager.get_persona_scope, src/personas.py:PersonaManager.load_all]"""
return project_root / "project_personas.toml"
def get_global_themes_path() -> Path:
"""Global themes directory. Frozen at initialize_paths() time.
[C: src/theme_2.py:load_themes_from_disk]"""
"""Global themes directory. Frozen at initialize_paths() time."""
return _cfg().themes
def get_layouts_dir() -> Path:
"""Global layouts directory. Frozen at initialize_paths() time.
[C: src/layouts.py:load_layouts_from_disk]"""
"""Global layouts directory. Frozen at initialize_paths() time."""
return _cfg().layouts
def get_project_themes_path(project_root: Path) -> Path:
"""[C: src/theme_2.py:load_themes_from_disk]"""
return project_root / "project_themes.toml"
def get_global_workspace_profiles_path() -> Path:
"""Global workspace profiles file. Frozen at initialize_paths() time.
[C: src/workspace_manager.py:WorkspaceManager._get_path, src/workspace_manager.py:WorkspaceManager.load_all_profiles]"""
"""Global workspace profiles file. Frozen at initialize_paths() time."""
return _cfg().workspace_profiles
def get_project_workspace_profiles_path(project_root: Path) -> Path:
"""[C: src/workspace_manager.py:WorkspaceManager._get_path, src/workspace_manager.py:WorkspaceManager.load_all_profiles]"""
return project_root / ".ai" / "workspace_profiles.toml"
def get_credentials_path() -> Path:
"""Global credentials file. Frozen at initialize_paths() time.
[C: src/mcp_client.py:_is_allowed]"""
"""Global credentials file. Frozen at initialize_paths() time."""
return _cfg().credentials
def get_logs_dir() -> Path:
"""Logs directory (contains session subdirs). Frozen at initialize_paths() time.
[C: src/session_logger.py:close_session, src/session_logger.py:open_session, tests/test_paths.py:test_config_overrides, tests/test_paths.py:test_default_paths, tests/test_paths.py:test_env_var_overrides, tests/test_paths.py:test_precedence]"""
"""Logs directory (contains session subdirs). Frozen at initialize_paths() time."""
return _cfg().logs_dir
def get_scripts_dir() -> Path:
"""Generated scripts directory. Frozen at initialize_paths() time.
[C: src/session_logger.py:log_tool_call, src/session_logger.py:open_session, tests/test_paths.py:test_config_overrides, tests/test_paths.py:test_default_paths]"""
"""Generated scripts directory. Frozen at initialize_paths() time."""
return _cfg().scripts_dir
def get_tracks_dir(project_path: Optional[str] = None) -> Path:
"""[C: src/project_manager.py:get_all_tracks, tests/test_paths.py:test_conductor_dir_project_relative]"""
return get_conductor_dir(project_path) / "tracks"
def get_track_state_dir(track_id: str, project_path: Optional[str] = None) -> Path:
"""[C: src/project_manager.py:load_track_state, src/project_manager.py:save_track_state, tests/test_paths.py:test_conductor_dir_project_relative]"""
return get_tracks_dir(project_path) / track_id
def get_archive_dir(project_path: Optional[str] = None) -> Path:
"""[C: tests/test_paths.py:test_conductor_dir_project_relative]"""
return get_conductor_dir(project_path) / "archive"
@@ -278,7 +253,6 @@ def _get_project_conductor_dir_from_toml(project_root: Path) -> Path:
def get_conductor_dir(project_path: Optional[str] = None) -> Path:
"""[C: tests/test_paths.py:test_conductor_dir_project_relative, tests/test_project_paths.py:test_get_conductor_dir_default, tests/test_project_paths.py:test_get_conductor_dir_project_specific_with_toml]"""
if not project_path:
return Path('conductor').resolve()
project_root = Path(project_path).resolve()
@@ -290,8 +264,7 @@ def get_conductor_dir(project_path: Optional[str] = None) -> Path:
def get_full_path_info() -> dict[str, dict[str, Any]]:
"""Return the resolved paths + their source (env / config / default).
For diagnostic UIs (e.g., the Session Hub's "show resolved paths" panel).
[C: src/gui_2.py:App._render_path_field]"""
For diagnostic UIs (e.g., the Session Hub's "show resolved paths" panel)."""
cfg = _cfg()
def info(value: Path) -> dict[str, Any]:
return {'path': str(value), 'source': 'frozen_at_init'}
@@ -311,10 +284,7 @@ def get_full_path_info() -> dict[str, dict[str, Any]]:
def reset_paths() -> None:
"""Clear the singleton. FOR TESTS ONLY — production code should never
call this. After reset, the next path getter raises RuntimeError until
initialize_paths() is called again.
[C: tests/conftest.py:reset_paths, tests/test_paths.py:reset_paths,
tests/test_app_controller_offloading.py:setup_function,
tests/test_gui_phase3.py:setup]"""
initialize_paths() is called again."""
global _PATHS_CONFIG
with _PATHS_LOCK:
_PATHS_CONFIG = None