mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-06-14 14:54:06 +00:00
fix(heartbeat): ignore completed-only heartbeat entries
This commit is contained in:
parent
e3df310309
commit
2671c8fe55
@ -107,6 +107,7 @@ _HEARTBEAT_PREAMBLE = (
|
|||||||
def _heartbeat_has_active_tasks(content: str) -> bool:
|
def _heartbeat_has_active_tasks(content: str) -> bool:
|
||||||
"""True if HEARTBEAT.md has task lines, ignoring headers, blanks and comments."""
|
"""True if HEARTBEAT.md has task lines, ignoring headers, blanks and comments."""
|
||||||
in_comment = False
|
in_comment = False
|
||||||
|
in_active_section: bool | None = None
|
||||||
for line in content.splitlines():
|
for line in content.splitlines():
|
||||||
stripped = line.strip()
|
stripped = line.strip()
|
||||||
if in_comment:
|
if in_comment:
|
||||||
@ -114,11 +115,16 @@ def _heartbeat_has_active_tasks(content: str) -> bool:
|
|||||||
in_comment = False
|
in_comment = False
|
||||||
continue
|
continue
|
||||||
if not stripped or stripped.startswith("#"):
|
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
|
continue
|
||||||
if stripped.startswith("<!--"):
|
if stripped.startswith("<!--"):
|
||||||
if "-->" not in stripped[4:]:
|
if "-->" not in stripped[4:]:
|
||||||
in_comment = True
|
in_comment = True
|
||||||
continue
|
continue
|
||||||
|
if in_active_section is False:
|
||||||
|
continue
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@ -960,6 +960,8 @@ def test_heartbeat_retains_recent_messages_by_default():
|
|||||||
("<!--\nmulti-line\ncomment\n-->\n", False), # block comment, not tasks
|
("<!--\nmulti-line\ncomment\n-->\n", False), # block comment, not tasks
|
||||||
("<!-- single line -->\n", False),
|
("<!-- single line -->\n", False),
|
||||||
("## Active Tasks\n\n- water the plants\n", True),
|
("## 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):
|
def test_heartbeat_has_active_tasks(content, expected):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user