nexo-brain 2.6.12 → 2.6.13
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.
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +3 -1
- package/package.json +1 -1
- package/src/plugins/schedule.py +69 -12
- package/src/script_registry.py +62 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nexo-brain",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.13",
|
|
4
4
|
"description": "Local cognitive runtime for Claude Code \u2014 persistent memory, overnight learning, doctor diagnostics, personal scripts, recovery-aware jobs, startup preflight, and optional dashboard/power helper.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "NEXO Brain",
|
package/README.md
CHANGED
|
@@ -484,7 +484,7 @@ Core and personal jobs now declare explicit recovery contracts in `crons/manifes
|
|
|
484
484
|
|
|
485
485
|
| Field | Purpose |
|
|
486
486
|
|-------|---------|
|
|
487
|
-
| `recovery_policy` | `catchup`, `restart`, or `skip` |
|
|
487
|
+
| `recovery_policy` | `catchup`, `restart`, `restart_daemon`, or `skip` |
|
|
488
488
|
| `run_on_boot` | Re-run when the machine starts |
|
|
489
489
|
| `run_on_wake` | Re-run after sleep/resume |
|
|
490
490
|
| `idempotent` | Safe to re-run without side effects |
|
|
@@ -492,6 +492,8 @@ Core and personal jobs now declare explicit recovery contracts in `crons/manifes
|
|
|
492
492
|
|
|
493
493
|
If the Mac was asleep during a scheduled window, `catchup` detects the gap from `cron_runs` (not a state file) and re-executes eligible jobs once. Interval-based personal scripts get a single recovery run, not repeated ticks.
|
|
494
494
|
|
|
495
|
+
For personal daemon-style helpers, `recovery_policy=restart_daemon` plus `schedule_required=true` declares an official `KeepAlive` schedule. NEXO can now reconcile and repair those daemons instead of treating them as unmanaged legacy LaunchAgents.
|
|
496
|
+
|
|
495
497
|
## Startup Preflight (v2.6.2)
|
|
496
498
|
|
|
497
499
|
Before `nexo chat` or MCP server start, NEXO runs a preflight check:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nexo-brain",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.13",
|
|
4
4
|
"mcpName": "io.github.wazionapps/nexo",
|
|
5
5
|
"description": "NEXO — local cognitive runtime for Claude Code. Persistent memory, overnight learning, recovery-aware crons, personal scripts, doctor diagnostics, startup preflight, and optional power helper.",
|
|
6
6
|
"bin": {
|
package/src/plugins/schedule.py
CHANGED
|
@@ -56,21 +56,20 @@ def handle_schedule_status(hours: int = 24, cron_id: str = '') -> str:
|
|
|
56
56
|
|
|
57
57
|
def handle_schedule_add(cron_id: str, script: str, schedule: str = '',
|
|
58
58
|
interval_seconds: int = 0, description: str = '',
|
|
59
|
-
script_type: str = 'auto') -> str:
|
|
59
|
+
script_type: str = 'auto', keep_alive: bool = False) -> str:
|
|
60
60
|
"""Add a new personal cron job. Generates and installs the LaunchAgent (macOS) or systemd timer (Linux).
|
|
61
61
|
|
|
62
62
|
Args:
|
|
63
63
|
cron_id: Unique ID for this cron (e.g. 'my-backup', 'report-daily'). Must be lowercase with hyphens.
|
|
64
64
|
script: Path to the script to run (absolute or relative to NEXO_HOME/scripts/).
|
|
65
65
|
schedule: Time-based schedule as 'HH:MM' (daily) or 'HH:MM:weekday' (e.g. '08:00:1' for Monday 8AM). Mutually exclusive with interval_seconds.
|
|
66
|
-
interval_seconds: Run every N seconds (e.g. 300 for every 5 min). Mutually exclusive with schedule.
|
|
66
|
+
interval_seconds: Run every N seconds (e.g. 300 for every 5 min). Mutually exclusive with schedule/keep_alive.
|
|
67
67
|
description: What this cron does (for logs and status).
|
|
68
68
|
script_type: 'auto' (default), 'python', 'shell', 'node', or 'php'.
|
|
69
|
+
keep_alive: Run as a daemon/keep-alive service instead of a timer.
|
|
69
70
|
"""
|
|
70
71
|
if not cron_id or not script:
|
|
71
72
|
return "ERROR: cron_id and script are required."
|
|
72
|
-
if not schedule and not interval_seconds:
|
|
73
|
-
return "ERROR: either schedule (e.g. '08:00') or interval_seconds (e.g. 300) is required."
|
|
74
73
|
|
|
75
74
|
nexo_home = Path(os.environ.get("NEXO_HOME", str(Path.home() / ".nexo")))
|
|
76
75
|
script_path = Path(script)
|
|
@@ -82,6 +81,11 @@ def handle_schedule_add(cron_id: str, script: str, schedule: str = '',
|
|
|
82
81
|
script_meta = parse_inline_metadata(script_path)
|
|
83
82
|
detected_runtime = classify_runtime(script_path, script_meta)
|
|
84
83
|
declared = get_declared_schedule(script_meta, script_meta.get("name", script_path.stem))
|
|
84
|
+
keep_alive = bool(keep_alive or declared.get("schedule_type") == "keep_alive")
|
|
85
|
+
|
|
86
|
+
if sum(bool(value) for value in [schedule, interval_seconds, keep_alive]) != 1:
|
|
87
|
+
return "ERROR: choose exactly one schedule mode: schedule, interval_seconds, or keep_alive."
|
|
88
|
+
|
|
85
89
|
script_type = (script_type or "auto").strip().lower()
|
|
86
90
|
if script_type == "auto":
|
|
87
91
|
script_type = detected_runtime if detected_runtime != "unknown" else "python"
|
|
@@ -102,6 +106,7 @@ def handle_schedule_add(cron_id: str, script: str, schedule: str = '',
|
|
|
102
106
|
description or script_meta.get("description", ""),
|
|
103
107
|
script_type,
|
|
104
108
|
nexo_home,
|
|
109
|
+
keep_alive=keep_alive,
|
|
105
110
|
declared=declared,
|
|
106
111
|
)
|
|
107
112
|
elif system == "Linux":
|
|
@@ -114,6 +119,7 @@ def handle_schedule_add(cron_id: str, script: str, schedule: str = '',
|
|
|
114
119
|
description or script_meta.get("description", ""),
|
|
115
120
|
script_type,
|
|
116
121
|
nexo_home,
|
|
122
|
+
keep_alive=keep_alive,
|
|
117
123
|
declared=declared,
|
|
118
124
|
)
|
|
119
125
|
else:
|
|
@@ -134,7 +140,7 @@ def _runtime_command(script_type: str) -> str:
|
|
|
134
140
|
return "python3"
|
|
135
141
|
|
|
136
142
|
|
|
137
|
-
def _register_schedule_metadata(cron_id, script_path, schedule, interval_seconds, description, script_type, label="", plist_path=""):
|
|
143
|
+
def _register_schedule_metadata(cron_id, script_path, schedule, interval_seconds, description, script_type, label="", plist_path="", keep_alive: bool = False):
|
|
138
144
|
init_db()
|
|
139
145
|
script_meta = parse_inline_metadata(Path(script_path))
|
|
140
146
|
runtime = classify_runtime(Path(script_path), script_meta)
|
|
@@ -148,7 +154,11 @@ def _register_schedule_metadata(cron_id, script_path, schedule, interval_seconds
|
|
|
148
154
|
source="filesystem",
|
|
149
155
|
has_inline_metadata=bool(script_meta),
|
|
150
156
|
)
|
|
151
|
-
if
|
|
157
|
+
if keep_alive:
|
|
158
|
+
schedule_type = "keep_alive"
|
|
159
|
+
schedule_value = "true"
|
|
160
|
+
schedule_label = "keep alive"
|
|
161
|
+
elif interval_seconds:
|
|
152
162
|
schedule_type = "interval"
|
|
153
163
|
schedule_value = str(interval_seconds)
|
|
154
164
|
schedule_label = f"every {interval_seconds}s"
|
|
@@ -174,7 +184,7 @@ def _register_schedule_metadata(cron_id, script_path, schedule, interval_seconds
|
|
|
174
184
|
|
|
175
185
|
|
|
176
186
|
def _add_launchagent(cron_id, script_path, wrapper_path, schedule, interval_seconds,
|
|
177
|
-
description, script_type, nexo_home, *, declared: dict | None = None):
|
|
187
|
+
description, script_type, nexo_home, *, keep_alive: bool = False, declared: dict | None = None):
|
|
178
188
|
"""Create and load a macOS LaunchAgent."""
|
|
179
189
|
import plistlib
|
|
180
190
|
|
|
@@ -201,7 +211,9 @@ def _add_launchagent(cron_id, script_path, wrapper_path, schedule, interval_seco
|
|
|
201
211
|
},
|
|
202
212
|
}
|
|
203
213
|
|
|
204
|
-
if
|
|
214
|
+
if keep_alive:
|
|
215
|
+
plist["KeepAlive"] = True
|
|
216
|
+
elif interval_seconds:
|
|
205
217
|
plist["StartInterval"] = interval_seconds
|
|
206
218
|
elif schedule:
|
|
207
219
|
parts = schedule.split(":")
|
|
@@ -211,7 +223,7 @@ def _add_launchagent(cron_id, script_path, wrapper_path, schedule, interval_seco
|
|
|
211
223
|
plist["StartCalendarInterval"] = cal
|
|
212
224
|
|
|
213
225
|
declared = declared or {}
|
|
214
|
-
if declared.get("run_on_boot"):
|
|
226
|
+
if declared.get("run_on_boot") or (keep_alive and "run_on_boot" not in declared):
|
|
215
227
|
plist["RunAtLoad"] = True
|
|
216
228
|
|
|
217
229
|
with open(plist_path, "wb") as f:
|
|
@@ -228,13 +240,20 @@ def _add_launchagent(cron_id, script_path, wrapper_path, schedule, interval_seco
|
|
|
228
240
|
script_type,
|
|
229
241
|
label=label,
|
|
230
242
|
plist_path=str(plist_path),
|
|
243
|
+
keep_alive=keep_alive,
|
|
231
244
|
)
|
|
232
245
|
|
|
233
|
-
|
|
246
|
+
if keep_alive:
|
|
247
|
+
detail = " KeepAlive daemon"
|
|
248
|
+
elif schedule:
|
|
249
|
+
detail = f" Schedule: {schedule}"
|
|
250
|
+
else:
|
|
251
|
+
detail = f" Interval: {interval_seconds}s"
|
|
252
|
+
return f"Cron '{cron_id}' installed at {plist_path} and loaded.{detail}"
|
|
234
253
|
|
|
235
254
|
|
|
236
255
|
def _add_systemd_timer(cron_id, script_path, wrapper_path, schedule, interval_seconds,
|
|
237
|
-
description, script_type, nexo_home, *, declared: dict | None = None):
|
|
256
|
+
description, script_type, nexo_home, *, keep_alive: bool = False, declared: dict | None = None):
|
|
238
257
|
"""Create and enable a systemd user timer (Linux)."""
|
|
239
258
|
unit_dir = Path.home() / ".config" / "systemd" / "user"
|
|
240
259
|
unit_dir.mkdir(parents=True, exist_ok=True)
|
|
@@ -257,9 +276,46 @@ Environment=NEXO_PERSONAL_CRON_ID={cron_id}
|
|
|
257
276
|
service_path = unit_dir / f"nexo-{cron_id}.service"
|
|
258
277
|
service_path.write_text(service_content)
|
|
259
278
|
|
|
260
|
-
# Timer unit
|
|
261
279
|
declared = declared or {}
|
|
262
280
|
|
|
281
|
+
if keep_alive:
|
|
282
|
+
service_content = f"""[Unit]
|
|
283
|
+
Description=NEXO daemon: {description or cron_id}
|
|
284
|
+
|
|
285
|
+
[Service]
|
|
286
|
+
Type=simple
|
|
287
|
+
ExecStart={exec_cmd}
|
|
288
|
+
Restart=always
|
|
289
|
+
RestartSec=10
|
|
290
|
+
Environment=NEXO_HOME={nexo_home}
|
|
291
|
+
Environment=HOME={Path.home()}
|
|
292
|
+
Environment={PERSONAL_SCHEDULE_MANAGED_ENV}=1
|
|
293
|
+
Environment=NEXO_PERSONAL_CRON_ID={cron_id}
|
|
294
|
+
|
|
295
|
+
[Install]
|
|
296
|
+
WantedBy=default.target
|
|
297
|
+
"""
|
|
298
|
+
service_path = unit_dir / f"nexo-{cron_id}.service"
|
|
299
|
+
service_path.write_text(service_content)
|
|
300
|
+
|
|
301
|
+
subprocess.run(["systemctl", "--user", "daemon-reload"], capture_output=True)
|
|
302
|
+
subprocess.run(["systemctl", "--user", "enable", "--now", f"nexo-{cron_id}.service"], capture_output=True)
|
|
303
|
+
|
|
304
|
+
_register_schedule_metadata(
|
|
305
|
+
cron_id,
|
|
306
|
+
script_path,
|
|
307
|
+
schedule,
|
|
308
|
+
interval_seconds,
|
|
309
|
+
description,
|
|
310
|
+
script_type,
|
|
311
|
+
label=f"nexo-{cron_id}",
|
|
312
|
+
plist_path="",
|
|
313
|
+
keep_alive=True,
|
|
314
|
+
)
|
|
315
|
+
|
|
316
|
+
return f"Cron '{cron_id}' installed as KeepAlive systemd service and enabled. Service: {service_path}"
|
|
317
|
+
|
|
318
|
+
# Timer unit
|
|
263
319
|
if interval_seconds:
|
|
264
320
|
timer_spec = f"OnUnitActiveSec={interval_seconds}s"
|
|
265
321
|
if declared.get("run_on_boot") or not declared.get("required"):
|
|
@@ -301,6 +357,7 @@ WantedBy=timers.target
|
|
|
301
357
|
script_type,
|
|
302
358
|
label=f"nexo-{cron_id}",
|
|
303
359
|
plist_path="",
|
|
360
|
+
keep_alive=False,
|
|
304
361
|
)
|
|
305
362
|
|
|
306
363
|
return f"Cron '{cron_id}' installed as systemd timer and enabled. Service: {service_path}, Timer: {timer_path}"
|
package/src/script_registry.py
CHANGED
|
@@ -32,6 +32,16 @@ _IGNORED_FILES = {
|
|
|
32
32
|
}
|
|
33
33
|
_IGNORED_DIRS = {"deep-sleep", "__pycache__"}
|
|
34
34
|
|
|
35
|
+
_LEGACY_WAKE_RECOVERY_METADATA = [
|
|
36
|
+
"# nexo: name=nexo-wake-recovery",
|
|
37
|
+
"# nexo: description=Recover interval LaunchAgents after macOS sleep/wake gaps",
|
|
38
|
+
"# nexo: runtime=shell",
|
|
39
|
+
"# nexo: cron_id=wake-recovery",
|
|
40
|
+
"# nexo: schedule_required=true",
|
|
41
|
+
"# nexo: recovery_policy=restart_daemon",
|
|
42
|
+
"# nexo: run_on_boot=true",
|
|
43
|
+
]
|
|
44
|
+
|
|
35
45
|
# Forbidden patterns — direct DB access from personal scripts
|
|
36
46
|
_FORBIDDEN_PATTERNS = [
|
|
37
47
|
re.compile(r"\bsqlite3\b"),
|
|
@@ -77,6 +87,33 @@ def get_scripts_dir() -> Path:
|
|
|
77
87
|
return NEXO_HOME / "scripts"
|
|
78
88
|
|
|
79
89
|
|
|
90
|
+
def _apply_legacy_personal_script_backfills() -> None:
|
|
91
|
+
"""Backfill metadata for known legacy personal scripts shipped before the registry existed."""
|
|
92
|
+
scripts_dir = get_scripts_dir()
|
|
93
|
+
wake_recovery = scripts_dir / "nexo-wake-recovery.sh"
|
|
94
|
+
if not wake_recovery.is_file():
|
|
95
|
+
return
|
|
96
|
+
|
|
97
|
+
try:
|
|
98
|
+
text = wake_recovery.read_text()
|
|
99
|
+
except Exception:
|
|
100
|
+
return
|
|
101
|
+
|
|
102
|
+
if "# nexo:" in "\n".join(text.splitlines()[:25]):
|
|
103
|
+
return
|
|
104
|
+
if "Wake Recovery" not in text:
|
|
105
|
+
return
|
|
106
|
+
|
|
107
|
+
lines = text.splitlines(keepends=True)
|
|
108
|
+
head: list[str] = []
|
|
109
|
+
start = 0
|
|
110
|
+
if lines and lines[0].startswith("#!"):
|
|
111
|
+
head.append(lines[0])
|
|
112
|
+
start = 1
|
|
113
|
+
head.extend([line + "\n" for line in _LEGACY_WAKE_RECOVERY_METADATA])
|
|
114
|
+
wake_recovery.write_text("".join(head + lines[start:]))
|
|
115
|
+
|
|
116
|
+
|
|
80
117
|
def load_core_script_names() -> set[str]:
|
|
81
118
|
"""Load script names from crons/manifest.json (these are core, not personal)."""
|
|
82
119
|
names: set[str] = set()
|
|
@@ -279,6 +316,11 @@ def get_declared_schedule(metadata: dict, default_name: str = "") -> dict:
|
|
|
279
316
|
"cron_id": cron_id,
|
|
280
317
|
}
|
|
281
318
|
|
|
319
|
+
def _effective_run_on_boot(policy: str) -> bool:
|
|
320
|
+
if "run_on_boot" in metadata:
|
|
321
|
+
return run_on_boot
|
|
322
|
+
return policy == "restart_daemon"
|
|
323
|
+
|
|
282
324
|
def _effective_run_on_wake(policy: str) -> bool:
|
|
283
325
|
if "run_on_wake" in metadata:
|
|
284
326
|
return run_on_wake
|
|
@@ -379,12 +421,29 @@ def get_declared_schedule(metadata: dict, default_name: str = "") -> dict:
|
|
|
379
421
|
"schedule": schedule_raw,
|
|
380
422
|
"interval_seconds": 0,
|
|
381
423
|
"recovery_policy": recovery_policy_raw or "catchup",
|
|
382
|
-
"run_on_boot":
|
|
424
|
+
"run_on_boot": _effective_run_on_boot(recovery_policy_raw or "catchup"),
|
|
383
425
|
"run_on_wake": _effective_run_on_wake(recovery_policy_raw or "catchup"),
|
|
384
426
|
"idempotent": _effective_idempotent(recovery_policy_raw or "catchup"),
|
|
385
427
|
"max_catchup_age": max_catchup_age or (14 * 86400 if weekday is not None else 48 * 3600),
|
|
386
428
|
}
|
|
387
429
|
|
|
430
|
+
if required and recovery_policy_raw == "restart_daemon":
|
|
431
|
+
return {
|
|
432
|
+
"required": required,
|
|
433
|
+
"valid": True,
|
|
434
|
+
"cron_id": cron_id,
|
|
435
|
+
"schedule_type": "keep_alive",
|
|
436
|
+
"schedule_value": "true",
|
|
437
|
+
"schedule_label": "keep alive",
|
|
438
|
+
"schedule": "",
|
|
439
|
+
"interval_seconds": 0,
|
|
440
|
+
"recovery_policy": "restart_daemon",
|
|
441
|
+
"run_on_boot": _effective_run_on_boot("restart_daemon"),
|
|
442
|
+
"run_on_wake": _effective_run_on_wake("restart_daemon"),
|
|
443
|
+
"idempotent": _effective_idempotent("restart_daemon"),
|
|
444
|
+
"max_catchup_age": max_catchup_age,
|
|
445
|
+
}
|
|
446
|
+
|
|
388
447
|
return {
|
|
389
448
|
"required": required,
|
|
390
449
|
"valid": not required,
|
|
@@ -416,6 +475,7 @@ def _script_entry(path: Path, meta: dict, *, is_core: bool, classification: str,
|
|
|
416
475
|
|
|
417
476
|
def classify_scripts_dir() -> dict:
|
|
418
477
|
"""Classify every file in NEXO_HOME/scripts into personal/core/ignored/non-script buckets."""
|
|
478
|
+
_apply_legacy_personal_script_backfills()
|
|
419
479
|
scripts_dir = get_scripts_dir()
|
|
420
480
|
if not scripts_dir.is_dir():
|
|
421
481
|
return {"scripts_dir": str(scripts_dir), "entries": [], "summary": {}}
|
|
@@ -927,6 +987,7 @@ def ensure_personal_schedules(*, dry_run: bool = False) -> dict:
|
|
|
927
987
|
interval_seconds=declared.get("interval_seconds", 0),
|
|
928
988
|
description=script.get("description", ""),
|
|
929
989
|
script_type=script.get("runtime", "auto"),
|
|
990
|
+
keep_alive=declared.get("schedule_type") == "keep_alive",
|
|
930
991
|
)
|
|
931
992
|
target = report["repaired" if existing else "created"]
|
|
932
993
|
target.append({
|