nexo-brain 5.3.26 → 5.3.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/package.json +1 -1
  3. package/src/hook_guardrails.py +44 -0
  4. package/src/server.py +3 -0
  5. package/src/tools_sessions.py +6 -1
  6. package/src/dashboard/static/favicon 2.svg +0 -32
  7. package/src/dashboard/static/nexo-logo 2.png +0 -0
  8. package/src/dashboard/static/nexo-logo 2.svg +0 -40
  9. package/src/dashboard/static/style 2.css +0 -2458
  10. package/src/dashboard/templates/adaptive 2.html +0 -118
  11. package/src/dashboard/templates/artifacts 2.html +0 -133
  12. package/src/dashboard/templates/backups 2.html +0 -136
  13. package/src/dashboard/templates/base 2.html +0 -417
  14. package/src/dashboard/templates/calendar 2.html +0 -591
  15. package/src/dashboard/templates/chat 2.html +0 -356
  16. package/src/dashboard/templates/claims 2.html +0 -259
  17. package/src/dashboard/templates/cortex 2.html +0 -321
  18. package/src/dashboard/templates/credentials 2.html +0 -128
  19. package/src/dashboard/templates/crons 2.html +0 -370
  20. package/src/dashboard/templates/dashboard 2.html +0 -494
  21. package/src/dashboard/templates/dreams 2.html +0 -252
  22. package/src/dashboard/templates/email 2.html +0 -160
  23. package/src/dashboard/templates/evolution 2.html +0 -189
  24. package/src/dashboard/templates/feed 2.html +0 -249
  25. package/src/dashboard/templates/followup_health 2.html +0 -170
  26. package/src/dashboard/templates/graph 2.html +0 -201
  27. package/src/dashboard/templates/guard 2.html +0 -259
  28. package/src/dashboard/templates/inbox 2.html +0 -251
  29. package/src/dashboard/templates/memory 2.html +0 -420
  30. package/src/dashboard/templates/operations 2.html +0 -608
  31. package/src/dashboard/templates/plugins 2.html +0 -185
  32. package/src/dashboard/templates/protocol 2.html +0 -199
  33. package/src/dashboard/templates/rules 2.html +0 -246
  34. package/src/dashboard/templates/sentiment 2.html +0 -247
  35. package/src/dashboard/templates/sessions 2.html +0 -218
  36. package/src/dashboard/templates/skills 2.html +0 -329
  37. package/src/dashboard/templates/somatic 2.html +0 -73
  38. package/src/dashboard/templates/triggers 2.html +0 -133
  39. package/src/dashboard/templates/trust 2.html +0 -360
  40. package/src/db/__init__ 2.py +0 -259
  41. package/src/db/_core 2.py +0 -437
  42. package/src/db/_credentials 2.py +0 -124
  43. package/src/db/_episodic 2.py +0 -762
  44. package/src/db/_evolution 2.py +0 -54
  45. package/src/db/_fts 2.py +0 -406
  46. package/src/db/_goal_profiles 2.py +0 -376
  47. package/src/db/_hot_context 2.py +0 -660
  48. package/src/db/_outcomes 2.py +0 -800
  49. package/src/db/_personal_scripts 2.py +0 -582
  50. package/src/db/_sessions 2.py +0 -330
  51. package/src/db/_tasks 2.py +0 -91
  52. package/src/db/_watchers 2.py +0 -173
  53. package/src/doctor/formatters 2.py +0 -52
  54. package/src/doctor/models 2.py +0 -69
  55. package/src/doctor/planes 2.py +0 -87
  56. package/src/doctor/providers/__init__ 2.py +0 -1
  57. package/src/doctor/providers/deep 2.py +0 -367
  58. package/src/evolution_cycle 2.py +0 -519
  59. package/src/hooks/auto_capture 2.py +0 -208
  60. package/src/hooks/caffeinate-guard 2.sh +0 -8
  61. package/src/hooks/capture-session 2.sh +0 -21
  62. package/src/hooks/capture-tool-logs 2.sh +0 -158
  63. package/src/hooks/daily-briefing-check 2.sh +0 -33
  64. package/src/hooks/heartbeat-enforcement 2.py +0 -90
  65. package/src/hooks/heartbeat-posttool 2.sh +0 -18
  66. package/src/hooks/inbox-hook 2.sh +0 -76
  67. package/src/hooks/post-compact 2.sh +0 -152
  68. package/src/hooks/pre-compact 2.sh +0 -169
  69. package/src/hooks/protocol-guardrail 2.sh +0 -10
  70. package/src/hooks/protocol-pretool-guardrail 2.sh +0 -9
  71. package/src/hooks/session-stop 2.sh +0 -52
  72. package/src/kg_populate 2.py +0 -292
  73. package/src/maintenance 2.py +0 -53
  74. package/src/memory_backends 2.py +0 -71
  75. package/src/migrate_embeddings 2.py +0 -124
  76. package/src/nexo_sdk 2.py +0 -103
  77. package/src/observability 2.py +0 -199
  78. package/src/plugin_loader 2.py +0 -217
  79. package/src/plugins/__init__ 2.py +0 -0
  80. package/src/plugins/artifact_registry 2.py +0 -450
  81. package/src/plugins/backup 2.py +0 -127
  82. package/src/plugins/claims_tools 2.py +0 -119
  83. package/src/plugins/cognitive_memory 2.py +0 -609
  84. package/src/plugins/core_rules 2.py +0 -252
  85. package/src/plugins/cortex 2.py +0 -1155
  86. package/src/plugins/entities 2.py +0 -67
  87. package/src/plugins/episodic_memory 2.py +0 -560
  88. package/src/plugins/evolution 2.py +0 -167
  89. package/src/plugins/goal_engine 2.py +0 -142
  90. package/src/plugins/guard 2.py +0 -862
  91. package/src/plugins/impact 2.py +0 -29
  92. package/src/plugins/knowledge_graph_tools 2.py +0 -137
  93. package/src/plugins/media_memory_tools 2.py +0 -98
  94. package/src/plugins/memory_export 2.py +0 -196
  95. package/src/plugins/outcomes 2.py +0 -130
  96. package/src/plugins/personal_scripts 2.py +0 -117
  97. package/src/plugins/preferences 2.py +0 -47
  98. package/src/plugins/protocol 2.py +0 -1449
  99. package/src/plugins/simple_api 2.py +0 -106
  100. package/src/plugins/skills 2.py +0 -341
  101. package/src/plugins/state_watchers 2.py +0 -79
  102. package/src/plugins/update 2.py +0 -986
  103. package/src/plugins/user_state_tools 2.py +0 -43
  104. package/src/plugins/workflow 2.py +0 -588
  105. package/src/protocol_settings 2.py +0 -59
  106. package/src/public_contribution 2.py +0 -466
  107. package/src/public_evolution_queue 2.py +0 -241
  108. package/src/requirements 2.txt +0 -14
  109. package/src/retroactive_learnings 2.py +0 -373
  110. package/src/rules/__init__ 2.py +0 -0
  111. package/src/rules/core-rules 2.json +0 -331
  112. package/src/rules/migrate 2.py +0 -207
  113. package/src/runtime_power 2.py +0 -874
  114. package/src/script_registry 2.py +0 -1559
  115. package/src/scripts/check-context 2.py +0 -272
  116. package/src/scripts/deep-sleep/apply_findings 2.py +0 -2327
  117. package/src/scripts/deep-sleep/collect 2.py +0 -928
  118. package/src/scripts/deep-sleep/extract 2.py +0 -330
  119. package/src/scripts/deep-sleep/extract-prompt 2.md +0 -285
  120. package/src/scripts/deep-sleep/synthesize 2.py +0 -312
  121. package/src/scripts/deep-sleep/synthesize-prompt 2.md +0 -336
  122. package/src/scripts/nexo-agent-run 2.py +0 -75
  123. package/src/scripts/nexo-auto-update 2.py +0 -6
  124. package/src/scripts/nexo-backup 2.sh +0 -25
  125. package/src/scripts/nexo-brain-activation 2.sh +0 -140
  126. package/src/scripts/nexo-catchup 2.py +0 -300
  127. package/src/scripts/nexo-cognitive-decay 2.py +0 -257
  128. package/src/scripts/nexo-cortex-cycle 2.py +0 -293
  129. package/src/scripts/nexo-cron-wrapper 2.sh +0 -53
  130. package/src/scripts/nexo-daily-self-audit 2.py +0 -2161
  131. package/src/scripts/nexo-dashboard 2.sh +0 -29
  132. package/src/scripts/nexo-deep-sleep 2.sh +0 -86
  133. package/src/scripts/nexo-evolution-run 2.py +0 -1664
  134. package/src/scripts/nexo-followup-hygiene 2.py +0 -139
  135. package/src/scripts/nexo-hook-record 2.py +0 -42
  136. package/src/scripts/nexo-immune 2.py +0 -936
  137. package/src/scripts/nexo-impact-scorer 2.py +0 -117
  138. package/src/scripts/nexo-inbox-hook 2.sh +0 -74
  139. package/src/scripts/nexo-install 2.py +0 -6
  140. package/src/scripts/nexo-learning-housekeep 2.py +0 -401
  141. package/src/scripts/nexo-learning-validator 2.py +0 -266
  142. package/src/scripts/nexo-migrate 2.py +0 -260
  143. package/src/scripts/nexo-outcome-checker 2.py +0 -127
  144. package/src/scripts/nexo-postmortem-consolidator 2.py +0 -456
  145. package/src/scripts/nexo-pre-commit 2.py +0 -120
  146. package/src/scripts/nexo-prevent-sleep 2.sh +0 -35
  147. package/src/scripts/nexo-proactive-dashboard 2.py +0 -354
  148. package/src/scripts/nexo-reflection 2.py +0 -256
  149. package/src/scripts/nexo-runtime-preflight 2.py +0 -274
  150. package/src/scripts/nexo-sleep 2.py +0 -631
  151. package/src/scripts/nexo-snapshot-restore 2.sh +0 -35
  152. package/src/scripts/nexo-sync-clients 2.py +0 -16
  153. package/src/scripts/nexo-synthesis 2.py +0 -475
  154. package/src/scripts/nexo-tcc-approve 2.sh +0 -79
  155. package/src/scripts/nexo-update 2.sh +0 -306
  156. package/src/scripts/nexo-watchdog 2.sh +0 -1207
  157. package/src/scripts/nexo-watchdog-smoke 2.py +0 -119
  158. package/src/scripts/rehydrate_learnings_from_archive 2.py +0 -245
  159. package/src/server 2.py +0 -1296
  160. package/src/skills/run-nexo-audit-phase/guide 2.md +0 -43
  161. package/src/skills/run-nexo-audit-phase/skill 2.json +0 -59
  162. package/src/skills/run-nexo-core-fix-cycle/guide 2.md +0 -17
  163. package/src/skills/run-nexo-core-fix-cycle/script 2.py +0 -276
  164. package/src/skills/run-nexo-core-fix-cycle/skill 2.json +0 -58
  165. package/src/skills/run-release-final-audit/guide 2.md +0 -16
  166. package/src/skills/run-release-final-audit/script 2.py +0 -259
  167. package/src/skills/run-release-final-audit/skill 2.json +0 -77
  168. package/src/skills/run-runtime-doctor/guide 2.md +0 -12
  169. package/src/skills/run-runtime-doctor/script 2.py +0 -21
  170. package/src/skills/run-runtime-doctor/skill 2.json +0 -25
  171. package/src/skills_runtime 2.py +0 -932
  172. package/src/state_watchers_runtime 2.py +0 -475
  173. package/src/storage_router 2.py +0 -32
  174. package/src/system_catalog 2.py +0 -786
  175. package/src/tools_coordination 2.py +0 -103
  176. package/src/tools_credentials 2.py +0 -68
  177. package/src/tools_drive 2.py +0 -487
  178. package/src/tools_hot_context 2.py +0 -163
  179. package/src/tools_learnings 2.py +0 -612
  180. package/src/tools_menu 2.py +0 -229
  181. package/src/tools_reminders 2.py +0 -88
  182. package/src/tools_reminders_crud 2.py +0 -363
  183. package/src/tools_sessions 2.py +0 -1054
  184. package/src/tools_system_catalog 2.py +0 -19
  185. package/src/tools_task_history 2.py +0 -57
  186. package/src/tools_transcripts 2.py +0 -98
  187. package/src/transcript_utils 2.py +0 -412
  188. package/src/user_context 2.py +0 -46
  189. package/src/user_data_portability 2.py +0 -328
  190. package/src/user_state_model 2.py +0 -170
  191. package/templates/CLAUDE.md 2.template +0 -108
  192. package/templates/CODEX.AGENTS.md 2.template +0 -66
  193. package/templates/launchagents/README 2.md +0 -132
  194. package/templates/launchagents/com.nexo.auto-close-sessions 2.plist +0 -39
  195. package/templates/launchagents/com.nexo.catchup 2.plist +0 -39
  196. package/templates/launchagents/com.nexo.cognitive-decay 2.plist +0 -40
  197. package/templates/launchagents/com.nexo.dashboard 2.plist +0 -43
  198. package/templates/launchagents/com.nexo.deep-sleep 2.plist +0 -43
  199. package/templates/launchagents/com.nexo.evolution 2.plist +0 -44
  200. package/templates/launchagents/com.nexo.followup-hygiene 2.plist +0 -45
  201. package/templates/launchagents/com.nexo.immune 2.plist +0 -41
  202. package/templates/launchagents/com.nexo.postmortem 2.plist +0 -45
  203. package/templates/launchagents/com.nexo.self-audit 2.plist +0 -47
  204. package/templates/launchagents/com.nexo.synthesis 2.plist +0 -45
  205. package/templates/launchagents/com.nexo.watchdog 2.plist +0 -37
  206. package/templates/nexo_helper 2.py +0 -301
  207. package/templates/openclaw 2.json +0 -13
  208. package/templates/plugin-template 2.py +0 -40
  209. package/templates/script-template 2.py +0 -59
  210. package/templates/script-template 2.sh +0 -13
  211. package/templates/skill-script-template 2.py +0 -48
  212. package/templates/skill-template 2.md +0 -33
