The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(doctor): show database size and the repair command for exposed databases
Erosikaa96a4621fadd
diff --git a/hermes_cli/doctor.py b/hermes_cli/doctor.pyindex ccb4699267e..3e35b67b6e9 100644--- a/hermes_cli/doctor.py+++ b/hermes_cli/doctor.py@@ -141,12 +141,20 @@ def _read_journal_mode(db_path: Path) -> tuple[str | None, str | None]:return None, f"unrecognized file-format version {header[18]}"+def _format_db_size(db_path: Path) -> str:+ try:+ mb = db_path.stat().st_size / 1_048_576+ except OSError:+ return "size unknown"+ return f"{mb:.1f} MB" if mb >= 0.1 else "<0.1 MB"++def _report_database_journal_modes(hermes_home: Path | None = None,version_info: tuple[int, ...] | None = None,) -> None:"""List each database's journal mode; warn on WAL under a vulnerable SQLite."""- from hermes_state import is_sqlite_wal_reset_vulnerable+ from hermes_state import _wal_reset_repair_hint, is_sqlite_wal_reset_vulnerablevulnerable = is_sqlite_wal_reset_vulnerable(version_info)home = hermes_home if hermes_home is not None else HERMES_HOME@@ -155,10 +163,12 @@ def _report_database_journal_modes(except Exception as exc:check_warn(f"Could not list Hermes databases: {exc}")return+ exposed = []for name, path in databases:if not path.is_file():continuemode, error = _read_journal_mode(path)+ size = _format_db_size(path)if error is not None:if vulnerable:check_warn(@@ -169,16 +179,19 @@ def _report_database_journal_modes(check_info(f"{name}: journal mode could not be read ({error})")elif mode == "wal":if vulnerable:+ exposed.append(name)check_warn(- f"{name} is in WAL mode",+ f"{name} is in WAL mode ({size})","(exposed to the WAL-reset bug until SQLite is upgraded)",)else:- check_info(f"{name}: WAL journal mode")+ check_info(f"{name}: WAL journal mode ({size})")elif vulnerable:- check_info(f"{name}: rollback journal mode (not exposed)")+ check_info(f"{name}: rollback journal mode ({size}, not exposed)")else:- check_info(f"{name}: rollback journal mode")+ check_info(f"{name}: rollback journal mode ({size})")+ if exposed:+ check_info(f"To clear the exposure: {_wal_reset_repair_hint()}")def _safe_which(cmd: str) -> str | None:diff --git a/tests/hermes_cli/test_doctor_journal_modes.py b/tests/hermes_cli/test_doctor_journal_modes.pyindex a9c6b77b67c..674d7023fec 100644--- a/tests/hermes_cli/test_doctor_journal_modes.py+++ b/tests/hermes_cli/test_doctor_journal_modes.py@@ -156,7 +156,7 @@ class TestReportDatabaseJournalModes:doctor._report_database_journal_modes(tmp_path, VULNERABLE)out = capsys.readouterr().out- assert "state.db: rollback journal mode (not exposed)" in out+ assert "state.db: rollback journal mode" in outassert EXPOSED_TEXT not in out@pytest.mark.parametrize("version", FIXED_VERSIONS)@@ -182,8 +182,8 @@ class TestReportDatabaseJournalModes:out = capsys.readouterr().outassert "state.db is in WAL mode" in out- assert "projects.db: rollback journal mode (not exposed)" in out- assert "kanban.db: rollback journal mode (not exposed)" in out+ assert "projects.db: rollback journal mode" in out+ assert "kanban.db: rollback journal mode" in outassert "kanban/boards/myboard/kanban.db is in WAL mode" in outdef test_missing_databases_are_skipped(self, tmp_path, capsys):@@ -205,7 +205,7 @@ class TestReportDatabaseJournalModes:holder.close()out = capsys.readouterr().out- assert "state.db: rollback journal mode (not exposed)" in out+ assert "state.db: rollback journal mode" in out@pytest.mark.skipif(os.name == "nt", reason="chmod is a no-op on Windows")@pytest.mark.skipif(os.geteuid() == 0, reason="root ignores file permissions")@@ -249,3 +249,26 @@ class TestReportDatabaseJournalModes:assert _sidecars(tmp_path) == []assert db.read_bytes() == db_bytes+++class TestSizeAndRepairHint:+ def test_exposed_databases_report_size_and_repair_hint(self, tmp_path, capsys):+ db = tmp_path / "state.db"+ _make_db(db, journal_mode="WAL")+ doctor._report_database_journal_modes(tmp_path, VULNERABLE)+ out = capsys.readouterr().out+ assert "MB)" in out+ assert "To clear the exposure:" in out++ def test_no_repair_hint_when_nothing_is_exposed(self, tmp_path, capsys):+ _make_db(tmp_path / "state.db", journal_mode="DELETE")+ doctor._report_database_journal_modes(tmp_path, VULNERABLE)+ assert "To clear the exposure:" not in capsys.readouterr().out++ def test_no_repair_hint_on_a_fixed_runtime(self, tmp_path, capsys):+ _make_db(tmp_path / "state.db", journal_mode="WAL")+ doctor._report_database_journal_modes(tmp_path, FIXED_VERSIONS[0])+ assert "To clear the exposure:" not in capsys.readouterr().out++ def test_size_failure_does_not_crash(self, tmp_path, capsys):+ assert doctor._format_db_size(tmp_path / "gone.db") == "size unknown"