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
+4 -32
View File
@@ -50,7 +50,6 @@ def parse_ts_result(s: str) -> Result[datetime.datetime]:
def entry_to_str(entry: Metadata) -> str:
"""
Serialise a disc entry dict -> stored string.
[C: tests/test_thinking_persistence.py:test_entry_to_str_with_thinking]
"""
ts = entry.get("ts", "")
role = entry.get("role", "User")
@@ -76,7 +75,6 @@ def format_discussion(entries: list[Metadata]) -> str:
def str_to_entry(raw: str, roles: list[str]) -> Metadata:
"""
Parse a stored string back to a disc entry dict.
[C: tests/test_thinking_persistence.py:test_str_to_entry_with_thinking]
"""
ts = ""
rest = raw
@@ -116,15 +114,9 @@ def get_git_commit(git_dir: str) -> str:
# ── default structures ───────────────────────────────────────────────────────
def default_discussion() -> Metadata:
"""
[C: tests/test_discussion_takes.py:TestDiscussionTakes.test_promote_take_renames_discussion]
"""
return {"git_commit": "", "last_updated": now_ts(), "history": []}
def default_project(name: str = "unnamed") -> Metadata:
"""
[C: tests/test_deepseek_infra.py:test_default_project_includes_reasoning_role, tests/test_discussion_takes.py:TestDiscussionTakes.setUp, tests/test_history_management.py:test_history_persistence_across_turns, tests/test_history_management.py:test_save_separation, tests/test_project_manager_modes.py:test_default_project_execution_mode, tests/test_project_manager_modes.py:test_load_save_execution_mode, tests/test_project_serialization.py:TestProjectSerialization.test_default_roles_include_context, tests/test_project_serialization.py:TestProjectSerialization.test_fileitem_roundtrip]
"""
return {
"project": {"name": name, "git_dir": "", "system_prompt": "", "execution_mode": "native"},
"output": {"output_dir": "./md_gen"},
@@ -177,10 +169,7 @@ def default_project(name: str = "unnamed") -> Metadata:
# ── load / save ──────────────────────────────────────────────────────────────
def get_history_path(project_path: Union[str, Path]) -> Path:
"""
Return the Path to the sibling history TOML file for a given project.
[C: tests/test_history_management.py:test_save_separation]
"""
"""Return the Path to the sibling history TOML file for a given project."""
p = Path(project_path)
return p.parent / f"{p.stem}_history.toml"
@@ -188,7 +177,6 @@ def load_project(path: Union[str, Path]) -> Metadata:
"""
Load a project TOML file.
Automatically migrates legacy 'discussion' keys to a sibling history file.
[C: tests/test_history_management.py:test_history_persistence_across_turns, tests/test_history_management.py:test_migration_on_load, tests/test_project_manager_modes.py:test_load_save_execution_mode, tests/test_project_serialization.py:TestProjectSerialization.test_backward_compatibility_strings, tests/test_project_serialization.py:TestProjectSerialization.test_fileitem_roundtrip]
"""
with open(path, "rb") as f: proj = tomllib.load(f)
# Deserialise FileItems in files.paths
@@ -208,10 +196,7 @@ def load_project(path: Union[str, Path]) -> Metadata:
return proj
def load_history(project_path: Union[str, Path]) -> Metadata:
"""
Load the segregated discussion history from its dedicated TOML file.
[C: tests/test_thinking_persistence.py:test_save_and_load_history_with_thinking_segments]
"""
"""Load the segregated discussion history from its dedicated TOML file."""
hist_path = get_history_path(project_path)
if hist_path.exists():
with open(hist_path, "rb") as f:
@@ -219,10 +204,7 @@ def load_history(project_path: Union[str, Path]) -> Metadata:
return {}
def clean_nones(data: Any) -> Any:
"""
Recursively remove None values from a dictionary/list.
[C: tests/test_thinking_persistence.py:test_clean_nones_removes_thinking]
"""
"""Recursively remove None values from a dictionary/list."""
if isinstance(data, dict): return {k: clean_nones(v) for k, v in data.items() if v is not None}
elif isinstance(data, list): return [clean_nones(v) for v in data if v is not None]
return data
@@ -231,7 +213,6 @@ def save_project(proj: Metadata, path: Union[str, Path], disc_data: Optional[Met
"""
Save the project TOML.
If 'discussion' is present in proj, it is moved to the sibling history file.
[C: tests/test_history_management.py:test_history_persistence_across_turns, tests/test_history_management.py:test_save_separation, tests/test_project_manager_modes.py:test_load_save_execution_mode, tests/test_project_serialization.py:TestProjectSerialization.test_fileitem_roundtrip, tests/test_thinking_persistence.py:test_save_and_load_history_with_thinking_segments]
"""
proj = clean_nones(proj)
# Serialise FileItems
@@ -305,10 +286,7 @@ def flat_config(proj: Metadata, disc_name: Optional[str] = None, track_id: Optio
# ── track state persistence ─────────────────────────────────────────────────
def save_track_state(track_id: str, state: 'TrackState', base_dir: Union[str, Path] = ".") -> None:
"""
Saves a TrackState object to conductor/tracks/<track_id>/state.toml.
[C: tests/test_project_manager_tracks.py:test_get_all_tracks_with_state, tests/test_track_state_persistence.py:test_track_state_persistence]
"""
"""Saves a TrackState object to conductor/tracks/<track_id>/state.toml."""
track_dir = paths.get_track_state_dir(track_id, project_path=str(base_dir))
track_dir.mkdir(parents=True, exist_ok=True)
state_file = track_dir / "state.toml"
@@ -319,7 +297,6 @@ def load_track_state(track_id: str, base_dir: Union[str, Path] = ".") -> "TrackS
"""
Loads a TrackState object from conductor/tracks/<track_id>/state.toml.
Returns empty TrackState (zero-init) if not found.
[C: tests/test_track_state_persistence.py:test_track_state_persistence]
"""
from src.mma import TrackState, EMPTY_TRACK_STATE
state_file = paths.get_track_state_dir(track_id, project_path=str(base_dir)) / 'state.toml'
@@ -368,8 +345,6 @@ def get_all_tracks(base_dir: Union[str, Path] = ".") -> list[Metadata]:
Each returned dict includes an 'errors' list (list[ErrorInfo]) for any
per-track metadata recovery that occurred. Callers can ignore the errors
field for display purposes; the metadata is best-effort.
[C: tests/test_project_manager_tracks.py:test_get_all_tracks_empty, tests/test_project_manager_tracks.py:test_get_all_tracks_malformed, tests/test_project_manager_tracks.py:test_get_all_tracks_with_metadata_json, tests/test_project_manager_tracks.py:test_get_all_tracks_with_state, tests/test_project_paths.py:test_get_all_tracks_project_specific]
"""
tracks_dir = paths.get_tracks_dir(project_path=str(base_dir))
if not tracks_dir.exists(): return []
@@ -440,7 +415,6 @@ def calculate_track_progress(tickets: list) -> dict:
"""
Calculates track progress based on ticket statuses.
percentage (float), completed (int), total (int), in_progress (int), blocked (int), todo (int)
[C: tests/test_progress_viz.py:test_calculate_track_progress_all_completed, tests/test_progress_viz.py:test_calculate_track_progress_all_todo, tests/test_progress_viz.py:test_calculate_track_progress_empty, tests/test_progress_viz.py:test_calculate_track_progress_mixed]
"""
total = len(tickets)
if total == 0:
@@ -473,7 +447,6 @@ def branch_discussion(project_dict: dict, source_id: str, new_id: str, message_i
"""
Creates a new discussion in project_dict['discussion']['discussions'] by copying
the history from source_id up to (and including) message_index, and sets active to new_id.
[C: tests/test_discussion_takes.py:TestDiscussionTakes.test_branch_discussion_creates_new_take]
"""
if "discussion" not in project_dict or "discussions" not in project_dict["discussion"]: return
if source_id not in project_dict["discussion"]["discussions"]: return
@@ -490,7 +463,6 @@ def branch_discussion(project_dict: dict, source_id: str, new_id: str, message_i
def promote_take(project_dict: dict, take_id: str, new_id: str) -> None:
"""
Renames a take_id to new_id in the discussions dict.
[C: tests/test_discussion_takes.py:TestDiscussionTakes.test_promote_take_renames_discussion]
"""
if "discussion" not in project_dict or "discussions" not in project_dict["discussion"]: return
if take_id not in project_dict["discussion"]["discussions"]: return