@@ -1,69 +0,0 @@
1
- """Doctor data models — check results and report structure."""
2
- from __future__ import annotations
3
-
4
- import traceback
5
- from dataclasses import dataclass, field
6
- from typing import Callable
7
-
8
-
9
- @dataclass
10
- class DoctorCheck:
11
- id: str
12
- tier: str
13
- status: str # healthy, degraded, critical
14
- severity: str # info, warn, error
15
- summary: str
16
- evidence: list[str] = field(default_factory=list)
17
- repair_plan: list[str] = field(default_factory=list)
18
- escalation_prompt: str = ""
19
- fixed: bool = False
20
-
21
-
22
- @dataclass
23
- class DoctorReport:
24
- overall_status: str # healthy, degraded, critical
25
- counts: dict = field(default_factory=dict)
26
- checks: list[DoctorCheck] = field(default_factory=list)
27
- duration_ms: int = 0
28
-
29
- def add(self, check: DoctorCheck):
30
- self.checks.append(check)
31
-
32
- def compute_status(self):
33
- """Compute overall status from individual checks."""
34
- statuses = [c.status for c in self.checks]
35
- if "critical" in statuses:
36
- self.overall_status = "critical"
37
- elif "degraded" in statuses:
38
- self.overall_status = "degraded"
39
- else:
40
- self.overall_status = "healthy"
41
- self.counts = {
42
- "healthy": statuses.count("healthy"),
43
- "degraded": statuses.count("degraded"),
44
- "critical": statuses.count("critical"),
45
- "total": len(statuses),
46
- }
47
-
48
-
49
- def safe_check(fn: Callable[..., DoctorCheck], *args, **kwargs) -> DoctorCheck:
50
- """Run a single check function, returning a crash DoctorCheck on exception.
51
-
52
- This isolates individual checks so one failure doesn't take down
53
- all sibling checks within a tier.
54
- """
55
- try:
56
- return fn(*args, **kwargs)
57
- except Exception as exc:
58
- tb = traceback.format_exception(type(exc), exc, exc.__traceback__)
59
- last_frame = tb[-1].strip() if tb else str(exc)
60
- check_name = getattr(fn, "__name__", "unknown")
61
- return DoctorCheck(
62
- id=f"check.{check_name}_crashed",
63
- tier="unknown",
64
- status="critical",
65
- severity="error",
66
- summary=f"Check {check_name} crashed: {type(exc).__name__}: {exc}",
67
- evidence=[last_frame],
68
- repair_plan=[f"Investigate {check_name} — exception during check execution"],
69
- )
@@ -1,87 +0,0 @@
1
- """Diagnostic plane preflight for NEXO Doctor."""
2
-
3
- from __future__ import annotations
4
-
5
- from doctor.models import DoctorCheck
6
-
7
- VALID_DIAGNOSTIC_PLANES = {
8
- "product_public": {
9
- "label": "producto público",
10
- "use": "release contracts, artefactos publicados, compare/, docs y surfaces públicas del repo",
11
- },
12
- "runtime_personal": {
13
- "label": "runtime personal",
14
- "use": "~/.nexo, scripts personales, followups, reminders y hábitos operativos del operador",
15
- },
16
- "installation_live": {
17
- "label": "instalación viva",
18
- "use": "runtime instalado, hooks activos, clientes conectados, cron sync y parity de la instalación local",
19
- },
20
- "database_real": {
21
- "label": "BD real",
22
- "use": "SQLite/MySQL reales, filas, schema, deudas, sesiones y evidencia persistida",
23
- },
24
- "cooperator": {
25
- "label": "co-operador",
26
- "use": "comportamiento del agente, protocolo, comunicación y decisiones del asistente",
27
- },
28
- }
29
-
30
- DOCTOR_COMPATIBLE_PLANES = {"runtime_personal", "installation_live", "database_real"}
31
-
32
-
33
- def normalize_diagnostic_plane(plane: str = "") -> str:
34
- clean = (plane or "").strip().lower().replace("-", "_").replace(" ", "_")
35
- return clean if clean in VALID_DIAGNOSTIC_PLANES else ""
36
-
37
-
38
- def diagnostic_plane_choices() -> list[str]:
39
- return sorted(VALID_DIAGNOSTIC_PLANES)
40
-
41
-
42
- def diagnostic_plane_preflight(plane: str = "") -> tuple[str, DoctorCheck | None]:
43
- clean_plane = normalize_diagnostic_plane(plane)
44
- if not clean_plane:
45
- options = ", ".join(diagnostic_plane_choices())
46
- return "", DoctorCheck(
47
- id="orchestrator.diagnostic_plane_required",
48
- tier="orchestrator",
49
- status="critical",
50
- severity="error",
51
- summary="El diagnóstico está bloqueado hasta fijar explícitamente el plano",
52
- evidence=[
53
- f"planes válidos: {options}",
54
- "Usa `runtime_personal` para ~/.nexo y hábitos del runtime; `installation_live` para hooks/clientes/instalación; `database_real` para filas y schema reales.",
55
- ],
56
- repair_plan=[
57
- "Repite `nexo_doctor` o `nexo doctor` con `plane='runtime_personal'`, `plane='installation_live'` o `plane='database_real'`.",
58
- "Si el problema pertenece a producto público o al co-operador, usa el surface correcto en vez de NEXO Doctor.",
59
- ],
60
- escalation_prompt=(
61
- "NEXO mezcló planos en diagnósticos anteriores. El doctor no debe correr hasta que se elija "
62
- "explícitamente si el problema está en producto público, runtime personal, instalación viva, BD real o co-operador."
63
- ),
64
- )
65
-
66
- if clean_plane not in DOCTOR_COMPATIBLE_PLANES:
67
- plane_info = VALID_DIAGNOSTIC_PLANES[clean_plane]
68
- return clean_plane, DoctorCheck(
69
- id="orchestrator.diagnostic_plane_mismatch",
70
- tier="orchestrator",
71
- status="degraded",
72
- severity="warn",
73
- summary=f"NEXO Doctor no es la superficie correcta para el plano {plane_info['label']}",
74
- evidence=[
75
- f"plane: {clean_plane}",
76
- f"este plano se diagnostica mejor desde: {plane_info['use']}",
77
- ],
78
- repair_plan=[
79
- "Si quieres diagnosticar runtime/instalación/BD, vuelve a lanzar el doctor con el plano correcto.",
80
- "Si el problema es del producto público o del co-operador, usa release checks, repo checks o herramientas de protocolo/sesión en vez de Doctor.",
81
- ],
82
- escalation_prompt=(
83
- "El plano elegido no corresponde al runtime doctor. Cambia de plano o de herramienta antes de seguir para no mezclar diagnóstico técnico con producto o comportamiento del agente."
84
- ),
85
- )
86
-
87
- return clean_plane, None
@@ -1 +0,0 @@
1
- """Doctor check providers — boot, runtime, deep."""
@@ -1,367 +0,0 @@
1
- """Deep tier checks — read existing artifacts for richer validation. Target <60s."""
2
- from __future__ import annotations
3
-
4
- import datetime as dt
5
- import json
6
- import os
7
- import time
8
- from pathlib import Path
9
-
10
- from cron_recovery import load_enabled_crons
11
- from doctor.models import DoctorCheck, safe_check
12
-
13
- NEXO_HOME = Path(os.environ.get("NEXO_HOME", str(Path.home() / ".nexo")))
14
-
15
- # Freshness thresholds
16
- SELF_AUDIT_FRESHNESS = 86400 * 2 # 2 days (runs daily)
17
- SELF_AUDIT_BOOTSTRAP_GRACE = 86400 # 1 day grace after install/update before the first summary exists
18
- PREFLIGHT_FRESHNESS = 86400 # 1 day
19
- WATCHDOG_SMOKE_FRESHNESS = 86400 # 1 day
20
-
21
-
22
- def _file_age_seconds(path: Path) -> float | None:
23
- try:
24
- if path.is_file():
25
- return time.time() - path.stat().st_mtime
26
- except Exception:
27
- pass
28
- return None
29
-
30
-
31
- def _load_json(path: Path) -> dict:
32
- return json.loads(path.read_text())
33
-
34
-
35
- def _timestamp_age_seconds(value: str) -> float | None:
36
- raw = str(value or "").strip()
37
- if not raw:
38
- return None
39
- try:
40
- parsed = dt.datetime.fromisoformat(raw.replace("Z", "+00:00"))
41
- except Exception:
42
- return None
43
- if parsed.tzinfo is None:
44
- parsed = parsed.replace(tzinfo=dt.timezone.utc)
45
- return max(0.0, time.time() - parsed.timestamp())
46
-
47
-
48
- def _runtime_bootstrap_age_seconds() -> float | None:
49
- version_file = NEXO_HOME / "version.json"
50
- try:
51
- payload = _load_json(version_file)
52
- except Exception:
53
- payload = {}
54
- for key in ("updated_at", "installed_at"):
55
- age = _timestamp_age_seconds(str(payload.get(key, "") or ""))
56
- if age is not None:
57
- return age
58
- return _file_age_seconds(version_file)
59
-
60
-
61
- def _self_audit_enabled() -> bool | None:
62
- try:
63
- return any(str(cron.get("id") or "").strip() == "self-audit" for cron in load_enabled_crons())
64
- except Exception:
65
- return None
66
-
67
-
68
- def check_self_audit_summary() -> DoctorCheck:
69
- """Check latest self-audit summary exists and is recent."""
70
- summary_file = NEXO_HOME / "logs" / "self-audit-summary.json"
71
- age = _file_age_seconds(summary_file)
72
-
73
- if age is None:
74
- enabled = _self_audit_enabled()
75
- if enabled is False:
76
- return DoctorCheck(
77
- id="deep.self_audit",
78
- tier="deep",
79
- status="healthy",
80
- severity="info",
81
- summary="Self-audit automation disabled or not installed",
82
- )
83
-
84
- bootstrap_age = _runtime_bootstrap_age_seconds()
85
- if enabled and bootstrap_age is not None and bootstrap_age <= SELF_AUDIT_BOOTSTRAP_GRACE:
86
- bootstrap_hours = bootstrap_age / 3600
87
- return DoctorCheck(
88
- id="deep.self_audit",
89
- tier="deep",
90
- status="healthy",
91
- severity="info",
92
- summary="Self-audit scheduled but no summary yet",
93
- evidence=[
94
- f"Runtime install/update {bootstrap_hours:.0f} hours ago",
95
- f"Expected later at: {summary_file}",
96
- ],
97
- )
98
-
99
- return DoctorCheck(
100
- id="deep.self_audit",
101
- tier="deep",
102
- status="degraded",
103
- severity="warn",
104
- summary="Self-audit summary not found",
105
- evidence=[f"Expected: {summary_file}"],
106
- repair_plan=["Check if daily self-audit cron is installed"],
107
- )
108
-
109
- age_hours = age / 3600
110
- if age > SELF_AUDIT_FRESHNESS:
111
- return DoctorCheck(
112
- id="deep.self_audit",
113
- tier="deep",
114
- status="degraded",
115
- severity="warn",
116
- summary=f"Self-audit summary stale ({age_hours:.0f}h old)",
117
- evidence=[f"Last modified {age_hours:.0f} hours ago, threshold {SELF_AUDIT_FRESHNESS // 3600}h"],
118
- )
119
-
120
- try:
121
- data = _load_json(summary_file)
122
- counts = data.get("counts") or {}
123
- error_count = int(counts.get("error", 0) or 0)
124
- warn_count = int(counts.get("warn", 0) or 0)
125
- findings = data.get("findings") or []
126
- if error_count > 0:
127
- status = "critical"
128
- severity = "error"
129
- else:
130
- status = "healthy"
131
- severity = "info"
132
- return DoctorCheck(
133
- id="deep.self_audit",
134
- tier="deep",
135
- status=status,
136
- severity=severity,
137
- summary=(
138
- f"Self-audit: {len(findings)} findings "
139
- f"({error_count} error, {warn_count} warn; {age_hours:.0f}h ago)"
140
- ),
141
- )
142
- except Exception as e:
143
- return DoctorCheck(
144
- id="deep.self_audit",
145
- tier="deep",
146
- status="degraded",
147
- severity="warn",
148
- summary=f"Self-audit summary unreadable ({age_hours:.0f}h ago)",
149
- evidence=[str(e)],
150
- )
151
-
152
-
153
- def check_schema_version() -> DoctorCheck:
154
- """Check DB schema version is present and reasonable."""
155
- try:
156
- import sqlite3
157
- db_path = NEXO_HOME / "data" / "nexo.db"
158
- if not db_path.is_file():
159
- return DoctorCheck(
160
- id="deep.schema_version",
161
- tier="deep",
162
- status="degraded",
163
- severity="warn",
164
- summary="No database to check schema",
165
- )
166
- conn = sqlite3.connect(str(db_path), timeout=2)
167
- try:
168
- version = conn.execute("PRAGMA user_version").fetchone()[0]
169
- finally:
170
- conn.close()
171
- return DoctorCheck(
172
- id="deep.schema_version",
173
- tier="deep",
174
- status="healthy",
175
- severity="info",
176
- summary=f"DB schema version: {version}",
177
- )
178
- except Exception as e:
179
- return DoctorCheck(
180
- id="deep.schema_version",
181
- tier="deep",
182
- status="degraded",
183
- severity="warn",
184
- summary=f"Schema check failed: {e}",
185
- )
186
-
187
-
188
- def check_preflight_summary() -> DoctorCheck:
189
- """Check runtime preflight summary."""
190
- summary_file = NEXO_HOME / "logs" / "runtime-preflight-summary.json"
191
- age = _file_age_seconds(summary_file)
192
-
193
- if age is None:
194
- return DoctorCheck(
195
- id="deep.preflight",
196
- tier="deep",
197
- status="healthy",
198
- severity="info",
199
- summary="No preflight summary (optional)",
200
- )
201
-
202
- age_hours = age / 3600
203
- if age > PREFLIGHT_FRESHNESS:
204
- return DoctorCheck(
205
- id="deep.preflight",
206
- tier="deep",
207
- status="degraded",
208
- severity="warn",
209
- summary=f"Preflight summary stale ({age_hours:.0f}h old)",
210
- )
211
- try:
212
- data = _load_json(summary_file)
213
- ok = data.get("ok")
214
- checks = data.get("checks") or {}
215
- errors = data.get("errors") or []
216
- if ok is True:
217
- return DoctorCheck(
218
- id="deep.preflight",
219
- tier="deep",
220
- status="healthy",
221
- severity="info",
222
- summary=f"Runtime preflight OK ({len(checks)} checks, {age_hours:.0f}h ago)",
223
- )
224
- return DoctorCheck(
225
- id="deep.preflight",
226
- tier="deep",
227
- status="critical",
228
- severity="error",
229
- summary=f"Runtime preflight failed ({len(errors)} errors, {age_hours:.0f}h ago)",
230
- evidence=errors[:5],
231
- )
232
- except Exception as e:
233
- return DoctorCheck(
234
- id="deep.preflight",
235
- tier="deep",
236
- status="degraded",
237
- severity="warn",
238
- summary=f"Preflight summary unreadable ({age_hours:.0f}h ago)",
239
- evidence=[str(e)],
240
- )
241
-
242
-
243
- def check_watchdog_smoke() -> DoctorCheck:
244
- """Check watchdog smoke summary."""
245
- summary_file = NEXO_HOME / "logs" / "watchdog-smoke-summary.json"
246
- age = _file_age_seconds(summary_file)
247
-
248
- if age is None:
249
- return DoctorCheck(
250
- id="deep.watchdog_smoke",
251
- tier="deep",
252
- status="healthy",
253
- severity="info",
254
- summary="No watchdog smoke summary (optional)",
255
- )
256
-
257
- age_hours = age / 3600
258
- if age > WATCHDOG_SMOKE_FRESHNESS:
259
- return DoctorCheck(
260
- id="deep.watchdog_smoke",
261
- tier="deep",
262
- status="degraded",
263
- severity="warn",
264
- summary=f"Watchdog smoke summary stale ({age_hours:.0f}h old)",
265
- )
266
-
267
- try:
268
- data = _load_json(summary_file)
269
- ok = data.get("ok")
270
- findings = data.get("findings") or []
271
- error_count = sum(1 for finding in findings if finding.get("severity") == "ERROR")
272
- if ok is True:
273
- return DoctorCheck(
274
- id="deep.watchdog_smoke",
275
- tier="deep",
276
- status="healthy",
277
- severity="info",
278
- summary=f"Watchdog smoke OK ({len(findings)} findings, {age_hours:.0f}h ago)",
279
- )
280
- return DoctorCheck(
281
- id="deep.watchdog_smoke",
282
- tier="deep",
283
- status="critical",
284
- severity="error",
285
- summary=f"Watchdog smoke failed ({error_count} errors, {age_hours:.0f}h ago)",
286
- evidence=[finding.get("msg", "") for finding in findings[:5]],
287
- )
288
- except Exception as e:
289
- return DoctorCheck(
290
- id="deep.watchdog_smoke",
291
- tier="deep",
292
- status="degraded",
293
- severity="warn",
294
- summary=f"Watchdog smoke summary unreadable ({age_hours:.0f}h ago)",
295
- evidence=[str(e)],
296
- )
297
-
298
-
299
- def check_learning_count() -> DoctorCheck:
300
- """Check learning count as a health proxy."""
301
- try:
302
- import sqlite3
303
- db_path = NEXO_HOME / "data" / "nexo.db"
304
- if not db_path.is_file():
305
- return DoctorCheck(
306
- id="deep.learning_count",
307
- tier="deep",
308
- status="healthy",
309
- severity="info",
310
- summary="No DB to check learnings",
311
- )
312
- conn = sqlite3.connect(str(db_path), timeout=2)
313
- try:
314
- tables = conn.execute(
315
- "SELECT name FROM sqlite_master WHERE type='table' AND name='learnings'"
316
- ).fetchone()
317
- if not tables:
318
- return DoctorCheck(
319
- id="deep.learning_count",
320
- tier="deep",
321
- status="healthy",
322
- severity="info",
323
- summary="No learnings table yet",
324
- )
325
- columns = {
326
- row[1]
327
- for row in conn.execute("PRAGMA table_info(learnings)").fetchall()
328
- }
329
- if "status" in columns:
330
- count = conn.execute(
331
- "SELECT COUNT(*) FROM learnings WHERE COALESCE(status, 'active') != 'archived'"
332
- ).fetchone()[0]
333
- elif "archived" in columns:
334
- count = conn.execute(
335
- "SELECT COUNT(*) FROM learnings WHERE archived=0"
336
- ).fetchone()[0]
337
- else:
338
- count = conn.execute("SELECT COUNT(*) FROM learnings").fetchone()[0]
339
- finally:
340
- conn.close()
341
- return DoctorCheck(
342
- id="deep.learning_count",
343
- tier="deep",
344
- status="healthy",
345
- severity="info",
346
- summary=f"{count} non-archived learnings in memory",
347
- )
348
- except Exception as e:
349
- return DoctorCheck(
350
- id="deep.learning_count",
351
- tier="deep",
352
- status="degraded",
353
- severity="warn",
354
- summary=f"Learning check unreadable: {e}",
355
- evidence=[str(e)],
356
- )
357
-
358
-
359
- def run_deep_checks(fix: bool = False) -> list[DoctorCheck]:
360
- """Run all deep-tier checks. Read-only."""
361
- return [
362
- safe_check(check_self_audit_summary),
363
- safe_check(check_schema_version),
364
- safe_check(check_preflight_summary),
365
- safe_check(check_watchdog_smoke),
366
- safe_check(check_learning_count),
367
- ]