Remove legacy filesystem logs

Stop PrintStyle from creating per-process HTML files under /a0/logs and remove the obsolete tracked folder scaffolding.

Delete existing legacy log directories during startup migration so self-updated and manually upgraded installations are cleaned automatically. Point plugin debugging guidance to Docker output and add regression coverage for repeatable cleanup.
This commit is contained in:
Alessandro 2026-07-16 15:30:37 +02:00
parent 98589c6357
commit 8e5d643483
12 changed files with 39 additions and 60 deletions

View file

@ -130,7 +130,8 @@ def _cleanup_obsolete() -> None:
"""
to_remove = [
"knowledge/default",
"memory"
"memory",
"logs",
]
for path in to_remove:
if files.exists(path):

View file

@ -24,6 +24,7 @@
- Helper modules own reusable framework APIs and must preserve public callers unless all callers, tests, and docs are updated together.
- Update this file whenever public functions, classes, persistence behavior, path/security assumptions, side effects, or cross-module contracts change.
- Startup cleanup removes obsolete `memory`, `knowledge/default`, and legacy `logs` directories; repeated runs are safe.
- Observed side-effect areas: filesystem reads, filesystem writes, filesystem deletion, settings/state persistence, secret handling, scheduler state.
- Imported dependency areas include: `helpers`, `helpers.print_style`, `json`, `os`.
@ -42,6 +43,7 @@
- Run targeted tests for changed helper behavior; run security regressions for auth, filesystem, WebSocket, tunnel, upload, or secret-handling helpers.
- Related tests observed by source search:
- `tests/test_migration_cleanup.py`
- `tests/test_browser_agent_regressions.py`
- `tests/test_office_canvas_setup.py`
- `tests/test_office_document_store.py`

View file

@ -1,8 +1,10 @@
import os, webcolors, html
import html
import sys
from datetime import datetime
from collections.abc import Mapping
from . import files
import webcolors
from . import files # Load before strings; helpers.files imports sanitize_string.
from .strings import sanitize_string
_runtime_module = None
@ -18,7 +20,6 @@ def _get_runtime():
class PrintStyle:
last_endline = True
log_file_path = None
def __init__(self, bold=False, italic=False, underline=False, font_color="default", background_color="default", padding=False, log_only=False):
self.bold = bold
@ -30,14 +31,6 @@ class PrintStyle:
self.padding_added = False # Flag to track if padding was added
self.log_only = log_only
if PrintStyle.log_file_path is None:
logs_dir = files.get_abs_path("logs")
os.makedirs(logs_dir, exist_ok=True)
log_filename = datetime.now().strftime("log_%Y%m%d_%H%M%S.html")
PrintStyle.log_file_path = os.path.join(logs_dir, log_filename)
with open(PrintStyle.log_file_path, "w", encoding="utf-8", errors="replace") as f:
f.write("<html><body style='background-color:black;font-family: Arial, Helvetica, sans-serif;'><pre>\n")
def _get_rgb_color_code(self, color, is_background=False):
try:
if color.startswith("#") and len(color) == 7:
@ -90,19 +83,8 @@ class PrintStyle:
if self.padding and not self.padding_added:
if not self.log_only:
print() # Print an empty line for padding
self._log_html("<br>")
self.padding_added = True
def _log_html(self, html):
with open(PrintStyle.log_file_path, "a", encoding="utf-8", errors="replace") as f: # type: ignore[arg-type]
f.write(sanitize_string(html))
@staticmethod
def _close_html_log():
if PrintStyle.log_file_path:
with open(PrintStyle.log_file_path, "a", encoding="utf-8", errors="replace") as f:
f.write("</pre></body></html>")
@staticmethod
def _format_args(args, sep):
if not args:
@ -155,22 +137,16 @@ class PrintStyle:
if not PrintStyle.last_endline:
if not self.log_only:
print()
self._log_html("<br>")
plain_text, styled_text, html_text = self.get(*args, sep=sep)
_, styled_text, _ = self.get(*args, sep=sep)
if not self.log_only:
print(styled_text, end=end, flush=flush)
if end.endswith('\n'):
self._log_html(html_text + "<br>\n")
else:
self._log_html(html_text)
PrintStyle.last_endline = end.endswith('\n')
def stream(self, *args, sep=' ', flush=True):
self._add_padding_if_needed()
plain_text, styled_text, html_text = self.get(*args, sep=sep)
_, styled_text, _ = self.get(*args, sep=sep)
if not self.log_only:
print(styled_text, end='', flush=flush)
self._log_html(html_text)
PrintStyle.last_endline = False
def is_last_line_empty(self):
@ -218,7 +194,3 @@ class PrintStyle:
def error(*args, sep=' ', end='\n', flush=True):
prefixed = PrintStyle._prefixed_args("Error", args)
PrintStyle(font_color="red", padding=True).print(*prefixed, sep=sep, end=end, flush=flush)
# Ensure HTML file is closed properly when the program exits
import atexit
atexit.register(PrintStyle._close_html_log)

View file

@ -27,12 +27,13 @@
- Helper modules own reusable framework APIs and must preserve public callers unless all callers, tests, and docs are updated together.
- Update this file whenever public functions, classes, persistence behavior, path/security assumptions, side effects, or cross-module contracts change.
- Observed side-effect areas: filesystem reads, WebSocket state, secret handling.
- Imported dependency areas include: `atexit`, `collections.abc`, `datetime`, `html`, `os`, `strings`, `sys`, `webcolors`.
- `PrintStyle` emits sanitized, secret-masked console output and does not create filesystem log files.
- `get()` preserves its plain-text, ANSI-styled, and HTML-styled return values for existing callers.
- Imported dependency areas include: `collections.abc`, `files`, `html`, `strings`, `sys`, `webcolors`.
## Key Concepts
- Important called helpers/classes observed in the source: `atexit.register`, `self._get_rgb_color_code`, `join`, `html.escape.replace`, `sep.join`, `self._format_args`, `sanitize_string`, `self._add_padding_if_needed`, `end.endswith`, `self._log_html`, `sys.stdin.readlines`, `PrintStyle._prefixed_args`, `files.get_abs_path`, `os.makedirs`, `datetime.now.strftime`, `os.path.join`, `f.write`, `self.secrets_mgr.mask_values`, `self._get_styled_text`, `self._get_html_styled_text`.
- Important called helpers/classes observed in the source: `self._get_rgb_color_code`, `html.escape.replace`, `sep.join`, `self._format_args`, `sanitize_string`, `self._add_padding_if_needed`, `end.endswith`, `sys.stdin.readlines`, `PrintStyle._prefixed_args`, `self.secrets_mgr.mask_values`, `self._get_styled_text`, `self._get_html_styled_text`.
- Keep request/response, tool, or helper semantics documented here at the same time as source changes.
## Work Guidance