Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
merge origin/main into pr-1039, adopt HEARTBEAT_OK in-check and on_notify
Re-bin6f4d1c2cdc91
diff --cc nanobot/heartbeat/service.pyindex ab2bfac32,7dbdc0373..3e40f2ff6--- a/nanobot/heartbeat/service.py+++ b/nanobot/heartbeat/service.py@@@ -36,15 -36,6 +36,7 @@@ def _is_heartbeat_empty(content: str |return True- def _is_heartbeat_ok_response(response: str | None) -> bool:- """Return True only for an exact HEARTBEAT_OK token (with simple markdown wrappers)."""- if not response:- return False-- normalized = re.sub(r"[\s`*_>\-]", "", response).upper()- return normalized == HEARTBEAT_OK_TOKEN.replace("_", "")-+class HeartbeatService:"""Periodic heartbeat service that wakes the agent to check for tasks.diff --cc tests/test_heartbeat_service.pyindex 52d1b96c8,000000000..ec91c6b7bmode 100644,000000..100644--- a/tests/test_heartbeat_service.py+++ b/tests/test_heartbeat_service.py@@@ -1,40 -1,0 +1,44 @@@+import asyncio++import pytest++from nanobot.heartbeat.service import (++ HEARTBEAT_OK_TOKEN,+ HeartbeatService,- _is_heartbeat_ok_response,+)++- def test_heartbeat_ok_response_requires_exact_token() -> None:- assert _is_heartbeat_ok_response("HEARTBEAT_OK")- assert _is_heartbeat_ok_response("`HEARTBEAT_OK`")- assert _is_heartbeat_ok_response("**HEARTBEAT_OK**")++def test_heartbeat_ok_detection() -> None:++ def is_ok(response: str) -> bool:++ return HEARTBEAT_OK_TOKEN in response.upper()+- assert not _is_heartbeat_ok_response("HEARTBEAT_OK, done")- assert not _is_heartbeat_ok_response("done HEARTBEAT_OK")- assert not _is_heartbeat_ok_response("HEARTBEAT_NOT_OK")++ assert is_ok("HEARTBEAT_OK")++ assert is_ok("`HEARTBEAT_OK`")++ assert is_ok("**HEARTBEAT_OK**")++ assert is_ok("heartbeat_ok")++ assert is_ok("HEARTBEAT_OK.")++++ assert not is_ok("HEARTBEAT_NOT_OK")++ assert not is_ok("all good")+++async def test_start_is_idempotent(tmp_path) -> None:+ async def _on_heartbeat(_: str) -> str:+ return "HEARTBEAT_OK"++ service = HeartbeatService(+ workspace=tmp_path,+ on_heartbeat=_on_heartbeat,+ interval_s=9999,+ enabled=True,+ )++ await service.start()+ first_task = service._task+ await service.start()++ assert service._task is first_task++ service.stop()+ await asyncio.sleep(0)