refactor(config): Route all config I/O through AppController
Eliminates 22 call sites that bypassed the AppController state owner
and read/wrote config.toml directly. AppController is now the single
source of truth for self.config; gui_2.py, commands.py, etc. go
through controller.save_config() / controller.load_config().
Production changes:
- src/models.py: rename load_config -> _load_config_from_disk,
save_config -> _save_config_to_disk (private I/O primitives)
- src/app_controller.py: add public load_config()/save_config() methods
that own the state. Update 3 internal call sites and 3 ConductorEngine
call sites to pass max_workers from self.config
- src/multi_agent_conductor.py: ConductorEngine.__init__ now takes
max_workers as a parameter (caller responsibility, not I/O primitive)
- src/external_editor.py: get_default_launcher() takes config as a
parameter; gui_2.py:1311,4776 pass app.config
- src/gui_2.py: 17 sites of models.save_config(X.config) replaced with
X.save_config() (delegates via __getattr__ to controller)
- src/commands.py: save_all() uses app.save_config()
Test changes (route through controller, not I/O primitive):
- tests/conftest.py: mock_app and app_instance fixtures now patch
AppController.load_config/save_config instead of models I/O primitives
- 18 other test files: patches renamed from models._save_config_to_disk
to AppController.save_config (and same for load_config)
- tests/test_app_controller_mcp.py: use SLOP_CONFIG env var instead of
patching removed CONFIG_PATH module constant
- tests/test_parallel_execution.py: pass max_workers=2 explicitly to
ConductorEngine (caller no longer reads config)
- tests/test_gui_paths.py: add save_config=MagicMock() to MockApp;
assert on controller method, not I/O primitive
- tests/test_models_no_top_level_tomli_w.py: still calls private
_save_config_to_disk directly (the only allowed exception; tests
the lazy-load behavior of the primitive itself)
New files:
- scripts/audit_no_models_config_io.py: enforces the rule (--strict,
--json modes; AST-based docstring detection to avoid false positives)
- conductor/code_styleguides/config_state_owner.md: documents the rule
Verification:
- 67 targeted tests pass
- scripts/audit_no_models_config_io.py --strict returns 0
This is the architectural cleanup that surfaced during the
audit_architectural_cheats_20260607 review. Closes the smoke-gun
CONFIG_PATH module constant (already done in 0c7ebf22) AND the
free-function models.load_config/save_config smell.
[conductor(checkpoint): config-iO-refactor-20260607]
This commit is contained in:
+19
-19
@@ -1009,7 +1009,7 @@ class App:
|
||||
if imgui.menu_item("Save All", "", False)[0]:
|
||||
self._flush_to_project()
|
||||
self._flush_to_config()
|
||||
models.save_config(self.config)
|
||||
self.save_config()
|
||||
self.ai_status = "config saved"
|
||||
if imgui.menu_item("Reset Session", "", False)[0]:
|
||||
ai_client.reset_session()
|
||||
@@ -1167,7 +1167,7 @@ class App:
|
||||
if "tools" not in self.config: self.config["tools"] = {}
|
||||
if "default_editor" not in self.config["tools"]: self.config["tools"]["default_editor"] = {}
|
||||
self.config["tools"]["default_editor"]["default_editor"] = editor_name
|
||||
models.save_config(self.config)
|
||||
self.save_config()
|
||||
self.ai_status = f"Default editor set to: {editor_name}"
|
||||
|
||||
_render_path_field("Logs Directory", "ui_logs_dir", "logs_dir", "Directory where session JSON-L logs and artifacts are stored.")
|
||||
@@ -1192,7 +1192,7 @@ class App:
|
||||
}
|
||||
cfg_path = paths.get_config_path()
|
||||
if cfg_path.exists(): shutil.copy(cfg_path, str(cfg_path) + ".bak")
|
||||
models.save_config(self.config)
|
||||
self.save_config()
|
||||
paths.reset_resolved()
|
||||
self.init_state()
|
||||
self.ai_status = 'paths applied and session reset'
|
||||
@@ -1308,7 +1308,7 @@ class App:
|
||||
if not self._pending_patch_files:
|
||||
self._patch_error_message = "No files to edit"
|
||||
return
|
||||
launcher = get_default_launcher()
|
||||
launcher = get_default_launcher(self.config)
|
||||
editor = launcher.config.get_default()
|
||||
if not editor:
|
||||
self._patch_error_message = "No external editor configured"
|
||||
@@ -1479,7 +1479,7 @@ def render_main_interface(app: App) -> None:
|
||||
try:
|
||||
app._flush_to_project()
|
||||
app._flush_to_config()
|
||||
models.save_config(app.config)
|
||||
app.save_config()
|
||||
except Exception:
|
||||
pass # silent — don't disrupt the GUI loop
|
||||
|
||||
@@ -2022,7 +2022,7 @@ def render_projects_panel(app: App) -> None:
|
||||
if imgui.button("Save All"):
|
||||
app._flush_to_project()
|
||||
app._flush_to_config()
|
||||
models.save_config(app.config)
|
||||
app.save_config()
|
||||
app.ai_status = "config saved"
|
||||
ch, app.ui_word_wrap = imgui.checkbox("Word-Wrap (Read-only panels)", app.ui_word_wrap)
|
||||
ch, app.ui_auto_scroll_comms = imgui.checkbox("Auto-scroll Comms History", app.ui_auto_scroll_comms)
|
||||
@@ -2415,7 +2415,7 @@ def render_save_preset_modal(app: App) -> None:
|
||||
"multi_viewport": app.ui_multi_viewport
|
||||
}
|
||||
app.config["layout_presets"] = app.layout_presets
|
||||
models.save_config(app.config)
|
||||
app.save_config()
|
||||
app._show_save_preset_modal = False
|
||||
app._new_preset_name = ""
|
||||
imgui.close_current_popup()
|
||||
@@ -4211,7 +4211,7 @@ def render_discussion_entry_controls(app: App) -> None:
|
||||
imgui.same_line()
|
||||
if imgui.button("Clear All"): app.disc_entries.clear()
|
||||
imgui.same_line()
|
||||
if imgui.button("Save"): app._flush_to_project(); app._flush_to_config(); models.save_config(app.config); app.ai_status = "discussion saved"
|
||||
if imgui.button("Save"): app._flush_to_project(); app._flush_to_config(); app.save_config(); app.ai_status = "discussion saved"
|
||||
imgui.same_line()
|
||||
if imgui.button("Compress"): app.controller._handle_compress_discussion()
|
||||
_, app.ui_auto_add_history = imgui.checkbox("Auto-add message & response to history", app.ui_auto_add_history)
|
||||
@@ -4773,7 +4773,7 @@ def render_external_editor_panel(app: App) -> None:
|
||||
imgui.text("External Editor for Diff Viewing")
|
||||
imgui.separator()
|
||||
try:
|
||||
launcher = get_default_launcher()
|
||||
launcher = get_default_launcher(app.config)
|
||||
editors = launcher.config.editors
|
||||
default_name = launcher.config.default_editor
|
||||
if not editors:
|
||||
@@ -4876,7 +4876,7 @@ def render_theme_panel(app: App) -> None:
|
||||
if imgui.selectable(p, p == cp)[0]:
|
||||
theme.apply(p)
|
||||
app._flush_to_config()
|
||||
models.save_config(app.config)
|
||||
app.save_config()
|
||||
imgui.end_combo()
|
||||
|
||||
imgui.separator()
|
||||
@@ -4907,7 +4907,7 @@ def render_theme_panel(app: App) -> None:
|
||||
imgui.same_line()
|
||||
if imgui.button("Apply Font (Requires Restart)"):
|
||||
app._flush_to_config()
|
||||
models.save_config(app.config)
|
||||
app.save_config()
|
||||
app.ai_status = "Font settings saved. Restart required."
|
||||
imgui.separator()
|
||||
imgui.text("UI Scale (DPI)")
|
||||
@@ -4915,14 +4915,14 @@ def render_theme_panel(app: App) -> None:
|
||||
if ch:
|
||||
theme.set_scale(scale)
|
||||
app._flush_to_config()
|
||||
models.save_config(app.config)
|
||||
app.save_config()
|
||||
|
||||
imgui.text("Panel Transparency")
|
||||
ch_t, trans = imgui.slider_float("##trans", theme.get_transparency(), 0.1, 1.0, "%.2f")
|
||||
if ch_t:
|
||||
theme.set_transparency(trans)
|
||||
app._flush_to_config()
|
||||
models.save_config(app.config)
|
||||
app.save_config()
|
||||
|
||||
imgui.text("Panel Item Transparency")
|
||||
ch_ct, ctrans = imgui.slider_float("##ctrans", theme.get_child_transparency(), 0.1, 1.0, "%.2f")
|
||||
@@ -4934,14 +4934,14 @@ def render_theme_panel(app: App) -> None:
|
||||
gui_cfg = app.config.setdefault("gui", {})
|
||||
gui_cfg["bg_shader_enabled"] = bg.enabled
|
||||
app._flush_to_config()
|
||||
models.save_config(app.config)
|
||||
app.save_config()
|
||||
|
||||
ch_crt, app.ui_crt_filter = imgui.checkbox("CRT Filter", app.ui_crt_filter)
|
||||
if ch_crt:
|
||||
gui_cfg = app.config.setdefault("gui", {})
|
||||
gui_cfg["crt_filter_enabled"] = app.ui_crt_filter
|
||||
app._flush_to_config()
|
||||
models.save_config(app.config)
|
||||
app.save_config()
|
||||
|
||||
imgui.separator()
|
||||
imgui.text("Tone Mapping (Per-Palette)")
|
||||
@@ -4949,20 +4949,20 @@ def render_theme_panel(app: App) -> None:
|
||||
|
||||
imgui.text("Brightness")
|
||||
ch_b, b = imgui.slider_float("##tm_b", theme.get_brightness(curr_p), 0.1, 2.0, "%.2f")
|
||||
if ch_b: theme.set_brightness(curr_p, b); app._flush_to_config(); models.save_config(app.config)
|
||||
if ch_b: theme.set_brightness(curr_p, b); app._flush_to_config(); app.save_config()
|
||||
|
||||
imgui.text("Contrast")
|
||||
ch_c, c = imgui.slider_float("##tm_c", theme.get_contrast(curr_p), 0.1, 2.0, "%.2f")
|
||||
if ch_c: theme.set_contrast(curr_p, c); app._flush_to_config(); models.save_config(app.config)
|
||||
if ch_c: theme.set_contrast(curr_p, c); app._flush_to_config(); app.save_config()
|
||||
|
||||
imgui.text("Gamma")
|
||||
ch_g, g = imgui.slider_float("##tm_g", theme.get_gamma(curr_p), 0.1, 3.0, "%.2f")
|
||||
if ch_g: theme.set_gamma(curr_p, g); app._flush_to_config(); models.save_config(app.config)
|
||||
if ch_g: theme.set_gamma(curr_p, g); app._flush_to_config(); app.save_config()
|
||||
|
||||
if imgui.button("Reset Tone Mapping"):
|
||||
theme.reset_tone_mapping(curr_p)
|
||||
app._flush_to_config()
|
||||
models.save_config(app.config)
|
||||
app.save_config()
|
||||
|
||||
imgui.end()
|
||||
if app.perf_profiling_enabled: app.perf_monitor.end_component("_render_theme_panel")
|
||||
|
||||
Reference in New Issue
Block a user