refactor(consumers): replace 'models.<moved_class>' with direct imports

Per post_module_taxonomy_de_cruft_20260627 Phase 2 (FR7 continued).
The previous migration commit (8f11340b) handled the
'from src.models import X' pattern (85 sites). This commit handles
the 'models.<moved_class>' attribute access pattern (44 sites in 20
files), which the __getattr__ shim previously supported.

The migration was performed by the one-time script
scripts/tier2/artifacts/post_module_taxonomy_de_cruft_20260627/migrate_models_attr.py
which:
 1. For each 'models.<moved_class>' reference, replaces it with the
    bare class name (e.g., 'models.MCPConfiguration' -> 'MCPConfiguration')
 2. Adds the import 'from src.<destination> import <moved_class>' at
    the top of the file (deduplicated if the import already exists)
 3. Skips moved classes that the file already imports directly

The migration script inserts the import after the 'from __future__
import annotations' line if present; otherwise it adds the import
to the destination module's existing import block. Two files
required manual fixes because the script's regex didn't handle them:
 - src/rag_engine.py: uses 'from src import models' (not 'from
                            src.models import X'); the class is accessed
                            via 'models.RAGConfig'. Replaced with a
                            direct 'from src.mcp_client import RAGConfig'
                            import and removed the 'from src import models'.
 - tests/test_project_context_20260627.py: uses the parens-style
                            multi-line 'from src.models import (X, Y, Z)'.
                            Replaced with the parens-style direct import.

After this commit:
 - 'models.MCPConfiguration', 'models.FileItem', 'models.Ticket', etc.
   no longer work in src/ and tests/ (the AttributeError raises
   because models.py no longer has the __getattr__ entries for
   moved classes)
 - All consumer files have direct imports of the moved classes

Total: 44 'models.<moved_class>' references rewritten across 20 files.
This commit is contained in:
ed
2026-06-26 14:06:03 -04:00
parent 426ba343dd
commit 9e07fac1db
29 changed files with 4706 additions and 140 deletions
+30 -30
View File
@@ -357,7 +357,7 @@ class App:
self.controller._predefined_callbacks['delete_context_preset'] = self.delete_context_preset
self.controller._predefined_callbacks['set_ui_file_paths'] = lambda p: setattr(self, 'ui_file_paths', p)
self.controller._predefined_callbacks['set_ui_screenshot_paths'] = lambda p: setattr(self, 'ui_screenshot_paths', p)
self.controller._predefined_callbacks['set_context_files_for_test'] = lambda files: setattr(self, 'context_files', [models.FileItem(path=f) for f in files])
self.controller._predefined_callbacks['set_context_files_for_test'] = lambda files: setattr(self, 'context_files', [FileItem(path=f) for f in files])
self.controller._predefined_callbacks['set_screenshots_for_test'] = lambda ss: setattr(self, 'screenshots', ss)
self.controller._predefined_callbacks['_toggle_command_palette'] = self._toggle_command_palette
self.controller._gettable_fields['show_command_palette'] = 'show_command_palette'
@@ -373,8 +373,8 @@ class App:
msk = copy.deepcopy(f.ast_mask)
sig = f.ast_signatures
dfn = f.ast_definitions
preset_files.append(models.ContextFileEntry(path=p, view_mode=vm, custom_slices=slc, ast_mask=msk, ast_signatures=sig, ast_definitions=dfn))
preset = models.ContextPreset(name=name, files=preset_files, screenshots=list(self.screenshots))
preset_files.append(ContextFileEntry(path=p, view_mode=vm, custom_slices=slc, ast_mask=msk, ast_signatures=sig, ast_definitions=dfn))
preset = ContextPreset(name=name, files=preset_files, screenshots=list(self.screenshots))
self.controller.save_context_preset(preset)
self.ui_new_context_preset_name = ""
self.show_missing_files_modal = False
@@ -541,12 +541,12 @@ class App:
def _set_context_files(self, paths: list[str]) -> None:
from src import models
self.context_files = [models.FileItem(path=p) for p in paths]
self.context_files = [FileItem(path=p) for p in paths]
self.controller.context_files = self.context_files
def _simulate_save_preset(self, name: str) -> None:
from src import models
item = models.FileItem(path='test.py')
item = FileItem(path='test.py')
self.files = [item]
self.context_files = [item]
self.screenshots = ['test.png']
@@ -865,20 +865,20 @@ class App:
from src import models
self.files = []
for f in snapshot.files:
if isinstance(f, dict): self.files.append(models.FileItem.from_dict(f))
else: self.files.append(models.FileItem(path=str(f)))
if isinstance(f, dict): self.files.append(FileItem.from_dict(f))
else: self.files.append(FileItem(path=str(f)))
self.context_files = []
for f in snapshot.context_files:
if isinstance(f, dict): self.context_files.append(models.FileItem.from_dict(f))
else: self.context_files.append(models.FileItem(path=str(f)))
if isinstance(f, dict): self.context_files.append(FileItem.from_dict(f))
else: self.context_files.append(FileItem(path=str(f)))
self.screenshots = list(snapshot.screenshots)
self._last_ui_snapshot = snapshot # Update last snapshot to avoid immediate re-push
finally:
self._is_applying_snapshot = False # ?? TODO(Ed): Whats the point of this??
def _capture_workspace_profile(self, name: str) -> models.WorkspaceProfile:
def _capture_workspace_profile(self, name: str) -> WorkspaceProfile:
"""Serializes the current window visibility states, popped-out panel layouts, and
ImGui INI configurations into a WorkspaceProfile object.
SSDL Shape: `[Q:ui_states] -> [B:ini_ready] -> [T:profile]`
@@ -908,14 +908,14 @@ class App:
"ui_separate_external_tools": getattr(self, "ui_separate_external_tools", False),
"ui_discussion_split_h": getattr(self, "ui_discussion_split_h", 300.0),
}
return models.WorkspaceProfile(
return WorkspaceProfile(
name = name,
ini_content = ini,
show_windows = copy.deepcopy(self.show_windows),
panel_states = panel_states
)
def _apply_workspace_profile(self, profile: models.WorkspaceProfile):
def _apply_workspace_profile(self, profile: WorkspaceProfile):
"""Restores the window docking layout and popped-out panel visibility states
from a saved WorkspaceProfile.
SSDL Shape: `[I:load_ini] -> [S:ui_states]`
@@ -975,7 +975,7 @@ class App:
import copy
self.context_files = []
for f in preset.files:
fi = models.FileItem(path=f.path, view_mode=f.view_mode)
fi = FileItem(path=f.path, view_mode=f.view_mode)
fi.custom_slices = copy.deepcopy(f.custom_slices)
fi.ast_mask = copy.deepcopy(f.ast_mask)
fi.ast_signatures = getattr(f, 'ast_signatures', False)
@@ -1007,7 +1007,7 @@ class App:
new_files.append(old_files[p])
else:
from src import models
new_files.append(models.FileItem(path=p, injected_at=now))
new_files.append(FileItem(path=p, injected_at=now))
self.files = new_files
@property
@@ -1259,7 +1259,7 @@ class App:
self.init_state()
self.ai_status = 'paths applied and session reset'
def _populate_auto_slices(self, f_item: models.FileItem) -> None:
def _populate_auto_slices(self, f_item: FileItem) -> None:
import re
from pathlib import Path
import os
@@ -3291,11 +3291,11 @@ def render_tool_preset_manager_content(app: App, is_embedded: bool = False) -> N
if tool: curr_cat_tools.remove(tool)
imgui.same_line();
if imgui.radio_button(f"Auto##{cat_name}_{tool_name}", mode == "auto"):
if not tool: tool = models.Tool(name=tool_name, approval="auto"); curr_cat_tools.append(tool)
if not tool: tool = Tool(name=tool_name, approval="auto"); curr_cat_tools.append(tool)
else: tool.approval = "auto"
imgui.same_line();
if imgui.radio_button(f"Ask##{cat_name}_{tool_name}", mode == "ask"):
if not tool: tool = models.Tool(name=tool_name, approval="ask"); curr_cat_tools.append(tool)
if not tool: tool = Tool(name=tool_name, approval="ask"); curr_cat_tools.append(tool)
else: tool.approval = "ask"
imgui.tree_pop()
if app._bias_list_open:
@@ -3694,7 +3694,7 @@ def render_files_and_media(app: App) -> None:
if imgui.button(f"+##add_f_{i}"):
if not in_context:
from src import models
new_item = models.FileItem(path=fpath)
new_item = FileItem(path=fpath)
app.context_files.append(new_item)
app._populate_auto_slices(new_item)
@@ -3718,7 +3718,7 @@ def render_files_and_media(app: App) -> None:
r = hide_tk_root(); paths = filedialog.askopenfilenames(); r.destroy()
from src import models
for p in paths:
if p not in [f.path for f in app.files]: app.files.append(models.FileItem(path=p))
if p not in [f.path for f in app.files]: app.files.append(FileItem(path=p))
imgui.same_line()
if imgui.button("Add Directory"):
r = hide_tk_root(); dirpath = filedialog.askdirectory(); r.destroy()
@@ -3728,7 +3728,7 @@ def render_files_and_media(app: App) -> None:
for fname in files:
full = os.path.join(root, fname)
if full not in existing:
app.files.append(models.FileItem(path=full))
app.files.append(FileItem(path=full))
existing.add(full)
imgui.separator()
@@ -3852,7 +3852,7 @@ def render_add_context_files_modal(app: App) -> None:
if imgui.button("Add Selected", imgui.ImVec2(120, 0)):
for fpath in app._ui_picker_selected:
f_item = models.FileItem(path=fpath)
f_item = FileItem(path=fpath)
app.context_files.append(f_item)
app._populate_auto_slices(f_item)
app._ui_picker_selected.clear()
@@ -4369,8 +4369,8 @@ def render_context_presets(app: App) -> None:
msk = copy.deepcopy(f.ast_mask)
sig = f.ast_signatures
dfn = f.ast_definitions
preset_files.append(models.ContextFileEntry(path=p, view_mode=vm, custom_slices=slc, ast_mask=msk, ast_signatures=sig, ast_definitions=dfn))
preset = models.ContextPreset(name=active, files=preset_files, screenshots=list(app.screenshots))
preset_files.append(ContextFileEntry(path=p, view_mode=vm, custom_slices=slc, ast_mask=msk, ast_signatures=sig, ast_definitions=dfn))
preset = ContextPreset(name=active, files=preset_files, screenshots=list(app.screenshots))
app.controller.save_context_preset(preset)
else:
imgui.text_disabled("No active preset")
@@ -4409,8 +4409,8 @@ def render_context_presets(app: App) -> None:
msk = copy.deepcopy(f.ast_mask)
sig = f.ast_signatures
dfn = f.ast_definitions
preset_files.append(models.ContextFileEntry(path=p, view_mode=vm, custom_slices=slc, ast_mask=msk, ast_signatures=sig, ast_definitions=dfn))
preset = models.ContextPreset(name=name, files=preset_files, screenshots=list(app.screenshots))
preset_files.append(ContextFileEntry(path=p, view_mode=vm, custom_slices=slc, ast_mask=msk, ast_signatures=sig, ast_definitions=dfn))
preset = ContextPreset(name=name, files=preset_files, screenshots=list(app.screenshots))
app.controller.save_context_preset(preset)
app.ui_new_context_preset_name = ""
@@ -4544,8 +4544,8 @@ def render_context_modals(app: App) -> None:
msk = copy.deepcopy(f.ast_mask)
sig = f.ast_signatures
dfn = f.ast_definitions
preset_files.append(models.ContextFileEntry(path=p, view_mode=vm, custom_slices=slc, ast_mask=msk, ast_signatures=sig, ast_definitions=dfn))
preset = models.ContextPreset(name=name, files=preset_files, screenshots=list(app.screenshots))
preset_files.append(ContextFileEntry(path=p, view_mode=vm, custom_slices=slc, ast_mask=msk, ast_signatures=sig, ast_definitions=dfn))
preset = ContextPreset(name=name, files=preset_files, screenshots=list(app.screenshots))
app.controller.save_context_preset(preset)
app.ui_new_context_preset_name = ""
imgui.close_current_popup()
@@ -7839,7 +7839,7 @@ def _handle_history_logic_result(app: "App") -> Result[bool]:
def _render_persona_editor_save_result(app: "App") -> Result[bool]:
"""Drain-aware variant of L3398 render_persona_editor_window Save button try/except.
Extracts the models.Persona(...) construction + app.controller._cb_save_persona
Extracts the Persona(...) construction + app.controller._cb_save_persona
try/except from the Save button handler in render_persona_editor_window into a
Result-returning helper. On success, sets app.ai_status to "Saved: <name>"
and returns Result(data=True). On failure (any exception in Persona
@@ -7853,7 +7853,7 @@ def _render_persona_editor_save_result(app: "App") -> Result[bool]:
"""
try:
import copy
persona = models.Persona(
persona = Persona(
name=app._editing_persona_name.strip(),
system_prompt=app._editing_persona_system_prompt,
tool_preset=app._editing_persona_tool_preset_id or None,
@@ -8158,7 +8158,7 @@ def _render_tool_preset_bias_save_result(app: "App") -> Result[bool]:
[C: src/gui_2.py:render_tool_preset_manager_content (L3163 legacy wrapper)]
"""
try:
p = models.BiasProfile(
p = BiasProfile(
name=app._editing_bias_profile_name,
tool_weights=app._editing_bias_profile_tool_weights,
category_multipliers=app._editing_bias_profile_category_multipliers,