feat(logs): Implement session restoration and historical replay mode

This commit is contained in:
2026-03-08 21:03:37 -04:00
parent 1e4eaf25d8
commit 1b3fc5ba2f
2 changed files with 102 additions and 23 deletions

View File

@@ -287,6 +287,9 @@ class AppController:
self._tier_stream_last_len: Dict[str, int] = {}
self.is_viewing_prior_session: bool = False
self.prior_session_entries: List[Dict[str, Any]] = []
self.prior_tool_calls: List[Dict[str, Any]] = []
self.prior_disc_entries: List[Dict[str, Any]] = []
self.prior_mma_dashboard_state: Dict[str, Any] = {}
self.test_hooks_enabled: bool = ("--enable-test-hooks" in sys.argv) or (os.environ.get("SLOP_TEST_HOOKS") == "1")
self.ui_manual_approve: bool = False
# Injection state
@@ -804,32 +807,79 @@ class AppController:
label = self.project.get("project", {}).get("name", "")
session_logger.open_session(label=label)
def cb_load_prior_log(self) -> None:
def cb_load_prior_log(self, path: Optional[str] = None) -> None:
root = hide_tk_root()
path = filedialog.askopenfilename(
title="Load Session Log",
initialdir=str(paths.get_logs_dir()),
filetypes=[("Log/JSONL", "*.log *.jsonl"), ("All Files", "*.*")]
)
if path is None:
path = filedialog.askdirectory(
title="Select Session Directory",
initialdir=str(paths.get_logs_dir())
)
root.destroy()
if not path:
return
log_path = Path(path)
if log_path.is_dir():
log_file = log_path / "comms.log"
else:
log_file = log_path
if not log_file.exists():
self._set_status(f"log file not found: {log_file}")
return
entries = []
disc_entries = []
try:
with open(path, "r", encoding="utf-8") as f:
with open(log_file, "r", encoding="utf-8") as f:
for line in f:
line = line.strip()
if line:
try:
entries.append(json.loads(line))
entry = json.loads(line)
entries.append(entry)
kind = entry.get("kind")
payload = entry.get("payload", {})
ts = entry.get("ts", "")
if kind == "history_add":
disc_entries.append({
"role": payload.get("role", "AI"),
"content": payload.get("content", ""),
"collapsed": payload.get("collapsed", False),
"ts": ts
})
elif kind == "request":
disc_entries.append({
"role": "User",
"content": payload.get("message", ""),
"collapsed": False,
"ts": ts
})
elif kind == "response":
disc_entries.append({
"role": "AI",
"content": payload.get("text", ""),
"collapsed": False,
"ts": ts
})
elif kind == "tool_result":
disc_entries.append({
"role": "Tool",
"content": f"[TOOL RESULT]\n{payload.get('output', '')}",
"collapsed": True,
"ts": ts
})
except json.JSONDecodeError:
continue
except Exception as e:
self._set_status(f"log load error: {e}")
return
self.prior_session_entries = entries
self.prior_disc_entries = disc_entries
self.is_viewing_prior_session = True
self._set_status(f"viewing prior session: {Path(path).name} ({len(entries)} entries)")
self._set_status(f"viewing prior session: {log_path.name} ({len(entries)} entries)")
def cb_prune_logs(self) -> None:
"""Manually triggers the log pruning process with aggressive thresholds."""