Skip to content

An always-on second brain you talk to. Voice notes in Telegram → typed, linked knowledge in your Obsidian vault. Runs 24/7 on the Claude subscription you already have.

feat(config): cron settings + croniter dependency

smixs2d2129c5d0a0
diff --git a/pyproject.toml b/pyproject.toml
index b528a03..30fef90 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -9,6 +9,7 @@ authors = [
requires-python = ">=3.12"
dependencies = [
"aiogram>=3.0",
+ "croniter>=2.0",
"deepgram-sdk",
"httpx",
"pydantic>=2.0",
diff --git a/src/d_brain/config.py b/src/d_brain/config.py
index 5621dd9..cafbe6e 100644
--- a/src/d_brain/config.py
+++ b/src/d_brain/config.py
@@ -45,6 +45,33 @@ class Settings(BaseSettings):
)
tz: str = Field(default="UTC", description="Timezone for timers/reports")
+ # ── cron (scheduled jobs in the second brain session) ────────────
+ cron_enabled: bool = Field(
+ default=True,
+ description="Run the in-bot cron ticker",
+ )
+ cron_tick_seconds: float = Field(
+ default=60.0,
+ description="Ticker interval; jobs.json is re-read every tick",
+ )
+ cron_job_timeout: float = Field(
+ default=600.0,
+ description="Per-job ask() timeout in the cron session",
+ )
+ cron_max_consecutive_errors: int = Field(
+ default=3,
+ description="Consecutive failures before a job is auto-disabled",
+ )
+ cron_retry_seconds: float = Field(
+ default=300.0,
+ description="Retry delay for a failed one-shot ('at') job",
+ )
+
+ @property
+ def cron_dir(self) -> Path:
+ """Cron state dir: jobs.json + the cron session's runtime files."""
+ return self.runtime_dir / "cron"
+
@property
def admin_chat_id(self) -> int | None:
"""First allowed user — destination for health alerts / reports."""
diff --git a/tests/test_config.py b/tests/test_config.py
index 78548aa..c24f407 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -32,3 +32,17 @@ def test_overrides_from_kwargs():
s = _settings(claude_model="sonnet", tz="Asia/Tashkent")
assert s.claude_model == "sonnet"
assert s.tz == "Asia/Tashkent"
+
+
+def test_cron_fields_have_safe_defaults():
+ s = _settings()
+ assert s.cron_enabled is True
+ assert s.cron_tick_seconds == 60.0
+ assert s.cron_job_timeout == 600.0
+ assert s.cron_max_consecutive_errors == 3
+ assert s.cron_retry_seconds == 300.0
+
+
+def test_cron_dir_lives_under_runtime_dir():
+ s = _settings(runtime_dir=Path("/tmp/rt"))
+ assert s.cron_dir == Path("/tmp/rt/cron")
diff --git a/uv.lock b/uv.lock
index 6e64618..c5405ab 100644
--- a/uv.lock
+++ b/uv.lock
@@ -8,6 +8,7 @@ version = "3.0.0"
source = { editable = "." }
dependencies = [
{ name = "aiogram" },
+ { name = "croniter" },
{ name = "deepgram-sdk" },
{ name = "httpx" },
{ name = "pydantic" },
@@ -31,6 +32,7 @@ dev = [
[package.metadata]
requires-dist = [
{ name = "aiogram", specifier = ">=3.0" },
+ { name = "croniter", specifier = ">=2.0" },
{ name = "deepgram-sdk" },
{ name = "httpx" },
{ name = "mypy", marker = "extra == 'dev'" },
@@ -230,6 +232,18 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335, upload-time = "2022-10-25T02:36:20.889Z" },
]
+[[package]]
+name = "croniter"
+version = "6.2.2"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "python-dateutil" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/df/de/5832661ed55107b8a09af3f0a2e71e0957226a59eb1dcf0a445cce6daf20/croniter-6.2.2.tar.gz", hash = "sha256:ba60832a5ec8e12e51b8691c3309a113d1cf6526bdf1a48150ce8ec7a532d0ab", size = 113762, upload-time = "2026-03-15T08:43:48.112Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/d0/39/783980e78cb92c2d7bdb1fc7dbc86e94ccc6d58224d76a7f1f51b6c51e30/croniter-6.2.2-py3-none-any.whl", hash = "sha256:a5d17b1060974d36251ea4faf388233eca8acf0d09cbd92d35f4c4ac8f279960", size = 45422, upload-time = "2026-03-15T08:43:46.626Z" },
+]
+
[[package]]
name = "deepgram-sdk"
version = "5.3.1"
@@ -841,6 +855,18 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/e5/35/f8b19922b6a25bc0880171a2f1a003eaeb93657475193ab516fd87cac9da/pytest_asyncio-1.3.0-py3-none-any.whl", hash = "sha256:611e26147c7f77640e6d0a92a38ed17c3e9848063698d5c93d5aa7aa11cebff5", size = 15075, upload-time = "2025-11-10T16:07:45.537Z" },
]
+[[package]]
+name = "python-dateutil"
+version = "2.9.0.post0"
+source = { registry = "https://pypi.org/simple" }
+dependencies = [
+ { name = "six" },
+]
+sdist = { url = "https://files.pythonhosted.org/packages/66/c0/0c8b6ad9f17a802ee498c46e004a0eb49bc148f2fd230864601a86dcf6db/python-dateutil-2.9.0.post0.tar.gz", hash = "sha256:37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3", size = 342432, upload-time = "2024-03-01T18:36:20.211Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/ec/57/56b9bcc3c9c6a792fcbaf139543cee77261f3651ca9da0c93f5c1221264b/python_dateutil-2.9.0.post0-py2.py3-none-any.whl", hash = "sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427", size = 229892, upload-time = "2024-03-01T18:36:18.57Z" },
+]
+
[[package]]
name = "python-dotenv"
version = "1.2.1"
@@ -876,6 +902,15 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/9e/6a/40fee331a52339926a92e17ae748827270b288a35ef4a15c9c8f2ec54715/ruff-0.14.14-py3-none-win_arm64.whl", hash = "sha256:56e6981a98b13a32236a72a8da421d7839221fa308b223b9283312312e5ac76c", size = 10920448, upload-time = "2026-01-22T22:30:15.417Z" },
]
+[[package]]
+name = "six"
+version = "1.17.0"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/94/e7/b2c673351809dca68a0e064b6af791aa332cf192da575fd474ed7d6f16a2/six-1.17.0.tar.gz", hash = "sha256:ff70335d468e7eb6ec65b95b99d3a2836546063f63acc5171de367e834932a81", size = 34031, upload-time = "2024-12-04T17:35:28.174Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/b7/ce/149a00dd41f10bc29e5921b496af8b574d8413afcd5e30dfa0ed46c2cc5e/six-1.17.0-py2.py3-none-any.whl", hash = "sha256:4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274", size = 11050, upload-time = "2024-12-04T17:35:26.475Z" },
+]
+
[[package]]
name = "typing-extensions"
version = "4.15.0"