From 2671c8fe5537b28b41111d94539884c34bbf5b5d Mon Sep 17 00:00:00 2001 From: Xubin Ren <52506698+Re-bin@users.noreply.github.com> Date: Sun, 31 May 2026 14:12:55 +0800 Subject: [PATCH] fix(heartbeat): ignore completed-only heartbeat entries --- nanobot/cli/commands.py | 6 ++++++ tests/cli/test_commands.py | 2 ++ 2 files changed, 8 insertions(+) diff --git a/nanobot/cli/commands.py b/nanobot/cli/commands.py index 12f1759e4..4d30d605e 100644 --- a/nanobot/cli/commands.py +++ b/nanobot/cli/commands.py @@ -107,6 +107,7 @@ _HEARTBEAT_PREAMBLE = ( def _heartbeat_has_active_tasks(content: str) -> bool: """True if HEARTBEAT.md has task lines, ignoring headers, blanks and comments.""" in_comment = False + in_active_section: bool | None = None for line in content.splitlines(): stripped = line.strip() if in_comment: @@ -114,11 +115,16 @@ def _heartbeat_has_active_tasks(content: str) -> bool: in_comment = False continue if not stripped or stripped.startswith("#"): + if stripped.startswith("##") and not stripped.startswith("###"): + heading = stripped.lstrip("#").strip().lower() + in_active_section = heading.startswith("active tasks") continue if stripped.startswith("" not in stripped[4:]: in_comment = True continue + if in_active_section is False: + continue return True return False diff --git a/tests/cli/test_commands.py b/tests/cli/test_commands.py index 20c07545c..eea27320a 100644 --- a/tests/cli/test_commands.py +++ b/tests/cli/test_commands.py @@ -960,6 +960,8 @@ def test_heartbeat_retains_recent_messages_by_default(): ("\n", False), # block comment, not tasks ("\n", False), ("## Active Tasks\n\n- water the plants\n", True), + ("## Completed\n\n- water the plants\n", False), + ("## Active Tasks\n\n### Garden\n\n- water the plants\n", True), ], ) def test_heartbeat_has_active_tasks(content, expected):