| 710 | text = "\n".join(f"{getattr(m, 'role', '?')}: {self._message_text(m)[:400]}" for m in msgs[-12:]) |
| 711 | |
| 712 | def _work() -> None: |
| 713 | try: |
| 714 | prompt = ( |
| 715 | "Analyze this coding session and give 3-5 concise insights: what was " |
| 716 | "accomplished, notable patterns, and one suggestion for next steps. " |
| 717 | "Be brief — short bullet points.\n\nSESSION:\n" + text |
| 718 | ) |
| 719 | resp = self.provider.chat([{"role": "user", "content": prompt}]) |
| 720 | self._reply(request_id, {"ok": True, "insights": (getattr(resp, "content", "") or "").strip()}) |
| 721 | except Exception as exc: # noqa: BLE001 |
| 722 | self._reply(request_id, {"ok": False, "error": str(exc)}) |
| 723 | |
| 724 | threading.Thread(target=_work, name=f"insights-{self.session_id}", daemon=True).start() |
| 725 | |