fix(app_controller): move 3 Result helpers out of cb_load_prior_log to class level
3 Result helper methods (_deserialize_active_track_result, _serialize_tool_calls_result, _parse_token_history_first_ts_result) were nested inside cb_load_prior_log as inner defs. The inner 'return' at the except block (line 2370) made the rest of the function body (lines 2377-2392) unreachable past the nested defs' scope. User fix: moved the 3 helpers to class level so they're reachable from other class methods (_refresh_from_project, _load_beads, etc.). Kept _resolve_log_ref and _read_ref_file_result as nested defs inside cb_load_prior_log because they're only used there. File: -69 lines (the 60-line def cb_load_prior_log block from its original position), +64 lines (the 3 helpers + cb_load_prior_log re-added in the correct order). Verified: ast.parse OK; from src import app_controller OK; AppController.cb_load_prior_log is reachable.
This commit is contained in:
+64
-69
@@ -2117,66 +2117,6 @@ class AppController:
|
||||
if cfg.auto_start:
|
||||
await mcp_client.get_external_mcp_manager().add_server(cfg)
|
||||
|
||||
def cb_load_prior_log(self, path: Optional[str] = None) -> None:
|
||||
"""
|
||||
[C: src/gui_2.py:App._render_log_management, src/gui_2.py:App.cb_load_prior_log]
|
||||
"""
|
||||
if not path:
|
||||
return
|
||||
|
||||
if not self.is_viewing_prior_session:
|
||||
self._current_session_usage = copy.deepcopy(self.session_usage)
|
||||
self._current_mma_tier_usage = copy.deepcopy(self.mma_tier_usage)
|
||||
self._current_token_history = copy.deepcopy(self._token_history)
|
||||
self._current_session_start_time = self._session_start_time
|
||||
|
||||
log_path = Path(path)
|
||||
if log_path.is_dir():
|
||||
log_file = log_path / "comms.log"
|
||||
session_dir = log_path
|
||||
else:
|
||||
log_file = log_path
|
||||
session_dir = log_path.parent
|
||||
|
||||
if not log_file.exists():
|
||||
self.ai_status = f"log file not found: {log_file}"
|
||||
return
|
||||
|
||||
def _resolve_log_ref(content: Any, session_dir: Path) -> str:
|
||||
if not content or not isinstance(content, str) or "[REF:" not in content:
|
||||
return str(content) if content is not None else ""
|
||||
pattern = r'\[REF:([^\]]+)\]'
|
||||
def replace_ref(match):
|
||||
ref_file = match.group(1)
|
||||
paths_to_check = [
|
||||
session_dir / "outputs" / ref_file,
|
||||
session_dir / "scripts" / ref_file
|
||||
]
|
||||
for p in paths_to_check:
|
||||
if p.exists():
|
||||
result = self._read_ref_file_result(p)
|
||||
if result.ok:
|
||||
return result.data
|
||||
self._last_request_errors.append((f"ref_file_read[{ref_file}]", result.errors[0]))
|
||||
return f"[ERROR READING REF: {ref_file}]"
|
||||
return match.group(0)
|
||||
return re.sub(pattern, replace_ref, content)
|
||||
|
||||
def _read_ref_file_result(self, p: Path) -> "Result[str]":
|
||||
"""Phase 6 Group 6.7: read a [REF:...] file content.
|
||||
On failure: OSError/IOError/UnicodeDecodeError -> ErrorInfo(original=e).
|
||||
Caller (`_resolve_log_ref`) appends to `self._last_request_errors`."""
|
||||
try:
|
||||
with open(p, "r", encoding="utf-8") as rf:
|
||||
return Result(data=rf.read())
|
||||
except (OSError, IOError, UnicodeDecodeError) as e:
|
||||
return Result(data="", errors=[ErrorInfo(
|
||||
kind=ErrorKind.INTERNAL,
|
||||
message=str(e),
|
||||
source=f"app_controller._read_ref_file_result[{p.name}]",
|
||||
original=e,
|
||||
)])
|
||||
|
||||
def _flush_to_project_result(self, cleaned_proj: dict, path: str) -> "Result[None]":
|
||||
"""Phase 6 Group 6.7: flush to project file with Result propagation.
|
||||
On failure: OSError/IOError/PermissionError/RuntimeError -> ErrorInfo(original=e).
|
||||
@@ -2246,6 +2186,66 @@ class AppController:
|
||||
original=e,
|
||||
)])
|
||||
|
||||
def cb_load_prior_log(self, path: Optional[str] = None) -> None:
|
||||
"""
|
||||
[C: src/gui_2.py:App._render_log_management, src/gui_2.py:App.cb_load_prior_log]
|
||||
"""
|
||||
if not path:
|
||||
return
|
||||
|
||||
if not self.is_viewing_prior_session:
|
||||
self._current_session_usage = copy.deepcopy(self.session_usage)
|
||||
self._current_mma_tier_usage = copy.deepcopy(self.mma_tier_usage)
|
||||
self._current_token_history = copy.deepcopy(self._token_history)
|
||||
self._current_session_start_time = self._session_start_time
|
||||
|
||||
log_path = Path(path)
|
||||
if log_path.is_dir():
|
||||
log_file = log_path / "comms.log"
|
||||
session_dir = log_path
|
||||
else:
|
||||
log_file = log_path
|
||||
session_dir = log_path.parent
|
||||
|
||||
if not log_file.exists():
|
||||
self.ai_status = f"log file not found: {log_file}"
|
||||
return
|
||||
|
||||
def _resolve_log_ref(content: Any, session_dir: Path) -> str:
|
||||
if not content or not isinstance(content, str) or "[REF:" not in content:
|
||||
return str(content) if content is not None else ""
|
||||
pattern = r'\[REF:([^\]]+)\]'
|
||||
def replace_ref(match):
|
||||
ref_file = match.group(1)
|
||||
paths_to_check = [
|
||||
session_dir / "outputs" / ref_file,
|
||||
session_dir / "scripts" / ref_file
|
||||
]
|
||||
for p in paths_to_check:
|
||||
if p.exists():
|
||||
result = self._read_ref_file_result(p)
|
||||
if result.ok:
|
||||
return result.data
|
||||
self._last_request_errors.append((f"ref_file_read[{ref_file}]", result.errors[0]))
|
||||
return f"[ERROR READING REF: {ref_file}]"
|
||||
return match.group(0)
|
||||
return re.sub(pattern, replace_ref, content)
|
||||
|
||||
def _read_ref_file_result(self, p: Path) -> "Result[str]":
|
||||
"""Phase 6 Group 6.7: read a [REF:...] file content.
|
||||
On failure: OSError/IOError/UnicodeDecodeError -> ErrorInfo(original=e).
|
||||
Caller (`_resolve_log_ref`) appends to `self._last_request_errors`."""
|
||||
try:
|
||||
with open(p, "r", encoding="utf-8") as rf:
|
||||
return Result(data=rf.read())
|
||||
except (OSError, IOError, UnicodeDecodeError) as e:
|
||||
return Result(data="", errors=[ErrorInfo(
|
||||
kind=ErrorKind.INTERNAL,
|
||||
message=str(e),
|
||||
source=f"app_controller._read_ref_file_result[{p.name}]",
|
||||
original=e,
|
||||
)])
|
||||
|
||||
entries = []
|
||||
disc_entries = []
|
||||
paired_tools = {}
|
||||
@@ -2373,7 +2373,7 @@ class AppController:
|
||||
source="app_controller.cb_load_prior_log",
|
||||
original=e,
|
||||
)])
|
||||
|
||||
|
||||
self.session_usage = new_usage
|
||||
self.mma_tier_usage = new_mma_usage
|
||||
self._token_history = new_token_history
|
||||
@@ -2393,7 +2393,6 @@ class AppController:
|
||||
|
||||
def cb_exit_prior_session(self):
|
||||
"""
|
||||
[C: src/gui_2.py:App._render_comms_history_panel, src/gui_2.py:App._render_prior_session_view]
|
||||
"""
|
||||
self.is_viewing_prior_session = False
|
||||
if self._current_session_usage:
|
||||
@@ -2402,14 +2401,14 @@ class AppController:
|
||||
if self._current_mma_tier_usage:
|
||||
self.mma_tier_usage = self._current_mma_tier_usage
|
||||
self._current_mma_tier_usage = None
|
||||
|
||||
|
||||
if self._current_token_history is not None:
|
||||
self._token_history = self._current_token_history
|
||||
self._current_token_history = None
|
||||
if self._current_session_start_time is not None:
|
||||
self._session_start_time = self._current_session_start_time
|
||||
self._current_session_start_time = None
|
||||
|
||||
|
||||
self.prior_session_entries.clear()
|
||||
self.prior_disc_entries.clear()
|
||||
self.prior_tool_calls.clear()
|
||||
@@ -2523,7 +2522,6 @@ class AppController:
|
||||
def inject_context(self, data: dict) -> None:
|
||||
"""
|
||||
Programmatic context injection.
|
||||
[C: tests/test_headless_simulation.py:test_mma_track_lifecycle_simulation]
|
||||
"""
|
||||
file_path = data.get("file_path")
|
||||
if file_path:
|
||||
@@ -2558,10 +2556,7 @@ class AppController:
|
||||
self.submit_io(run_prune)
|
||||
|
||||
def start_services(self, app: Any = None):
|
||||
"""
|
||||
Starts background threads.
|
||||
[C: src/gui_2.py:App.__init__]
|
||||
"""
|
||||
"""Starts background threads."""
|
||||
self._prune_old_logs()
|
||||
self._init_ai_and_hooks(app)
|
||||
self._loop_thread = threading.Thread(target=self._run_event_loop, daemon=True)
|
||||
|
||||
Reference in New Issue
Block a user