This commit is contained in:
2026-06-09 11:26:28 +03:00
parent 94735fd540
commit 244935e4ac
21 changed files with 886 additions and 15 deletions
+75
View File
@@ -0,0 +1,75 @@
import json
from typing import Any
def _format_time(seconds: int) -> str:
minutes, secs = divmod(max(0, seconds), 60)
return f"{minutes:02d}:{secs:02d}"
def format_pomodoro_notice(tool_name: str, raw_result: str) -> str | None:
try:
data = json.loads(raw_result)
except json.JSONDecodeError:
return None
if isinstance(data, dict) and "error" in data:
return f"⏱ Помидоро: {data['error']}"
if tool_name in ("get_pomodoro_status", "start_pomodoro", "stop_pomodoro"):
return _format_status_notice(data)
if tool_name == "get_pomodoro_history":
return _format_history_notice(data)
return None
def _format_status_notice(data: dict[str, Any]) -> str:
status = data.get("status", "idle")
task = data.get("task_note") or "без описания"
remaining = data.get("remaining_seconds", 0)
duration = data.get("duration_min", 25)
if status == "idle":
return "⏱ **Помидоро:** таймер не запущен."
if status == "running":
return (
f"⏱ **Помидоро запущен** · осталось **{_format_time(remaining)}** "
f"из {duration} мин · задача: _{task}_"
)
if status == "paused":
elapsed = data.get("elapsed_seconds", 0)
return (
f"⏱ **Помидоро на паузе** · прошло {_format_time(elapsed)} "
f"из {duration} мин · задача: _{task}_"
)
if status == "completed":
return f"⏱ **Помидоро завершён** · {duration} мин · задача: _{task}_"
if status == "cancelled":
return f"⏱ **Помидоро отменён** · задача: _{task}_"
return f"⏱ Помидоро: {status}"
def _format_history_notice(data: Any) -> str:
if not isinstance(data, list) or not data:
return "⏱ **История помидоро** пуста."
lines = ["⏱ **История помидоро:**"]
for item in data[:10]:
task = item.get("task_note") or "без описания"
status = item.get("status", "?")
duration = item.get("duration_min", "?")
lines.append(f"- {task} ({duration} мин, {status})")
return "\n".join(lines)
def format_pomodoro_context(status: dict[str, Any]) -> str:
notice = _format_status_notice(status)
return f"[Актуальный статус помидоро]\n{notice}"