nexo-brain 5.3.11 → 5.3.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 -5
- package/package.json +1 -1
- package/src/agent_runner.py +2 -0
- package/src/auto_update.py +116 -4
- package/src/cli.py +8 -2
- package/src/client_preferences.py +26 -7
- package/src/client_sync.py +3 -2
- package/src/doctor/orchestrator.py +10 -1
- package/src/doctor/planes.py +87 -0
- package/src/hook_guardrails.py +147 -11
- package/src/plugins/doctor.py +3 -2
- package/src/plugins/schedule.py +119 -1
- package/src/runtime_power.py +3 -2
- package/src/scripts/check-context.py +7 -1
- package/src/scripts/deep-sleep/extract.py +8 -2
- package/src/scripts/deep-sleep/synthesize.py +8 -1
- package/src/scripts/nexo-catchup.py +8 -2
- package/src/scripts/nexo-cortex-cycle.py +48 -21
- package/src/scripts/nexo-daily-self-audit.py +56 -23
- package/src/scripts/nexo-evolution-run.py +10 -2
- package/src/scripts/nexo-immune.py +8 -1
- package/src/scripts/nexo-learning-validator.py +9 -1
- package/src/scripts/nexo-postmortem-consolidator.py +9 -1
- package/src/scripts/nexo-sleep.py +7 -1
- package/src/scripts/nexo-synthesis.py +8 -1
- package/src/scripts/rehydrate_learnings_from_archive.py +245 -0
- package/src/server.py +2 -0
- package/src/skills/run-nexo-core-fix-cycle/guide.md +17 -0
- package/src/skills/run-nexo-core-fix-cycle/script.py +276 -0
- package/src/skills/run-nexo-core-fix-cycle/skill.json +58 -0
- package/src/skills/run-release-final-audit/guide.md +5 -3
- package/src/skills/run-release-final-audit/script.py +17 -8
- package/src/skills/run-release-final-audit/skill.json +15 -2
- package/src/skills/run-runtime-doctor/script.py +1 -1
|
@@ -37,6 +37,12 @@ if str(NEXO_CODE) not in sys.path:
|
|
|
37
37
|
sys.path.insert(0, str(NEXO_CODE))
|
|
38
38
|
|
|
39
39
|
from agent_runner import AutomationBackendUnavailableError, run_automation_prompt
|
|
40
|
+
try:
|
|
41
|
+
from client_preferences import resolve_user_model as _resolve_user_model
|
|
42
|
+
_USER_MODEL = _resolve_user_model()
|
|
43
|
+
except Exception:
|
|
44
|
+
_USER_MODEL = ""
|
|
45
|
+
|
|
40
46
|
|
|
41
47
|
# ─── Paths ────────────────────────────────────────────────────────────────────
|
|
42
48
|
CLAUDE_DIR = NEXO_HOME
|
|
@@ -439,7 +445,7 @@ Execute without asking."""
|
|
|
439
445
|
try:
|
|
440
446
|
result = run_automation_prompt(
|
|
441
447
|
prompt,
|
|
442
|
-
model="opus",
|
|
448
|
+
model=_USER_MODEL or "opus",
|
|
443
449
|
timeout=21600,
|
|
444
450
|
output_format="text",
|
|
445
451
|
allowed_tools="Read,Write,Edit,Glob,Grep,Bash,mcp__nexo__*",
|
|
@@ -18,6 +18,13 @@ import sys
|
|
|
18
18
|
from datetime import datetime, date, timedelta
|
|
19
19
|
from pathlib import Path
|
|
20
20
|
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
from client_preferences import resolve_user_model as _resolve_user_model
|
|
24
|
+
_USER_MODEL = _resolve_user_model()
|
|
25
|
+
except Exception:
|
|
26
|
+
_USER_MODEL = ""
|
|
27
|
+
|
|
21
28
|
HOME = Path.home()
|
|
22
29
|
NEXO_HOME = Path(os.environ.get("NEXO_HOME", str(Path.home() / ".nexo")))
|
|
23
30
|
_script_dir = Path(__file__).resolve().parent
|
|
@@ -340,7 +347,7 @@ Execute without asking."""
|
|
|
340
347
|
try:
|
|
341
348
|
result = run_automation_prompt(
|
|
342
349
|
prompt,
|
|
343
|
-
model="opus",
|
|
350
|
+
model=_USER_MODEL or "opus",
|
|
344
351
|
timeout=21600,
|
|
345
352
|
output_format="text",
|
|
346
353
|
allowed_tools="Read,Write,Edit,Glob,Grep,Bash,mcp__nexo__*",
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
"""Rehydrate archived markdown learnings back into the NEXO learnings table.
|
|
5
|
+
|
|
6
|
+
The original Evolution #5 incident found an empty learnings table while the
|
|
7
|
+
historical archive still existed as markdown grouped by domain. This helper
|
|
8
|
+
parses the archive format used in those files:
|
|
9
|
+
|
|
10
|
+
- markdown tables with `Error | Solucion`
|
|
11
|
+
- dated sections with bullet/numbered operational learnings
|
|
12
|
+
|
|
13
|
+
Dry-run is the default. Pass `--apply` to insert missing learnings.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import argparse
|
|
17
|
+
import re
|
|
18
|
+
import sys
|
|
19
|
+
from dataclasses import dataclass
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
|
|
22
|
+
REPO_SRC = Path(__file__).resolve().parents[1]
|
|
23
|
+
if str(REPO_SRC) not in sys.path:
|
|
24
|
+
sys.path.insert(0, str(REPO_SRC))
|
|
25
|
+
|
|
26
|
+
from db import create_learning, get_db, init_db # noqa: E402
|
|
27
|
+
from runtime_home import export_resolved_nexo_home # noqa: E402
|
|
28
|
+
|
|
29
|
+
NEXO_HOME = export_resolved_nexo_home()
|
|
30
|
+
TABLE_HEADER_TITLES = {"error", "problema", "issue"}
|
|
31
|
+
DEFAULT_ARCHIVE_DIRS = (
|
|
32
|
+
NEXO_HOME / "claude" / "operations" / "archive" / "learnings",
|
|
33
|
+
Path.home() / "claude" / "operations" / "archive" / "learnings",
|
|
34
|
+
Path.home() / ".claude" / "operations" / "archive" / "learnings",
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclass(frozen=True)
|
|
39
|
+
class LearningCandidate:
|
|
40
|
+
category: str
|
|
41
|
+
title: str
|
|
42
|
+
content: str
|
|
43
|
+
reasoning: str
|
|
44
|
+
prevention: str
|
|
45
|
+
status: str = "active"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _strip_markdown(text: str) -> str:
|
|
49
|
+
text = text.replace("**", "").replace("__", "")
|
|
50
|
+
text = text.replace("~~", "")
|
|
51
|
+
text = re.sub(r"`([^`]*)`", r"\1", text)
|
|
52
|
+
text = re.sub(r"\[([^\]]+)\]\([^)]+\)", r"\1", text)
|
|
53
|
+
text = re.sub(r"\s+", " ", text).strip(" |")
|
|
54
|
+
return text.strip()
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _derive_title(text: str) -> str:
|
|
58
|
+
first_sentence = re.split(r"(?<=[.!?])\s+", text, maxsplit=1)[0].strip()
|
|
59
|
+
if not first_sentence:
|
|
60
|
+
first_sentence = text.strip()
|
|
61
|
+
return first_sentence[:180].rstrip(" .")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _derive_prevention(text: str) -> str:
|
|
65
|
+
match = re.search(r"(Regla:\s*.*|SIEMPRE\s+.*|NUNCA\s+.*)", text, flags=re.IGNORECASE)
|
|
66
|
+
if match:
|
|
67
|
+
return match.group(1).strip()
|
|
68
|
+
return text[:500].strip()
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _candidate_reasoning(path: Path, section: str) -> str:
|
|
72
|
+
section_note = f" [{section}]" if section and section != path.stem else ""
|
|
73
|
+
return f"Rehydrated from markdown archive {path.name}{section_note}"
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _parse_table_row(path: Path, section: str, line: str) -> LearningCandidate | None:
|
|
77
|
+
parts = [_strip_markdown(cell) for cell in line.strip().strip("|").split("|")]
|
|
78
|
+
if len(parts) < 2:
|
|
79
|
+
return None
|
|
80
|
+
title, prevention = parts[0], parts[1]
|
|
81
|
+
if title.lower() in TABLE_HEADER_TITLES or set(title) <= {"-"}:
|
|
82
|
+
return None
|
|
83
|
+
if not title or not prevention:
|
|
84
|
+
return None
|
|
85
|
+
status = "superseded" if "obsoleto" in prevention.lower() or "obsoleto" in title.lower() else "active"
|
|
86
|
+
content = f"{title}. {prevention}"
|
|
87
|
+
return LearningCandidate(
|
|
88
|
+
category=path.stem,
|
|
89
|
+
title=title,
|
|
90
|
+
content=content,
|
|
91
|
+
reasoning=_candidate_reasoning(path, section),
|
|
92
|
+
prevention=prevention,
|
|
93
|
+
status=status,
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def _consume_bullet_block(lines: list[str], start: int) -> tuple[str, int]:
|
|
98
|
+
pieces = [re.sub(r"^([-*]|\d+\.)\s+", "", lines[start].strip())]
|
|
99
|
+
idx = start + 1
|
|
100
|
+
while idx < len(lines):
|
|
101
|
+
stripped = lines[idx].strip()
|
|
102
|
+
if not stripped:
|
|
103
|
+
break
|
|
104
|
+
if stripped.startswith("## ") or stripped.startswith("|"):
|
|
105
|
+
break
|
|
106
|
+
if re.match(r"^([-*]|\d+\.)\s+", stripped):
|
|
107
|
+
break
|
|
108
|
+
pieces.append(stripped)
|
|
109
|
+
idx += 1
|
|
110
|
+
return _strip_markdown(" ".join(pieces)), idx
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def _parse_bullet(path: Path, section: str, text: str) -> LearningCandidate | None:
|
|
114
|
+
if len(text) < 12:
|
|
115
|
+
return None
|
|
116
|
+
title = _derive_title(text)
|
|
117
|
+
prevention = _derive_prevention(text)
|
|
118
|
+
status = "superseded" if "obsoleto" in text.lower() else "active"
|
|
119
|
+
return LearningCandidate(
|
|
120
|
+
category=path.stem,
|
|
121
|
+
title=title,
|
|
122
|
+
content=text,
|
|
123
|
+
reasoning=_candidate_reasoning(path, section),
|
|
124
|
+
prevention=prevention,
|
|
125
|
+
status=status,
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def parse_archive_file(path: Path) -> list[LearningCandidate]:
|
|
130
|
+
lines = path.read_text(encoding="utf-8", errors="ignore").splitlines()
|
|
131
|
+
section = path.stem
|
|
132
|
+
results: list[LearningCandidate] = []
|
|
133
|
+
idx = 0
|
|
134
|
+
while idx < len(lines):
|
|
135
|
+
stripped = lines[idx].strip()
|
|
136
|
+
if stripped.startswith("## "):
|
|
137
|
+
section = _strip_markdown(stripped[3:])
|
|
138
|
+
idx += 1
|
|
139
|
+
continue
|
|
140
|
+
if stripped.startswith("|") and not re.match(r"^\|\s*-", stripped):
|
|
141
|
+
row = _parse_table_row(path, section, stripped)
|
|
142
|
+
if row is not None:
|
|
143
|
+
results.append(row)
|
|
144
|
+
idx += 1
|
|
145
|
+
continue
|
|
146
|
+
if re.match(r"^([-*]|\d+\.)\s+", stripped):
|
|
147
|
+
block, next_idx = _consume_bullet_block(lines, idx)
|
|
148
|
+
row = _parse_bullet(path, section, block)
|
|
149
|
+
if row is not None:
|
|
150
|
+
results.append(row)
|
|
151
|
+
idx = next_idx
|
|
152
|
+
continue
|
|
153
|
+
idx += 1
|
|
154
|
+
return results
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def parse_archive_dir(archive_dir: Path) -> list[LearningCandidate]:
|
|
158
|
+
candidates: list[LearningCandidate] = []
|
|
159
|
+
for path in sorted(archive_dir.glob("*.md")):
|
|
160
|
+
candidates.extend(parse_archive_file(path))
|
|
161
|
+
|
|
162
|
+
deduped: list[LearningCandidate] = []
|
|
163
|
+
seen: set[tuple[str, str]] = set()
|
|
164
|
+
for item in candidates:
|
|
165
|
+
key = (item.category.lower(), item.title.lower())
|
|
166
|
+
if key in seen:
|
|
167
|
+
continue
|
|
168
|
+
seen.add(key)
|
|
169
|
+
deduped.append(item)
|
|
170
|
+
return deduped
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def resolve_archive_dir(explicit: str = "") -> Path:
|
|
174
|
+
if explicit:
|
|
175
|
+
path = Path(explicit).expanduser()
|
|
176
|
+
if not path.is_dir():
|
|
177
|
+
raise FileNotFoundError(f"archive dir not found: {path}")
|
|
178
|
+
return path
|
|
179
|
+
for candidate in DEFAULT_ARCHIVE_DIRS:
|
|
180
|
+
if candidate.is_dir():
|
|
181
|
+
return candidate
|
|
182
|
+
raise FileNotFoundError(
|
|
183
|
+
"No learnings archive found. Tried: "
|
|
184
|
+
+ ", ".join(str(path) for path in DEFAULT_ARCHIVE_DIRS)
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def apply_candidates(candidates: list[LearningCandidate], *, apply: bool) -> dict:
|
|
189
|
+
init_db()
|
|
190
|
+
conn = get_db()
|
|
191
|
+
existing = {
|
|
192
|
+
(row[0].lower(), row[1].lower())
|
|
193
|
+
for row in conn.execute("SELECT category, title FROM learnings").fetchall()
|
|
194
|
+
}
|
|
195
|
+
inserted = 0
|
|
196
|
+
skipped = 0
|
|
197
|
+
for item in candidates:
|
|
198
|
+
key = (item.category.lower(), item.title.lower())
|
|
199
|
+
if key in existing:
|
|
200
|
+
skipped += 1
|
|
201
|
+
continue
|
|
202
|
+
if apply:
|
|
203
|
+
create_learning(
|
|
204
|
+
item.category,
|
|
205
|
+
item.title,
|
|
206
|
+
item.content,
|
|
207
|
+
reasoning=item.reasoning,
|
|
208
|
+
prevention=item.prevention,
|
|
209
|
+
status=item.status,
|
|
210
|
+
)
|
|
211
|
+
existing.add(key)
|
|
212
|
+
inserted += 1
|
|
213
|
+
return {
|
|
214
|
+
"parsed": len(candidates),
|
|
215
|
+
"inserted": inserted,
|
|
216
|
+
"skipped_existing": skipped,
|
|
217
|
+
"mode": "apply" if apply else "dry-run",
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def build_arg_parser() -> argparse.ArgumentParser:
|
|
222
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
223
|
+
parser.add_argument("--archive-dir", default="", help="Override archive directory")
|
|
224
|
+
parser.add_argument("--apply", action="store_true", help="Insert parsed learnings into the DB")
|
|
225
|
+
return parser
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def main(argv: list[str] | None = None) -> int:
|
|
229
|
+
args = build_arg_parser().parse_args(argv)
|
|
230
|
+
try:
|
|
231
|
+
archive_dir = resolve_archive_dir(args.archive_dir)
|
|
232
|
+
except FileNotFoundError as exc:
|
|
233
|
+
print(f"ERROR: {exc}", file=sys.stderr)
|
|
234
|
+
return 1
|
|
235
|
+
candidates = parse_archive_dir(archive_dir)
|
|
236
|
+
summary = apply_candidates(candidates, apply=args.apply)
|
|
237
|
+
print(
|
|
238
|
+
f"{summary['mode']}: archive={archive_dir} parsed={summary['parsed']} "
|
|
239
|
+
f"inserted={summary['inserted']} skipped_existing={summary['skipped_existing']}"
|
|
240
|
+
)
|
|
241
|
+
return 0
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
if __name__ == "__main__":
|
|
245
|
+
raise SystemExit(main())
|
package/src/server.py
CHANGED
|
@@ -202,6 +202,8 @@ mcp = FastMCP(
|
|
|
202
202
|
"- **Workflow runtime (MANDATORY for long multi-step or cross-session work):** open `nexo_goal_open(...)` when the objective must survive sessions, then `nexo_workflow_open(...)`, "
|
|
203
203
|
"update meaningful checkpoints with `nexo_workflow_update(...)`, then use `nexo_workflow_resume(...)` / "
|
|
204
204
|
"`nexo_workflow_replay(...)` instead of restarting blindly.\n"
|
|
205
|
+
"- **Diagnostic plane (MANDATORY before diagnosing NEXO):** fix the plane explicitly first — `product_public`, `runtime_personal`, `installation_live`, `database_real`, or `cooperator`. "
|
|
206
|
+
"Do not mix product, runtime, install, DB, and agent-behavior explanations in the same diagnosis.\n"
|
|
205
207
|
"- **Guard (MANDATORY before ANY code edit):** `nexo_guard_check(files='...', area='...')` BEFORE editing code. "
|
|
206
208
|
"No exceptions. Blocking rules→resolve first. `nexo_track(sid=SID, paths=[...])` before shared files\n"
|
|
207
209
|
"- **Skills (MANDATORY before multi-step tasks):** `nexo_skill_match(task)` to find reusable procedures. "
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Run NEXO Core Fix Cycle
|
|
2
|
+
|
|
3
|
+
Usa esta skill cuando haya que implementar y verificar un grupo pequeño de fixes del core de NEXO sin improvisar el plano ni repetir siempre la misma fase de descubrimiento y test.
|
|
4
|
+
|
|
5
|
+
## Steps
|
|
6
|
+
1. Fija primero el plano: repo público `nexo`, runtime instalado `~/.nexo` y claims/documentación pública. No mezcles esos tres mundos.
|
|
7
|
+
2. Abre `nexo_task_open(...)` y `nexo_workflow_open(...)` antes de tocar código. Si el fix es de acción, pasa también por `nexo_cortex_decide(...)`.
|
|
8
|
+
3. Ejecuta la skill con `areas` ajustadas al fix. El helper te devuelve el mapa de archivos y corre la batería de tests focalizada para `protocol`, `plane`, `guard`, `cortex` y/o `release`.
|
|
9
|
+
4. Implementa el cambio mínimo defendible solo en la superficie correcta. Si el problema es producto, se arregla en el repo; no en `~/.nexo`.
|
|
10
|
+
5. Reejecuta la skill para revalidar el clúster exacto de tests tocado por el fix.
|
|
11
|
+
6. Cierra con `nexo_task_close(...)` y evidencia real. Si hubo edición real, deja `change_log` y captura learning si cambió una regla canónica.
|
|
12
|
+
|
|
13
|
+
## Gotchas
|
|
14
|
+
- No uses diary, workflow text o intuición como sustituto de git/tests/runtime reales.
|
|
15
|
+
- Si el fix toca doctor o claims públicos, fija el `plane` explícito antes de ejecutar diagnósticos.
|
|
16
|
+
- Si el fix toca release o runtime update, usa la vía oficial (`nexo update`, doctor, skill de release final) y no scripts laterales.
|
|
17
|
+
- Si el helper no encuentra un área, añade la superficie nueva de forma explícita en la skill en vez de seguir repitiendo grep manual disperso.
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
import shutil
|
|
7
|
+
import subprocess
|
|
8
|
+
import sys
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
AREA_MAP = {
|
|
13
|
+
"protocol": {
|
|
14
|
+
"files": [
|
|
15
|
+
"src/plugins/protocol.py",
|
|
16
|
+
"src/db/_protocol.py",
|
|
17
|
+
"src/db/__init__.py",
|
|
18
|
+
"tests/test_protocol.py",
|
|
19
|
+
],
|
|
20
|
+
"tests": [
|
|
21
|
+
"tests/test_protocol.py",
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
"plane": {
|
|
25
|
+
"files": [
|
|
26
|
+
"src/doctor/orchestrator.py",
|
|
27
|
+
"src/plugins/doctor.py",
|
|
28
|
+
"src/server.py",
|
|
29
|
+
"tests/test_doctor.py",
|
|
30
|
+
],
|
|
31
|
+
"tests": [
|
|
32
|
+
"tests/test_doctor.py",
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
"guard": {
|
|
36
|
+
"files": [
|
|
37
|
+
"src/hook_guardrails.py",
|
|
38
|
+
"tests/test_hook_guardrails.py",
|
|
39
|
+
],
|
|
40
|
+
"tests": [
|
|
41
|
+
"tests/test_hook_guardrails.py",
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
"cortex": {
|
|
45
|
+
"files": [
|
|
46
|
+
"src/plugins/cortex.py",
|
|
47
|
+
"tests/test_cortex_decisions.py",
|
|
48
|
+
],
|
|
49
|
+
"tests": [
|
|
50
|
+
"tests/test_cortex_decisions.py",
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
"release": {
|
|
54
|
+
"files": [
|
|
55
|
+
"scripts/verify_release_readiness.py",
|
|
56
|
+
"src/skills/run-release-final-audit/script.py",
|
|
57
|
+
"tests/test_verify_release_readiness.py",
|
|
58
|
+
"tests/test_release_readiness_baseline.py",
|
|
59
|
+
],
|
|
60
|
+
"tests": [
|
|
61
|
+
"tests/test_verify_release_readiness.py",
|
|
62
|
+
"tests/test_release_readiness_baseline.py",
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _is_repo_root(candidate: Path) -> bool:
|
|
69
|
+
return (
|
|
70
|
+
(candidate / "package.json").is_file()
|
|
71
|
+
and (candidate / "src" / "server.py").is_file()
|
|
72
|
+
and (candidate / "tests").is_dir()
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _normalize_candidate(raw: str | Path) -> Path:
|
|
77
|
+
candidate = Path(raw).expanduser().resolve()
|
|
78
|
+
if candidate.is_file():
|
|
79
|
+
candidate = candidate.parent
|
|
80
|
+
if candidate.name == "src" and (candidate / "server.py").is_file():
|
|
81
|
+
candidate = candidate.parent
|
|
82
|
+
return candidate
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _resolve_repo_root_from_atlas() -> Path | None:
|
|
86
|
+
homes = []
|
|
87
|
+
env_home = os.environ.get("NEXO_HOME", "").strip()
|
|
88
|
+
if env_home:
|
|
89
|
+
homes.append(Path(env_home).expanduser())
|
|
90
|
+
homes.extend((Path.home() / ".nexo", Path.home() / "claude"))
|
|
91
|
+
|
|
92
|
+
seen = set()
|
|
93
|
+
for home in homes:
|
|
94
|
+
key = str(home)
|
|
95
|
+
if key in seen:
|
|
96
|
+
continue
|
|
97
|
+
seen.add(key)
|
|
98
|
+
atlas_path = home / "brain" / "project-atlas.json"
|
|
99
|
+
if not atlas_path.is_file():
|
|
100
|
+
continue
|
|
101
|
+
try:
|
|
102
|
+
payload = json.loads(atlas_path.read_text(encoding="utf-8"))
|
|
103
|
+
except json.JSONDecodeError:
|
|
104
|
+
continue
|
|
105
|
+
nexo = payload.get("nexo") if isinstance(payload, dict) else None
|
|
106
|
+
locations = nexo.get("locations") if isinstance(nexo, dict) else None
|
|
107
|
+
source = locations.get("mcp_server", "") if isinstance(locations, dict) else ""
|
|
108
|
+
if not isinstance(source, str) or not source.strip():
|
|
109
|
+
continue
|
|
110
|
+
candidate = _normalize_candidate(source)
|
|
111
|
+
if _is_repo_root(candidate):
|
|
112
|
+
return candidate
|
|
113
|
+
return None
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _resolve_repo_root(explicit_root: str = "") -> Path:
|
|
117
|
+
if explicit_root.strip():
|
|
118
|
+
candidate = _normalize_candidate(explicit_root)
|
|
119
|
+
if _is_repo_root(candidate):
|
|
120
|
+
return candidate
|
|
121
|
+
|
|
122
|
+
env_code = os.environ.get("NEXO_CODE", "").strip()
|
|
123
|
+
if env_code:
|
|
124
|
+
candidate = _normalize_candidate(env_code)
|
|
125
|
+
if _is_repo_root(candidate):
|
|
126
|
+
return candidate
|
|
127
|
+
|
|
128
|
+
cwd = Path.cwd().resolve()
|
|
129
|
+
for candidate in (cwd, *cwd.parents):
|
|
130
|
+
if _is_repo_root(candidate):
|
|
131
|
+
return candidate
|
|
132
|
+
|
|
133
|
+
atlas_repo = _resolve_repo_root_from_atlas()
|
|
134
|
+
if atlas_repo is not None:
|
|
135
|
+
return atlas_repo
|
|
136
|
+
|
|
137
|
+
script_root = Path(__file__).resolve().parents[3]
|
|
138
|
+
if _is_repo_root(script_root):
|
|
139
|
+
return script_root
|
|
140
|
+
return script_root
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _parse_bool(raw: str, default: bool) -> bool:
|
|
144
|
+
text = (raw or "").strip().lower()
|
|
145
|
+
if not text:
|
|
146
|
+
return default
|
|
147
|
+
if text in {"1", "true", "yes", "on"}:
|
|
148
|
+
return True
|
|
149
|
+
if text in {"0", "false", "no", "off"}:
|
|
150
|
+
return False
|
|
151
|
+
raise SystemExit(f"[core-fix-cycle] invalid boolean: {raw}")
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def _normalize_areas(raw: str) -> list[str]:
|
|
155
|
+
text = (raw or "protocol,plane").replace("+", ",")
|
|
156
|
+
parts = [item.strip().lower() for item in text.split(",") if item.strip()]
|
|
157
|
+
if not parts:
|
|
158
|
+
return ["protocol", "plane"]
|
|
159
|
+
unknown = [item for item in parts if item not in AREA_MAP]
|
|
160
|
+
if unknown:
|
|
161
|
+
raise SystemExit(
|
|
162
|
+
f"[core-fix-cycle] unknown area(s): {', '.join(unknown)}. Expected one of: {', '.join(sorted(AREA_MAP))}"
|
|
163
|
+
)
|
|
164
|
+
seen = set()
|
|
165
|
+
ordered = []
|
|
166
|
+
for item in parts:
|
|
167
|
+
if item in seen:
|
|
168
|
+
continue
|
|
169
|
+
seen.add(item)
|
|
170
|
+
ordered.append(item)
|
|
171
|
+
return ordered
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def _env(root: Path, nexo_home: str) -> dict[str, str]:
|
|
175
|
+
env = os.environ.copy()
|
|
176
|
+
src_path = str(root / "src")
|
|
177
|
+
existing_pythonpath = env.get("PYTHONPATH", "").strip()
|
|
178
|
+
env["PYTHONPATH"] = (
|
|
179
|
+
f"{src_path}{os.pathsep}{existing_pythonpath}" if existing_pythonpath else src_path
|
|
180
|
+
)
|
|
181
|
+
env["NEXO_CODE"] = src_path
|
|
182
|
+
env["PYTEST_DISABLE_PLUGIN_AUTOLOAD"] = "1"
|
|
183
|
+
if nexo_home.strip():
|
|
184
|
+
env["NEXO_HOME"] = str(Path(nexo_home).expanduser())
|
|
185
|
+
return env
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def _command_succeeds(cmd: list[str], *, env: dict[str, str], root: Path) -> bool:
|
|
189
|
+
result = subprocess.run(
|
|
190
|
+
cmd,
|
|
191
|
+
cwd=root,
|
|
192
|
+
env=env,
|
|
193
|
+
stdout=subprocess.DEVNULL,
|
|
194
|
+
stderr=subprocess.DEVNULL,
|
|
195
|
+
)
|
|
196
|
+
return result.returncode == 0
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def _resolve_python(root: Path, env: dict[str, str]) -> str:
|
|
200
|
+
candidates = []
|
|
201
|
+
override = os.environ.get("NEXO_RELEASE_PYTHON", "").strip()
|
|
202
|
+
if override:
|
|
203
|
+
candidates.append(override)
|
|
204
|
+
|
|
205
|
+
for name in ("python3", "python"):
|
|
206
|
+
path = shutil.which(name)
|
|
207
|
+
if path:
|
|
208
|
+
candidates.append(path)
|
|
209
|
+
|
|
210
|
+
candidates.append(sys.executable)
|
|
211
|
+
|
|
212
|
+
seen = set()
|
|
213
|
+
for candidate in candidates:
|
|
214
|
+
if not candidate or candidate in seen:
|
|
215
|
+
continue
|
|
216
|
+
seen.add(candidate)
|
|
217
|
+
if _command_succeeds([candidate, "-m", "pytest", "--version"], env=env, root=root):
|
|
218
|
+
return candidate
|
|
219
|
+
|
|
220
|
+
raise SystemExit(
|
|
221
|
+
"[core-fix-cycle] no Python interpreter with pytest available. "
|
|
222
|
+
"Set NEXO_RELEASE_PYTHON or install pytest in the active runtime."
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _run(cmd: list[str], *, env: dict[str, str], root: Path) -> None:
|
|
227
|
+
print(f"[core-fix-cycle] $ {' '.join(cmd)}")
|
|
228
|
+
result = subprocess.run(cmd, cwd=root, env=env)
|
|
229
|
+
if result.returncode != 0:
|
|
230
|
+
raise SystemExit(result.returncode)
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def main() -> int:
|
|
234
|
+
areas = _normalize_areas(sys.argv[1] if len(sys.argv) > 1 else "protocol,plane")
|
|
235
|
+
run_tests = _parse_bool(sys.argv[2] if len(sys.argv) > 2 else "true", True)
|
|
236
|
+
repo_root = _resolve_repo_root(sys.argv[3] if len(sys.argv) > 3 else "")
|
|
237
|
+
nexo_home = sys.argv[4] if len(sys.argv) > 4 else ""
|
|
238
|
+
env = _env(repo_root, nexo_home)
|
|
239
|
+
|
|
240
|
+
files: list[str] = []
|
|
241
|
+
tests: list[str] = []
|
|
242
|
+
for area in areas:
|
|
243
|
+
for path in AREA_MAP[area]["files"]:
|
|
244
|
+
if path not in files:
|
|
245
|
+
files.append(path)
|
|
246
|
+
for path in AREA_MAP[area]["tests"]:
|
|
247
|
+
if path not in tests:
|
|
248
|
+
tests.append(path)
|
|
249
|
+
|
|
250
|
+
print(f"[core-fix-cycle] repo_root={repo_root}")
|
|
251
|
+
print(f"[core-fix-cycle] areas={','.join(areas)}")
|
|
252
|
+
print("[core-fix-cycle] file-map:")
|
|
253
|
+
for path in files:
|
|
254
|
+
label = "OK" if (repo_root / path).exists() else "missing"
|
|
255
|
+
print(f"[core-fix-cycle] - {path} [{label}]")
|
|
256
|
+
|
|
257
|
+
if not run_tests:
|
|
258
|
+
print("[core-fix-cycle] tests skipped")
|
|
259
|
+
print("[core-fix-cycle] OK")
|
|
260
|
+
return 0
|
|
261
|
+
|
|
262
|
+
existing_tests = [path for path in tests if (repo_root / path).is_file()]
|
|
263
|
+
if not existing_tests:
|
|
264
|
+
print("[core-fix-cycle] no tests found for selected areas")
|
|
265
|
+
print("[core-fix-cycle] OK")
|
|
266
|
+
return 0
|
|
267
|
+
|
|
268
|
+
python_bin = _resolve_python(repo_root, env)
|
|
269
|
+
print(f"[core-fix-cycle] python={python_bin}")
|
|
270
|
+
_run([python_bin, "-m", "pytest", "-q", *existing_tests], env=env, root=repo_root)
|
|
271
|
+
print("[core-fix-cycle] OK")
|
|
272
|
+
return 0
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
if __name__ == "__main__":
|
|
276
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "SK-RUN-NEXO-CORE-FIX-CYCLE",
|
|
3
|
+
"name": "Run NEXO Core Fix Cycle",
|
|
4
|
+
"description": "Mapea las superficies core impactadas y ejecuta la verificación focalizada para ciclos pequeños de fixes de NEXO sin mezclar repo público, runtime y claims no verificados.",
|
|
5
|
+
"level": "published",
|
|
6
|
+
"mode": "hybrid",
|
|
7
|
+
"source_kind": "core",
|
|
8
|
+
"execution_level": "read-only",
|
|
9
|
+
"approval_required": false,
|
|
10
|
+
"tags": [
|
|
11
|
+
"nexo",
|
|
12
|
+
"core",
|
|
13
|
+
"fix",
|
|
14
|
+
"protocol",
|
|
15
|
+
"plane",
|
|
16
|
+
"verification"
|
|
17
|
+
],
|
|
18
|
+
"trigger_patterns": [
|
|
19
|
+
"dos fixes core nexo",
|
|
20
|
+
"core fix cycle",
|
|
21
|
+
"enforcement protocolario",
|
|
22
|
+
"plano antes del diagnostico",
|
|
23
|
+
"ciclo fix core nexo"
|
|
24
|
+
],
|
|
25
|
+
"params_schema": {
|
|
26
|
+
"areas": {
|
|
27
|
+
"type": "string",
|
|
28
|
+
"required": false,
|
|
29
|
+
"default": "protocol,plane"
|
|
30
|
+
},
|
|
31
|
+
"run_tests": {
|
|
32
|
+
"type": "boolean",
|
|
33
|
+
"required": false,
|
|
34
|
+
"default": true
|
|
35
|
+
},
|
|
36
|
+
"repo_root": {
|
|
37
|
+
"type": "string",
|
|
38
|
+
"required": false,
|
|
39
|
+
"default": ""
|
|
40
|
+
},
|
|
41
|
+
"nexo_home": {
|
|
42
|
+
"type": "string",
|
|
43
|
+
"required": false,
|
|
44
|
+
"default": ""
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"command_template": {
|
|
48
|
+
"argv": [
|
|
49
|
+
"{{file_path}}",
|
|
50
|
+
"{{areas}}",
|
|
51
|
+
"{{run_tests}}",
|
|
52
|
+
"{{repo_root}}",
|
|
53
|
+
"{{nexo_home}}"
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
"executable_entry": "script.py",
|
|
57
|
+
"stable_after_uses": 5
|
|
58
|
+
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
# Run Release Final Audit
|
|
2
2
|
|
|
3
|
-
Use this before
|
|
3
|
+
Use this before claiming a release/publication is closed when you need a live check that smoke, release contract, public surfaces, runtime update/doctor, and protocol closeout still align.
|
|
4
4
|
|
|
5
5
|
## Steps
|
|
6
6
|
1. Run the skill with defaults to audit the current package version. It auto-resolves `release-contracts/v{version}.json` and `scripts/run_vX_Y_smoke.py` when present.
|
|
7
7
|
2. Keep `contract="auto"` and `require_contract_complete=true` for the real final gate. Set `contract="none"` only for pre-contract repo checks.
|
|
8
|
-
3.
|
|
8
|
+
3. For the real post-publish closeout, set `final_closeout=true` and pass the release `protocol_task_id` so the audit also verifies GitHub Release, npm, `nexo update`, runtime doctor, `change_log`, and `task_close`.
|
|
9
|
+
4. Treat `ci=true` as repo-only. The last live audit must stay outside CI because `final_closeout` expects a live runtime and a real closed task.
|
|
9
10
|
|
|
10
11
|
## Gotchas
|
|
11
12
|
- A missing auto-resolved contract is a real blocker for the final release audit.
|
|
12
13
|
- Smoke is version-line scoped. If no runner exists, the skill reports the skip explicitly instead of pretending it ran.
|
|
13
|
-
- The script is read-only
|
|
14
|
+
- The script is read-only except for the optional official `nexo update` step during `final_closeout`; it still does not bump versions, tag, publish, or edit website worktrees.
|
|
15
|
+
- `final_closeout` is intentionally stricter than the repo-only readiness pass: it fails if the release task was not closed with evidence or if its `change_log` row is missing.
|
|
14
16
|
- If the touched area includes bootstrap, startup, or public claims, finish with the manual watchpoints in `docs/client-parity-checklist.md`.
|