Skip to content

Commit 551e506

Browse files
committed
feat: report skill synthesis status
1 parent d5c6607 commit 551e506

2 files changed

Lines changed: 113 additions & 2 deletions

File tree

‎src/codex_self_evolution/diagnostics.py‎

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@
2828
from typing import Any
2929

3030
from .config import PROJECTS_SUBDIR, get_home_dir, is_archived_bucket
31+
from .managed_skills.publish import codex_skills_dir
32+
from .skill_synthesis.inventory import read_skills_inventory
3133

3234
HOOK_MARKER = "codex-self-evolution-plugin managed"
3335
LAUNCHD_LABEL = "com.codex-self-evolution.preflight"
36+
SKILL_SYNTHESIS_LAUNCHD_LABEL = "com.codex-self-evolution.skill-synthesis"
3437

3538
# Keys we recognize from .env.provider.example. Not exhaustive — other env
3639
# vars a user might add (custom MINIMAX_BASE_URL etc.) are reported as
@@ -66,6 +69,8 @@ def collect_status(
6669
"legacy_user_hooks": legacy_hooks,
6770
"plugin_hooks": _check_plugin_hook_bundle(),
6871
"scheduler": _check_scheduler(),
72+
"skill_synthesis": _check_skill_synthesis(home_dir),
73+
"skills": _check_skill_counts(),
6974
"env_provider": _check_env_provider(home_dir),
7075
"tools": _check_tools(),
7176
"buckets": _list_buckets(home_dir),
@@ -215,9 +220,15 @@ def _commands_for_hook_event(entries: Any) -> list[str]:
215220

216221

217222
def _check_scheduler() -> dict[str, Any]:
223+
return _check_launchd_label(LAUNCHD_LABEL)
224+
225+
226+
def _check_launchd_label(label: str) -> dict[str, Any]:
218227
plist_path = Path.home() / "Library" / "LaunchAgents" / f"{LAUNCHD_LABEL}.plist"
228+
if label != LAUNCHD_LABEL:
229+
plist_path = Path.home() / "Library" / "LaunchAgents" / f"{label}.plist"
219230
result: dict[str, Any] = {
220-
"label": LAUNCHD_LABEL,
231+
"label": label,
221232
"plist_path": str(plist_path),
222233
"plist_exists": plist_path.exists(),
223234
"loaded": False,
@@ -243,12 +254,44 @@ def _check_scheduler() -> dict[str, Any]:
243254
# "does our label appear", not about PID or status — launchd might have
244255
# our job loaded but not currently running (between ticks).
245256
for line in proc.stdout.splitlines():
246-
if line.strip().endswith(LAUNCHD_LABEL):
257+
if line.strip().endswith(label):
247258
result["loaded"] = True
248259
break
249260
return result
250261

251262

263+
def _check_skill_synthesis(home_dir: Path) -> dict[str, Any]:
264+
root = home_dir / "skill_synthesis"
265+
return {
266+
"root": str(root),
267+
"exists": root.exists(),
268+
"scheduler": _check_launchd_label(SKILL_SYNTHESIS_LAUNCHD_LABEL),
269+
"last_receipt": _read_skill_synthesis_receipt(root / "last_receipt.json"),
270+
}
271+
272+
273+
def _check_skill_counts() -> dict[str, Any]:
274+
root = codex_skills_dir()
275+
inventory = read_skills_inventory(root)
276+
synth = inventory["synth"]
277+
legacy = [
278+
item for item in inventory["non_synth"]
279+
if Path(item["path"]).parent.name.startswith("csep-")
280+
]
281+
return {
282+
"skills_root": str(root),
283+
"synthesized": {
284+
"active": sum(1 for item in synth if not item.get("invalid_marker") and item.get("csep_status") != "retired"),
285+
"invalid": sum(1 for item in synth if item.get("invalid_marker")),
286+
"retired": sum(1 for item in synth if item.get("csep_status") == "retired"),
287+
},
288+
"compiler_legacy": {
289+
"active": len(legacy),
290+
"note": "legacy; compiler no longer creates or updates skills",
291+
},
292+
}
293+
294+
252295
# ---------- .env.provider key presence ----------------------------------
253296

254297

@@ -409,6 +452,39 @@ def _read_last_receipt(receipt_path: Path) -> dict[str, Any] | None:
409452
}
410453

411454

455+
def _read_skill_synthesis_receipt(receipt_path: Path) -> dict[str, Any] | None:
456+
if not receipt_path.is_file():
457+
return None
458+
try:
459+
data = json.loads(receipt_path.read_text(encoding="utf-8"))
460+
except (OSError, ValueError):
461+
return None
462+
try:
463+
mtime = receipt_path.stat().st_mtime
464+
timestamp = datetime.fromtimestamp(mtime, tz=timezone.utc).strftime(
465+
"%Y-%m-%dT%H:%M:%SZ"
466+
)
467+
except OSError:
468+
timestamp = None
469+
return {
470+
"path": str(receipt_path),
471+
"timestamp": timestamp,
472+
"status": data.get("status"),
473+
"run_id": data.get("run_id"),
474+
"mode": data.get("mode"),
475+
"dry_run": data.get("dry_run"),
476+
"evidence_count": data.get("evidence_count"),
477+
"valid_count": len(data.get("valid") or []),
478+
"invalid_count": len(data.get("invalid") or []),
479+
"retired_count": len(data.get("retired") or []),
480+
"mismatch": data.get("mismatch"),
481+
"dry_run_leak": data.get("dry_run_leak"),
482+
"result_missing": data.get("result_missing"),
483+
"result_invalid": data.get("result_invalid"),
484+
"error": data.get("error"),
485+
}
486+
487+
412488
# ---------- recent activity from plugin.log -----------------------------
413489

414490
# Fields we actually care about when rolling up the log. Anything outside
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from __future__ import annotations
2+
3+
import json
4+
from pathlib import Path
5+
6+
from codex_self_evolution.diagnostics import collect_status
7+
8+
9+
def test_status_reports_skill_synthesis_receipt_and_counts(tmp_path: Path, monkeypatch) -> None:
10+
skills_root = tmp_path / "skills"
11+
active = skills_root / "csep-synth-active"
12+
active.mkdir(parents=True)
13+
(active / "SKILL.md").write_text(
14+
"---\nname: csep-synth-active\ndescription: Use when active repeats.\n---\n\nWorkflow steps check verify run output.\n",
15+
encoding="utf-8",
16+
)
17+
invalid = skills_root / "csep-synth-invalid"
18+
invalid.mkdir()
19+
(invalid / "SKILL.md").write_text("bad", encoding="utf-8")
20+
(invalid / "CSEP_INVALID.json").write_text("{}", encoding="utf-8")
21+
legacy = skills_root / "csep-legacy"
22+
legacy.mkdir()
23+
(legacy / "SKILL.md").write_text("---\nname: csep-legacy\ndescription: legacy\n---\n", encoding="utf-8")
24+
25+
synth_dir = tmp_path / "skill_synthesis"
26+
synth_dir.mkdir()
27+
(synth_dir / "last_receipt.json").write_text(json.dumps({"status": "partial", "run_id": "run-1"}), encoding="utf-8")
28+
monkeypatch.setenv("CSEP_CODEX_SKILLS_DIR", str(skills_root))
29+
30+
status = collect_status(home=tmp_path)
31+
32+
assert status["skill_synthesis"]["last_receipt"]["status"] == "partial"
33+
assert status["skills"]["synthesized"]["active"] == 1
34+
assert status["skills"]["synthesized"]["invalid"] == 1
35+
assert status["skills"]["compiler_legacy"]["active"] == 1

0 commit comments

Comments
 (0)