@jcorpac/skill-vault 2.0.0 → 2.1.0
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/README.md +6 -5
- package/SKILL.md +10 -9
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/scripts/mcp_server.py +378 -61
- package/scripts/skill_router.py +161 -28
- package/scripts/skill_vault.py +729 -134
package/scripts/skill_vault.py
CHANGED
|
@@ -7,8 +7,10 @@ strictly in backup_manifest.json and INDEX.md, keeping SKILL.md files pure and u
|
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
9
|
import argparse
|
|
10
|
+
from datetime import datetime
|
|
10
11
|
import fnmatch
|
|
11
12
|
import hashlib
|
|
13
|
+
import io
|
|
12
14
|
import json
|
|
13
15
|
import os
|
|
14
16
|
from pathlib import Path
|
|
@@ -387,6 +389,22 @@ def parse_version_tuple(ver_str):
|
|
|
387
389
|
return None
|
|
388
390
|
|
|
389
391
|
|
|
392
|
+
def compare_version_tuples(ver_a, ver_b):
|
|
393
|
+
"""Compare two version tuples with zero-padding. Returns 1, -1, or 0."""
|
|
394
|
+
if ver_a is None or ver_b is None:
|
|
395
|
+
return 0
|
|
396
|
+
ta = tuple(ver_a)
|
|
397
|
+
tb = tuple(ver_b)
|
|
398
|
+
max_len = max(len(ta), len(tb))
|
|
399
|
+
pa = ta + (0,) * (max_len - len(ta))
|
|
400
|
+
pb = tb + (0,) * (max_len - len(tb))
|
|
401
|
+
if pa > pb:
|
|
402
|
+
return 1
|
|
403
|
+
if pa < pb:
|
|
404
|
+
return -1
|
|
405
|
+
return 0
|
|
406
|
+
|
|
407
|
+
|
|
390
408
|
def get_skill_metadata(skill_dir):
|
|
391
409
|
"""Extract parsed version and latest modification timestamp for a skill directory."""
|
|
392
410
|
skill_dir = Path(skill_dir)
|
|
@@ -396,9 +414,12 @@ def get_skill_metadata(skill_dir):
|
|
|
396
414
|
if skill_md.exists():
|
|
397
415
|
try:
|
|
398
416
|
content = skill_md.read_text(encoding="utf-8", errors="ignore")
|
|
399
|
-
fm_match = re.
|
|
417
|
+
fm_match = re.match(r"^---\s*\n(.*?)\n---(?:\s*\n|\s*\Z)", content, re.DOTALL)
|
|
400
418
|
if fm_match:
|
|
401
|
-
|
|
419
|
+
fm_text = fm_match.group(1)
|
|
420
|
+
v_match = re.search(r"^version:\s*([^\n]+)", fm_text, re.MULTILINE | re.IGNORECASE)
|
|
421
|
+
if not v_match:
|
|
422
|
+
v_match = re.search(r"^[ \t]+version:\s*([^\n]+)", fm_text, re.MULTILINE | re.IGNORECASE)
|
|
402
423
|
if v_match:
|
|
403
424
|
ver_tuple = parse_version_tuple(v_match.group(1))
|
|
404
425
|
except Exception:
|
|
@@ -432,17 +453,28 @@ def compare_skill_recency(dir_a, dir_b):
|
|
|
432
453
|
-1 if dir_b is newer than dir_a
|
|
433
454
|
0 if they are equivalent in version and recency
|
|
434
455
|
"""
|
|
456
|
+
a_exists = (Path(dir_a) / "SKILL.md").exists()
|
|
457
|
+
b_exists = (Path(dir_b) / "SKILL.md").exists()
|
|
458
|
+
if a_exists != b_exists:
|
|
459
|
+
return 1 if a_exists else -1
|
|
460
|
+
|
|
435
461
|
ver_a, mtime_a = get_skill_metadata(dir_a)
|
|
436
462
|
ver_b, mtime_b = get_skill_metadata(dir_b)
|
|
437
463
|
|
|
438
464
|
# 1. Compare semantic/numeric versions if both exist and differ
|
|
439
|
-
if ver_a is not None and ver_b is not None
|
|
440
|
-
|
|
465
|
+
if ver_a is not None and ver_b is not None:
|
|
466
|
+
vcmp = compare_version_tuples(ver_a, ver_b)
|
|
467
|
+
if vcmp != 0:
|
|
468
|
+
return vcmp
|
|
441
469
|
|
|
442
470
|
# 2. Compare file modification timestamps (allowing a 1-second margin for filesystem granularity)
|
|
443
471
|
if abs(mtime_a - mtime_b) > 1.0:
|
|
444
472
|
return 1 if mtime_a > mtime_b else -1
|
|
445
473
|
|
|
474
|
+
# 3. Tie-breaker when timestamps match: prefer an explicitly versioned skill
|
|
475
|
+
if (ver_a is not None) != (ver_b is not None):
|
|
476
|
+
return 1 if ver_a is not None else -1
|
|
477
|
+
|
|
446
478
|
return 0
|
|
447
479
|
|
|
448
480
|
|
|
@@ -854,6 +886,191 @@ class SkillVault:
|
|
|
854
886
|
pass
|
|
855
887
|
return protected
|
|
856
888
|
|
|
889
|
+
def _collect_bin_shim_targets(self):
|
|
890
|
+
"""Read small launcher shims in antigravity/bin or base_dir/bin to detect path-bound scripts."""
|
|
891
|
+
app_data = os.environ.get("ANTIGRAVITY_APP_DATA_DIR")
|
|
892
|
+
agy_bin = (Path(app_data) / "bin") if app_data else (Path.home() / ".gemini" / "antigravity" / "bin")
|
|
893
|
+
bin_dirs = []
|
|
894
|
+
for cand in (agy_bin, self.base_dir / "bin", self.get_root_dir() / "bin"):
|
|
895
|
+
if cand.exists() and cand.is_dir():
|
|
896
|
+
res = cand.resolve()
|
|
897
|
+
if res not in bin_dirs:
|
|
898
|
+
bin_dirs.append(res)
|
|
899
|
+
|
|
900
|
+
shims = []
|
|
901
|
+
for bdir in bin_dirs:
|
|
902
|
+
try:
|
|
903
|
+
for fp in bdir.iterdir():
|
|
904
|
+
if not fp.is_file():
|
|
905
|
+
continue
|
|
906
|
+
if fp.suffix.lower() not in {".cmd", ".bat", ".sh", ""}:
|
|
907
|
+
continue
|
|
908
|
+
try:
|
|
909
|
+
if fp.stat().st_size > 4096:
|
|
910
|
+
continue
|
|
911
|
+
txt = fp.read_text(encoding="utf-8", errors="ignore").lower()
|
|
912
|
+
shims.append((fp.name, txt))
|
|
913
|
+
except OSError:
|
|
914
|
+
pass
|
|
915
|
+
except OSError:
|
|
916
|
+
pass
|
|
917
|
+
return shims
|
|
918
|
+
|
|
919
|
+
def assess_skill_compat(self, skill_dir, original_path=None, bin_shim_targets=None, max_single_chars=None):
|
|
920
|
+
"""Inspect a skill directory for path dependencies, cross-skill refs, truncation size, and guardrails."""
|
|
921
|
+
skill_dir = Path(skill_dir)
|
|
922
|
+
if max_single_chars is None:
|
|
923
|
+
max_single_chars = int(self.load_config().get("routing", {}).get("max_single_skill_chars", 9000))
|
|
924
|
+
else:
|
|
925
|
+
max_single_chars = int(max_single_chars)
|
|
926
|
+
|
|
927
|
+
companion_files = []
|
|
928
|
+
if skill_dir.exists():
|
|
929
|
+
for root, dirs, files in os.walk(skill_dir):
|
|
930
|
+
rp = Path(root)
|
|
931
|
+
dirs[:] = sorted(
|
|
932
|
+
d for d in dirs
|
|
933
|
+
if d not in {"__pycache__", ".git", "node_modules"}
|
|
934
|
+
and not (rp / d / "SKILL.md").exists()
|
|
935
|
+
)
|
|
936
|
+
for fname in sorted(files):
|
|
937
|
+
if rp == skill_dir and fname == "SKILL.md":
|
|
938
|
+
continue
|
|
939
|
+
companion_files.append((rp / fname).relative_to(skill_dir).as_posix())
|
|
940
|
+
|
|
941
|
+
has_companions = len(companion_files) > 0
|
|
942
|
+
skill_md = skill_dir / "SKILL.md"
|
|
943
|
+
skill_md_bytes = 0
|
|
944
|
+
md_text = ""
|
|
945
|
+
if skill_md.exists():
|
|
946
|
+
try:
|
|
947
|
+
skill_md_bytes = skill_md.stat().st_size
|
|
948
|
+
md_text = skill_md.read_text(encoding="utf-8", errors="replace")
|
|
949
|
+
except OSError:
|
|
950
|
+
pass
|
|
951
|
+
oversized_skill_md = skill_md_bytes > max_single_chars
|
|
952
|
+
|
|
953
|
+
traversal_re = re.compile(
|
|
954
|
+
r"(?:%~dp0\s*\.\.[\\/]\.\.|(?:\.\.[\\/]){2,}|"
|
|
955
|
+
r"path\.resolve\(\s*__dirname\s*,\s*['\"](?:\.\.[\\/]){2,}|\.parents\[\s*[234]\s*\])",
|
|
956
|
+
re.IGNORECASE,
|
|
957
|
+
)
|
|
958
|
+
plugin_env_re = re.compile(
|
|
959
|
+
r"\b(?:PLUGIN_DIR_NAME|CLAUDE_PLUGIN_ROOT|PLUGIN_DIR|PLUGIN_DATA|plugin_data)\b"
|
|
960
|
+
)
|
|
961
|
+
script_exts = {".py", ".js", ".ts", ".sh", ".cmd", ".bat", ".ps1", ".toml"}
|
|
962
|
+
|
|
963
|
+
path_reasons = []
|
|
964
|
+
for rel in companion_files:
|
|
965
|
+
fp = skill_dir / rel
|
|
966
|
+
if not rel.startswith("scripts/") and fp.suffix.lower() not in script_exts:
|
|
967
|
+
continue
|
|
968
|
+
try:
|
|
969
|
+
if fp.stat().st_size > 262144:
|
|
970
|
+
continue
|
|
971
|
+
ftxt = fp.read_text(encoding="utf-8", errors="ignore")
|
|
972
|
+
except OSError:
|
|
973
|
+
continue
|
|
974
|
+
if traversal_re.search(ftxt):
|
|
975
|
+
path_reasons.append(f"script_parent_traversal: {rel}")
|
|
976
|
+
if plugin_env_re.search(ftxt):
|
|
977
|
+
path_reasons.append(f"script_plugin_root_ref: {rel}")
|
|
978
|
+
|
|
979
|
+
if original_path and bin_shim_targets:
|
|
980
|
+
orig_fwd = str(Path(original_path)).lower().replace("\\", "/")
|
|
981
|
+
orig_bck = str(Path(original_path)).lower().replace("/", "\\")
|
|
982
|
+
for shim_name, shim_txt in bin_shim_targets:
|
|
983
|
+
for pat in (orig_fwd, orig_bck):
|
|
984
|
+
pos = shim_txt.find(pat)
|
|
985
|
+
if pos != -1:
|
|
986
|
+
end_pos = pos + len(pat)
|
|
987
|
+
if end_pos == len(shim_txt) or shim_txt[end_pos] in ("/", "\\", "\"", "'", " ", "\t", "\r", "\n"):
|
|
988
|
+
path_reasons.append(f"path_shim_target: bin/{shim_name}")
|
|
989
|
+
break
|
|
990
|
+
|
|
991
|
+
cross_re = re.compile(
|
|
992
|
+
r"(?:\.\./[a-zA-Z0-9._-]+(?:/[a-zA-Z0-9._-]+)*|"
|
|
993
|
+
r"\$\{?CLAUDE_PLUGIN_ROOT\}?|\$PLUGIN_DIR|<PLUGIN_DIR>|@skill:[a-zA-Z0-9._-]+)"
|
|
994
|
+
)
|
|
995
|
+
cross_skill_refs = []
|
|
996
|
+
seen_refs = set()
|
|
997
|
+
for m in cross_re.finditer(md_text):
|
|
998
|
+
val = m.group(0)
|
|
999
|
+
if val not in seen_refs:
|
|
1000
|
+
seen_refs.add(val)
|
|
1001
|
+
cross_skill_refs.append(val)
|
|
1002
|
+
if len(cross_skill_refs) >= 15:
|
|
1003
|
+
break
|
|
1004
|
+
|
|
1005
|
+
if has_companions and re.search(
|
|
1006
|
+
r"(?:\$\{?CLAUDE_PLUGIN_ROOT\}?|\$PLUGIN_DIR|<PLUGIN_DIR>|\.\./[a-zA-Z0-9._-]+/scripts/)",
|
|
1007
|
+
md_text,
|
|
1008
|
+
):
|
|
1009
|
+
path_reasons.append("skill_plugin_path_ref: SKILL.md")
|
|
1010
|
+
|
|
1011
|
+
# Deduplicate while preserving order
|
|
1012
|
+
path_reasons = list(dict.fromkeys(path_reasons))
|
|
1013
|
+
|
|
1014
|
+
guard_re = re.compile(
|
|
1015
|
+
r"(?:trigger:\s*always_on|MANDATORY:\s*Execute FIRST|CRITICAL RULE|STOP AND VERIFY)"
|
|
1016
|
+
)
|
|
1017
|
+
guardrail_signals = list(dict.fromkeys(m.group(0) for m in guard_re.finditer(md_text[:2000])))
|
|
1018
|
+
|
|
1019
|
+
path_dependent = bool(path_reasons)
|
|
1020
|
+
needs_runtime_in_place = bool(path_dependent and has_companions)
|
|
1021
|
+
return {
|
|
1022
|
+
"path_dependent": path_dependent,
|
|
1023
|
+
"needs_runtime_in_place": needs_runtime_in_place,
|
|
1024
|
+
"has_companions": has_companions,
|
|
1025
|
+
"path_reasons": path_reasons,
|
|
1026
|
+
"cross_skill_refs": cross_skill_refs,
|
|
1027
|
+
"oversized_skill_md": oversized_skill_md,
|
|
1028
|
+
"skill_md_bytes": skill_md_bytes,
|
|
1029
|
+
"guardrail_signals": guardrail_signals,
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
def _prune_skill_runtime_in_place(self, active_path):
|
|
1033
|
+
"""Remove SKILL.md only so L1 context drops to 0 while path-dependent companions stay in place."""
|
|
1034
|
+
active_path = Path(active_path)
|
|
1035
|
+
if not active_path.exists():
|
|
1036
|
+
return False
|
|
1037
|
+
skill_md = active_path / "SKILL.md"
|
|
1038
|
+
if skill_md.exists():
|
|
1039
|
+
skill_md.unlink()
|
|
1040
|
+
try:
|
|
1041
|
+
has_remaining = any(active_path.iterdir())
|
|
1042
|
+
except OSError:
|
|
1043
|
+
has_remaining = False
|
|
1044
|
+
if not has_remaining:
|
|
1045
|
+
try:
|
|
1046
|
+
active_path.rmdir()
|
|
1047
|
+
except OSError:
|
|
1048
|
+
pass
|
|
1049
|
+
return False
|
|
1050
|
+
return True
|
|
1051
|
+
|
|
1052
|
+
def _materialize_runtime_companions(self, archived_dir, target_dir):
|
|
1053
|
+
"""Copy companion files from L2 to target_dir without creating SKILL.md."""
|
|
1054
|
+
archived_dir = Path(archived_dir).resolve()
|
|
1055
|
+
target_dir = Path(target_dir).resolve()
|
|
1056
|
+
if (target_dir / "SKILL.md").exists():
|
|
1057
|
+
return False
|
|
1058
|
+
target_dir.mkdir(parents=True, exist_ok=True)
|
|
1059
|
+
|
|
1060
|
+
def _ignore_skill_md_and_nested(curr_dir, names):
|
|
1061
|
+
curr_path = Path(curr_dir).resolve()
|
|
1062
|
+
ignored = []
|
|
1063
|
+
if curr_path == archived_dir:
|
|
1064
|
+
for n in names:
|
|
1065
|
+
if n == "SKILL.md":
|
|
1066
|
+
ignored.append(n)
|
|
1067
|
+
elif (curr_path / n).is_dir() and (curr_path / n / "SKILL.md").exists():
|
|
1068
|
+
ignored.append(n)
|
|
1069
|
+
return ignored
|
|
1070
|
+
|
|
1071
|
+
shutil.copytree(archived_dir, target_dir, dirs_exist_ok=True, ignore=_ignore_skill_md_and_nested)
|
|
1072
|
+
return True
|
|
1073
|
+
|
|
857
1074
|
def make_portable_path(self, abs_path):
|
|
858
1075
|
"""Convert path to relative from base_dir or root_dir if possible."""
|
|
859
1076
|
resolved = Path(abs_path).resolve()
|
|
@@ -1192,6 +1409,7 @@ class SkillVault:
|
|
|
1192
1409
|
|
|
1193
1410
|
core_set = self.get_core_skills(protect_skills)
|
|
1194
1411
|
hook_protected = self.get_hook_protected_skills()
|
|
1412
|
+
bin_shims = self._collect_bin_shim_targets()
|
|
1195
1413
|
|
|
1196
1414
|
active_skills = self.get_active_skills()
|
|
1197
1415
|
manifest = self.load_manifest()
|
|
@@ -1240,7 +1458,12 @@ class SkillVault:
|
|
|
1240
1458
|
elif is_hook_dep:
|
|
1241
1459
|
protected_hooks.append(name)
|
|
1242
1460
|
elif not keep_active:
|
|
1243
|
-
|
|
1461
|
+
compat = (
|
|
1462
|
+
self.assess_skill_compat(active_path, original_path=active_path, bin_shim_targets=bin_shims)
|
|
1463
|
+
if not data.get("single_skill_dir")
|
|
1464
|
+
else {"needs_runtime_in_place": False, "path_reasons": []}
|
|
1465
|
+
)
|
|
1466
|
+
to_prune.append((name, data, compat))
|
|
1244
1467
|
|
|
1245
1468
|
print("Scan Results:")
|
|
1246
1469
|
print(f" * New skills to ingest into vault: {len(to_ingest_new)}")
|
|
@@ -1258,8 +1481,11 @@ class SkillVault:
|
|
|
1258
1481
|
for name in sorted(protected_hooks):
|
|
1259
1482
|
print(f" [Protected (Hook Dependency)] {name}")
|
|
1260
1483
|
print(f" * Non-core active skills to prune: {len(to_prune)}")
|
|
1261
|
-
for name,
|
|
1262
|
-
|
|
1484
|
+
for name, data, compat in to_prune:
|
|
1485
|
+
if compat.get("needs_runtime_in_place"):
|
|
1486
|
+
print(f" [PRUNE (Runtime-in-Place)] {name} (Remove SKILL.md only; keep scripts at {data['path']})")
|
|
1487
|
+
else:
|
|
1488
|
+
print(f" [PRUNE] {name} (Will be removed from active context to prevent context bloat)")
|
|
1263
1489
|
print("")
|
|
1264
1490
|
|
|
1265
1491
|
if dry_run:
|
|
@@ -1293,7 +1519,7 @@ class SkillVault:
|
|
|
1293
1519
|
}
|
|
1294
1520
|
total_ingested += 1
|
|
1295
1521
|
|
|
1296
|
-
for name, data in to_prune:
|
|
1522
|
+
for name, data, compat in to_prune:
|
|
1297
1523
|
active_path = Path(data["path"])
|
|
1298
1524
|
if data.get("single_skill_dir"):
|
|
1299
1525
|
for sub in active_path.iterdir():
|
|
@@ -1304,6 +1530,18 @@ class SkillVault:
|
|
|
1304
1530
|
else:
|
|
1305
1531
|
sub.unlink()
|
|
1306
1532
|
print(f"[Pruned] Emptied single-skill directory: {active_path}")
|
|
1533
|
+
elif compat.get("needs_runtime_in_place"):
|
|
1534
|
+
kept_rt = self._prune_skill_runtime_in_place(active_path)
|
|
1535
|
+
if kept_rt and name in manifest_map:
|
|
1536
|
+
manifest_map[name]["runtime_dir"] = self.make_portable_path(active_path)
|
|
1537
|
+
manifest_map[name]["relocation_mode"] = "runtime_in_place"
|
|
1538
|
+
reasons_str = ", ".join(compat.get("path_reasons", [])[:3])
|
|
1539
|
+
print(
|
|
1540
|
+
f"[Pruned (Runtime-in-Place)] Removed SKILL.md only; kept companion files at: "
|
|
1541
|
+
f"{active_path} ({reasons_str})"
|
|
1542
|
+
)
|
|
1543
|
+
else:
|
|
1544
|
+
print(f"[Pruned] Removed active folder: {active_path}")
|
|
1307
1545
|
else:
|
|
1308
1546
|
if active_path.exists():
|
|
1309
1547
|
shutil.rmtree(active_path)
|
|
@@ -1410,6 +1648,7 @@ class SkillVault:
|
|
|
1410
1648
|
manifest = self.load_manifest()
|
|
1411
1649
|
manifest_map = {item["name"]: item for item in manifest}
|
|
1412
1650
|
hook_protected = self.get_hook_protected_skills()
|
|
1651
|
+
bin_shims = self._collect_bin_shim_targets()
|
|
1413
1652
|
|
|
1414
1653
|
skills_to_archive = []
|
|
1415
1654
|
if name:
|
|
@@ -1444,8 +1683,16 @@ class SkillVault:
|
|
|
1444
1683
|
if skill_name in hook_protected:
|
|
1445
1684
|
print(f"[Protected (Hook Dependency)] Preserving active '{skill_name}' (referenced by plugin hooks/MCP; use --force to override)")
|
|
1446
1685
|
else:
|
|
1447
|
-
|
|
1448
|
-
|
|
1686
|
+
compat = self.assess_skill_compat(active_path, original_path=active_path, bin_shim_targets=bin_shims)
|
|
1687
|
+
if compat.get("needs_runtime_in_place"):
|
|
1688
|
+
kept_rt = self._prune_skill_runtime_in_place(active_path)
|
|
1689
|
+
if kept_rt and skill_name in manifest_map:
|
|
1690
|
+
manifest_map[skill_name]["runtime_dir"] = self.make_portable_path(active_path)
|
|
1691
|
+
manifest_map[skill_name]["relocation_mode"] = "runtime_in_place"
|
|
1692
|
+
print(f"[Cleaned (Runtime-in-Place)] Removed SKILL.md only; kept companion files at: {active_path}")
|
|
1693
|
+
else:
|
|
1694
|
+
shutil.rmtree(active_path)
|
|
1695
|
+
print(f"[Cleaned] Removed older active directory: {active_path}")
|
|
1449
1696
|
continue
|
|
1450
1697
|
elif recency > 0:
|
|
1451
1698
|
print(f"[Archived] Overwriting older L2 archive with newer active L1 version: {active_path} -> {dest_dir}")
|
|
@@ -1477,8 +1724,16 @@ class SkillVault:
|
|
|
1477
1724
|
if skill_name in hook_protected and not force:
|
|
1478
1725
|
print(f"[Protected (Hook Dependency)] Preserving active '{skill_name}' (referenced by plugin hooks/MCP; use --force to override)")
|
|
1479
1726
|
else:
|
|
1480
|
-
|
|
1481
|
-
|
|
1727
|
+
compat = self.assess_skill_compat(active_path, original_path=active_path, bin_shim_targets=bin_shims)
|
|
1728
|
+
if compat.get("needs_runtime_in_place") and not force:
|
|
1729
|
+
kept_rt = self._prune_skill_runtime_in_place(active_path)
|
|
1730
|
+
if kept_rt:
|
|
1731
|
+
manifest_map[skill_name]["runtime_dir"] = self.make_portable_path(active_path)
|
|
1732
|
+
manifest_map[skill_name]["relocation_mode"] = "runtime_in_place"
|
|
1733
|
+
print(f"[Cleaned (Runtime-in-Place)] Removed SKILL.md only; kept companion files at: {active_path}")
|
|
1734
|
+
else:
|
|
1735
|
+
shutil.rmtree(active_path)
|
|
1736
|
+
print(f"[Cleaned] Removed active directory: {active_path}")
|
|
1482
1737
|
|
|
1483
1738
|
self.save_manifest(list(manifest_map.values()))
|
|
1484
1739
|
self.reindex()
|
|
@@ -1889,12 +2144,20 @@ class SkillVault:
|
|
|
1889
2144
|
if archived_path.exists() and (archived_path / "SKILL.md").exists():
|
|
1890
2145
|
folder_name = archived_path.name
|
|
1891
2146
|
if folder_name not in manifest_by_folder or item.get("name") == folder_name:
|
|
1892
|
-
|
|
2147
|
+
entry = {
|
|
1893
2148
|
"name": folder_name,
|
|
1894
2149
|
"category": item.get("category") or "General & Utility Skills",
|
|
1895
2150
|
"original_path": item.get("original_path", self.make_portable_path(self.skills_dir / folder_name)),
|
|
1896
2151
|
"archived_path": self.make_portable_path(archived_path),
|
|
1897
2152
|
}
|
|
2153
|
+
if item.get("runtime_dir"):
|
|
2154
|
+
rt_path = self.resolve_original_path(item["runtime_dir"], skill_name=folder_name)
|
|
2155
|
+
if not rt_path.exists():
|
|
2156
|
+
rt_path = self.resolve_portable_path(item["runtime_dir"])
|
|
2157
|
+
if rt_path.exists() and rt_path.is_dir() and not (rt_path / "SKILL.md").exists():
|
|
2158
|
+
entry["runtime_dir"] = item["runtime_dir"]
|
|
2159
|
+
entry["relocation_mode"] = item.get("relocation_mode") or "runtime_in_place"
|
|
2160
|
+
manifest_by_folder[folder_name] = entry
|
|
1898
2161
|
|
|
1899
2162
|
disk_skills = self.get_archived_skill_folders()
|
|
1900
2163
|
for name, data in disk_skills.items():
|
|
@@ -1956,7 +2219,7 @@ class SkillVault:
|
|
|
1956
2219
|
return (
|
|
1957
2220
|
"Universal agent-agnostic skill router and tiered storage manager. "
|
|
1958
2221
|
"Background hooks automatically inject relevant vaulted skills on demand; "
|
|
1959
|
-
"use MCP tools search_skills/load_skill for mid-turn lookups."
|
|
2222
|
+
"use MCP tools list_skills/search_skills/load_skill for mid-turn lookups."
|
|
1960
2223
|
)
|
|
1961
2224
|
|
|
1962
2225
|
def build_router_description(self):
|
|
@@ -2210,108 +2473,312 @@ class SkillVault:
|
|
|
2210
2473
|
print(f" * {rc}")
|
|
2211
2474
|
print("")
|
|
2212
2475
|
|
|
2213
|
-
def verify(self, fix=False):
|
|
2214
|
-
"""Perform a
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
disk_skills = self.get_archived_skill_folders()
|
|
2222
|
-
manifest = self.load_manifest()
|
|
2223
|
-
manifest_map = {m["name"]: m for m in manifest}
|
|
2224
|
-
indexed_skills = self.parse_index_file()
|
|
2476
|
+
def verify(self, fix=False, compat=False, as_json=False):
|
|
2477
|
+
"""Perform a bi-directional integrity check and optional L2 compatibility audit."""
|
|
2478
|
+
if not as_json:
|
|
2479
|
+
print("==================================================")
|
|
2480
|
+
print(" SKILL VAULT INTEGRITY AUDIT")
|
|
2481
|
+
print(f" Base Directory: {self.base_dir}")
|
|
2482
|
+
print(f" Archive Store: {self.archive_dir}")
|
|
2483
|
+
print("==================================================\n")
|
|
2225
2484
|
|
|
2226
|
-
|
|
2227
|
-
|
|
2485
|
+
def _audit_integrity():
|
|
2486
|
+
disk_skills_local = self.get_archived_skill_folders()
|
|
2487
|
+
manifest_local = self.load_manifest()
|
|
2488
|
+
manifest_map_local = {m["name"]: m for m in manifest_local}
|
|
2489
|
+
indexed_local = self.parse_index_file()
|
|
2228
2490
|
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
issues.append(f"[Disk Error] Folder '{name}' in archive is missing SKILL.md")
|
|
2232
|
-
elif d["size"] == 0:
|
|
2233
|
-
issues.append(f"[Disk Error] SKILL.md in '{name}' is 0 bytes (empty file)")
|
|
2491
|
+
issues_local = []
|
|
2492
|
+
warnings_local = []
|
|
2234
2493
|
|
|
2235
|
-
|
|
2236
|
-
|
|
2494
|
+
for name, d in disk_skills_local.items():
|
|
2495
|
+
if not d["has_skill_md"]:
|
|
2496
|
+
issues_local.append(f"[Disk Error] Folder '{name}' in archive is missing SKILL.md")
|
|
2497
|
+
elif d["size"] == 0:
|
|
2498
|
+
issues_local.append(f"[Disk Error] SKILL.md in '{name}' is 0 bytes (empty file)")
|
|
2237
2499
|
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
for name in sorted(unmanifested_disk):
|
|
2241
|
-
issues.append(f"[Uncataloged on Disk] '{name}' exists in archive folder but NOT in backup_manifest.json")
|
|
2500
|
+
disk_names = set(disk_skills_local.keys())
|
|
2501
|
+
manifest_names = set(manifest_map_local.keys())
|
|
2242
2502
|
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
for name in sorted(
|
|
2246
|
-
|
|
2503
|
+
for name in sorted(disk_names - manifest_names):
|
|
2504
|
+
issues_local.append(f"[Uncataloged on Disk] '{name}' exists in archive folder but NOT in backup_manifest.json")
|
|
2505
|
+
for name in sorted(manifest_names - disk_names):
|
|
2506
|
+
issues_local.append(f"[Phantom Manifest Entry] '{name}' listed in backup_manifest.json but NOT found on disk")
|
|
2247
2507
|
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
unindexed_manifest = manifest_names - index_names
|
|
2271
|
-
if unindexed_manifest:
|
|
2272
|
-
for name in sorted(unindexed_manifest):
|
|
2273
|
-
issues.append(f"[Manifest/Index Mismatch] '{name}' is in backup_manifest.json but NOT in INDEX.md")
|
|
2274
|
-
|
|
2275
|
-
for name, data in indexed_skills.items():
|
|
2276
|
-
link_path_str = data.get("link_path")
|
|
2277
|
-
if link_path_str:
|
|
2278
|
-
if link_path_str.startswith("file:///"):
|
|
2279
|
-
pass
|
|
2280
|
-
else:
|
|
2508
|
+
for item in manifest_local:
|
|
2509
|
+
name = item["name"]
|
|
2510
|
+
archived_path = self.resolve_portable_path(item.get("archived_path", ""))
|
|
2511
|
+
if not archived_path.exists():
|
|
2512
|
+
issues_local.append(f"[Broken Manifest Path] '{name}' archived_path does not exist: {archived_path}")
|
|
2513
|
+
elif not (archived_path / "SKILL.md").exists():
|
|
2514
|
+
issues_local.append(f"[Missing SKILL.md] '{name}' archived_path has no SKILL.md: {archived_path}")
|
|
2515
|
+
if not item.get("category"):
|
|
2516
|
+
warnings_local.append(f"[Missing Category] '{name}' in manifest has no category assigned")
|
|
2517
|
+
|
|
2518
|
+
index_names = set(indexed_local.keys())
|
|
2519
|
+
for name in sorted(disk_names - index_names):
|
|
2520
|
+
issues_local.append(f"[Unindexed on Disk] '{name}' exists on disk but is NOT listed in INDEX.md")
|
|
2521
|
+
for name in sorted(index_names - disk_names):
|
|
2522
|
+
issues_local.append(f"[Phantom Index Entry] '{name}' listed in INDEX.md but does NOT exist on disk")
|
|
2523
|
+
for name in sorted(manifest_names - index_names):
|
|
2524
|
+
issues_local.append(f"[Manifest/Index Mismatch] '{name}' is in backup_manifest.json but NOT in INDEX.md")
|
|
2525
|
+
|
|
2526
|
+
for name, data in indexed_local.items():
|
|
2527
|
+
link_path_str = data.get("link_path")
|
|
2528
|
+
if link_path_str and not link_path_str.startswith("file:///"):
|
|
2281
2529
|
target_file = (self.archive_dir / link_path_str).resolve()
|
|
2282
2530
|
if not target_file.exists():
|
|
2283
|
-
|
|
2531
|
+
issues_local.append(f"[Broken Index Link] '{name}' link target missing: {target_file}")
|
|
2284
2532
|
|
|
2285
|
-
|
|
2286
|
-
print(f" * Physical Folders on Disk: {len(disk_skills)}")
|
|
2287
|
-
print(f" * Entries in backup_manifest.json: {len(manifest)}")
|
|
2288
|
-
print(f" * Entries in INDEX.md: {len(indexed_skills)}\n")
|
|
2533
|
+
return disk_skills_local, manifest_local, indexed_local, issues_local, warnings_local
|
|
2289
2534
|
|
|
2290
|
-
|
|
2291
|
-
print("[OK] 100% Integrity Verified! Disk, manifest, and index are in perfect sync.\n")
|
|
2292
|
-
return 0
|
|
2535
|
+
disk_skills, manifest, indexed_skills, issues, warnings = _audit_integrity()
|
|
2293
2536
|
|
|
2294
|
-
if
|
|
2295
|
-
print(
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
print("")
|
|
2537
|
+
if not as_json:
|
|
2538
|
+
print("Component Counts:")
|
|
2539
|
+
print(f" * Physical Folders on Disk: {len(disk_skills)}")
|
|
2540
|
+
print(f" * Entries in backup_manifest.json: {len(manifest)}")
|
|
2541
|
+
print(f" * Entries in INDEX.md: {len(indexed_skills)}\n")
|
|
2299
2542
|
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2543
|
+
if not issues and not warnings and not compat:
|
|
2544
|
+
print("[OK] 100% Integrity Verified! Disk, manifest, and index are in perfect sync.\n")
|
|
2545
|
+
return 0
|
|
2546
|
+
|
|
2547
|
+
if warnings:
|
|
2548
|
+
print(f"Warnings ({len(warnings)}):")
|
|
2549
|
+
for w in warnings:
|
|
2550
|
+
print(f" [!] {w}")
|
|
2551
|
+
print("")
|
|
2552
|
+
|
|
2553
|
+
if issues:
|
|
2554
|
+
print(f"Discrepancies / Errors ({len(issues)}):")
|
|
2555
|
+
for iss in issues:
|
|
2556
|
+
print(f" [X] {iss}")
|
|
2557
|
+
print("")
|
|
2305
2558
|
|
|
2306
|
-
|
|
2559
|
+
integrity_repaired = False
|
|
2560
|
+
if issues and fix:
|
|
2561
|
+
if not as_json:
|
|
2307
2562
|
print("[Self-Healing] Applying automatic repairs (--fix enabled)...")
|
|
2308
|
-
|
|
2563
|
+
self.reindex()
|
|
2564
|
+
integrity_repaired = True
|
|
2565
|
+
if not as_json:
|
|
2309
2566
|
print("[Self-Healing] Reindexed and resynchronized successfully.\n")
|
|
2567
|
+
if not compat and not as_json:
|
|
2310
2568
|
return 0
|
|
2311
|
-
|
|
2569
|
+
disk_skills, manifest, indexed_skills, issues, warnings = _audit_integrity()
|
|
2570
|
+
|
|
2571
|
+
if not compat:
|
|
2572
|
+
if as_json:
|
|
2573
|
+
print(
|
|
2574
|
+
json.dumps(
|
|
2575
|
+
{
|
|
2576
|
+
"counts": {
|
|
2577
|
+
"disk": len(disk_skills),
|
|
2578
|
+
"manifest": len(manifest),
|
|
2579
|
+
"index": len(indexed_skills),
|
|
2580
|
+
},
|
|
2581
|
+
"issues": issues,
|
|
2582
|
+
"warnings": warnings,
|
|
2583
|
+
"integrity_repaired": integrity_repaired,
|
|
2584
|
+
"ok": not issues,
|
|
2585
|
+
},
|
|
2586
|
+
indent=2,
|
|
2587
|
+
)
|
|
2588
|
+
)
|
|
2589
|
+
return 0 if not issues else 1
|
|
2590
|
+
if issues:
|
|
2312
2591
|
print("Tip: Run with '--fix' (e.g. 'python skill_vault.py verify --fix') to automatically repair discrepancies.\n")
|
|
2313
2592
|
return 1
|
|
2593
|
+
return 0
|
|
2594
|
+
|
|
2595
|
+
# Compatibility audit across vaulted skills
|
|
2596
|
+
bin_shims = self._collect_bin_shim_targets()
|
|
2597
|
+
active_skills = self.get_active_skills()
|
|
2598
|
+
base_res = self.base_dir.resolve()
|
|
2599
|
+
root_res = self.get_root_dir().resolve()
|
|
2600
|
+
|
|
2601
|
+
def _can_safely_materialize(orig_path):
|
|
2602
|
+
orig_res = Path(orig_path).resolve()
|
|
2603
|
+
anchor = None
|
|
2604
|
+
rel_parts = ()
|
|
2605
|
+
for cand_anchor in (base_res, root_res):
|
|
2606
|
+
try:
|
|
2607
|
+
rel = orig_res.relative_to(cand_anchor)
|
|
2608
|
+
anchor = cand_anchor
|
|
2609
|
+
rel_parts = rel.parts
|
|
2610
|
+
break
|
|
2611
|
+
except ValueError:
|
|
2612
|
+
continue
|
|
2613
|
+
if anchor is None or (orig_res / "SKILL.md").exists():
|
|
2614
|
+
return False
|
|
2615
|
+
if len(rel_parts) >= 2 and rel_parts[0].lower() == "plugins":
|
|
2616
|
+
plugin_dir = anchor / rel_parts[0] / rel_parts[1]
|
|
2617
|
+
if not plugin_dir.exists() or not plugin_dir.is_dir():
|
|
2618
|
+
return False
|
|
2619
|
+
return True
|
|
2620
|
+
|
|
2621
|
+
path_dependent_broken = []
|
|
2622
|
+
runtime_in_place_active = []
|
|
2623
|
+
cross_skill_refs = []
|
|
2624
|
+
oversized = []
|
|
2625
|
+
vaulted_guardrails = []
|
|
2626
|
+
|
|
2627
|
+
for item in manifest:
|
|
2628
|
+
name = item["name"]
|
|
2629
|
+
archived_path = self.resolve_portable_path(item.get("archived_path", ""))
|
|
2630
|
+
if not (archived_path / "SKILL.md").exists():
|
|
2631
|
+
continue
|
|
2632
|
+
orig_path = self.resolve_original_path(item.get("original_path", ""), skill_name=name)
|
|
2633
|
+
is_active_l1 = (orig_path / "SKILL.md").exists() or (name in active_skills)
|
|
2634
|
+
|
|
2635
|
+
info = self.assess_skill_compat(archived_path, original_path=orig_path, bin_shim_targets=bin_shims)
|
|
2636
|
+
|
|
2637
|
+
rt_ok = False
|
|
2638
|
+
rt_path = None
|
|
2639
|
+
if item.get("runtime_dir"):
|
|
2640
|
+
rt_path = self.resolve_original_path(item["runtime_dir"], skill_name=name)
|
|
2641
|
+
if not rt_path.exists():
|
|
2642
|
+
rt_path = self.resolve_portable_path(item["runtime_dir"])
|
|
2643
|
+
try:
|
|
2644
|
+
rt_ok = (
|
|
2645
|
+
rt_path.exists()
|
|
2646
|
+
and rt_path.is_dir()
|
|
2647
|
+
and not (rt_path / "SKILL.md").exists()
|
|
2648
|
+
and any(rt_path.iterdir())
|
|
2649
|
+
)
|
|
2650
|
+
except OSError:
|
|
2651
|
+
rt_ok = False
|
|
2652
|
+
|
|
2653
|
+
if info["needs_runtime_in_place"] and not is_active_l1:
|
|
2654
|
+
if rt_ok:
|
|
2655
|
+
runtime_in_place_active.append({
|
|
2656
|
+
"name": name,
|
|
2657
|
+
"runtime_dir": str(rt_path),
|
|
2658
|
+
"reasons": info["path_reasons"],
|
|
2659
|
+
})
|
|
2660
|
+
else:
|
|
2661
|
+
path_dependent_broken.append({
|
|
2662
|
+
"name": name,
|
|
2663
|
+
"item": item,
|
|
2664
|
+
"archived_path": archived_path,
|
|
2665
|
+
"orig_path": orig_path,
|
|
2666
|
+
"reasons": info["path_reasons"],
|
|
2667
|
+
})
|
|
2668
|
+
|
|
2669
|
+
if info["cross_skill_refs"]:
|
|
2670
|
+
cross_skill_refs.append({"name": name, "refs": info["cross_skill_refs"]})
|
|
2671
|
+
if info["oversized_skill_md"]:
|
|
2672
|
+
oversized.append({"name": name, "bytes": info["skill_md_bytes"]})
|
|
2673
|
+
if info["guardrail_signals"] and not is_active_l1:
|
|
2674
|
+
vaulted_guardrails.append({"name": name, "signals": info["guardrail_signals"]})
|
|
2675
|
+
|
|
2676
|
+
repaired_compat = []
|
|
2677
|
+
remaining_broken = []
|
|
2678
|
+
if fix and path_dependent_broken:
|
|
2679
|
+
for entry in path_dependent_broken:
|
|
2680
|
+
orig_path = entry["orig_path"]
|
|
2681
|
+
if _can_safely_materialize(orig_path):
|
|
2682
|
+
self._materialize_runtime_companions(entry["archived_path"], orig_path)
|
|
2683
|
+
entry["item"]["runtime_dir"] = self.make_portable_path(orig_path)
|
|
2684
|
+
entry["item"]["relocation_mode"] = "runtime_in_place"
|
|
2685
|
+
repaired_compat.append({"name": entry["name"], "runtime_dir": str(orig_path)})
|
|
2686
|
+
runtime_in_place_active.append({
|
|
2687
|
+
"name": entry["name"],
|
|
2688
|
+
"runtime_dir": str(orig_path),
|
|
2689
|
+
"reasons": entry["reasons"],
|
|
2690
|
+
})
|
|
2691
|
+
else:
|
|
2692
|
+
remaining_broken.append(entry)
|
|
2693
|
+
if repaired_compat:
|
|
2694
|
+
self.save_manifest(manifest)
|
|
2695
|
+
if not as_json:
|
|
2696
|
+
self.reindex()
|
|
2697
|
+
else:
|
|
2698
|
+
old_stdout = sys.stdout
|
|
2699
|
+
sys.stdout = io.StringIO()
|
|
2700
|
+
try:
|
|
2701
|
+
self.reindex()
|
|
2702
|
+
finally:
|
|
2703
|
+
sys.stdout = old_stdout
|
|
2704
|
+
else:
|
|
2705
|
+
remaining_broken = path_dependent_broken
|
|
2706
|
+
|
|
2707
|
+
remaining_broken_pub = [
|
|
2708
|
+
{"name": e["name"], "original_path": str(e["orig_path"]), "reasons": e["reasons"]}
|
|
2709
|
+
for e in remaining_broken
|
|
2710
|
+
]
|
|
2711
|
+
|
|
2712
|
+
if as_json:
|
|
2713
|
+
print(
|
|
2714
|
+
json.dumps(
|
|
2715
|
+
{
|
|
2716
|
+
"counts": {
|
|
2717
|
+
"disk": len(disk_skills),
|
|
2718
|
+
"manifest": len(manifest),
|
|
2719
|
+
"index": len(indexed_skills),
|
|
2720
|
+
},
|
|
2721
|
+
"issues": issues,
|
|
2722
|
+
"warnings": warnings,
|
|
2723
|
+
"integrity_repaired": integrity_repaired,
|
|
2724
|
+
"compat": {
|
|
2725
|
+
"path_dependent_broken": remaining_broken_pub,
|
|
2726
|
+
"runtime_in_place_active": runtime_in_place_active,
|
|
2727
|
+
"repaired": repaired_compat,
|
|
2728
|
+
"cross_skill_refs": cross_skill_refs,
|
|
2729
|
+
"oversized": oversized,
|
|
2730
|
+
"vaulted_guardrails": vaulted_guardrails,
|
|
2731
|
+
},
|
|
2732
|
+
"ok": (not issues) and (not remaining_broken_pub),
|
|
2733
|
+
},
|
|
2734
|
+
indent=2,
|
|
2735
|
+
)
|
|
2736
|
+
)
|
|
2737
|
+
return 0 if (not issues and not remaining_broken_pub) else 1
|
|
2738
|
+
|
|
2739
|
+
print("==================================================")
|
|
2740
|
+
print(" L2 COMPATIBILITY AUDIT SUMMARY")
|
|
2741
|
+
print("==================================================")
|
|
2742
|
+
print(f" * Path-Dependent Skills Missing Runtime-in-Place: {len(remaining_broken_pub)}")
|
|
2743
|
+
for e in remaining_broken_pub:
|
|
2744
|
+
print(f" [X] {e['name']} -> {e['original_path']} ({', '.join(e['reasons'][:3])})")
|
|
2745
|
+
|
|
2746
|
+
if repaired_compat:
|
|
2747
|
+
print(f" * Materialized Runtime-in-Place (--fix): {len(repaired_compat)}")
|
|
2748
|
+
for r in repaired_compat:
|
|
2749
|
+
print(f" [FIXED] {r['name']} -> {r['runtime_dir']} (companions restored without SKILL.md)")
|
|
2750
|
+
|
|
2751
|
+
print(f" * Runtime-in-Place Protected Skills: {len(runtime_in_place_active)}")
|
|
2752
|
+
for r in runtime_in_place_active[:10]:
|
|
2753
|
+
print(f" [OK] {r['name']} -> {r['runtime_dir']}")
|
|
2754
|
+
if len(runtime_in_place_active) > 10:
|
|
2755
|
+
print(f" ... (+{len(runtime_in_place_active) - 10} more)")
|
|
2756
|
+
|
|
2757
|
+
print(f" * Cross-Skill / Plugin References: {len(cross_skill_refs)}")
|
|
2758
|
+
for c in cross_skill_refs[:10]:
|
|
2759
|
+
print(f" [!] {c['name']}: {', '.join(c['refs'][:4])}")
|
|
2760
|
+
if len(cross_skill_refs) > 10:
|
|
2761
|
+
print(f" ... (+{len(cross_skill_refs) - 10} more)")
|
|
2762
|
+
|
|
2763
|
+
print(f" * Oversized SKILL.md (truncated on inline): {len(oversized)}")
|
|
2764
|
+
for o in sorted(oversized, key=lambda x: -x["bytes"])[:10]:
|
|
2765
|
+
print(f" [!] {o['name']}: {o['bytes']} bytes")
|
|
2766
|
+
if len(oversized) > 10:
|
|
2767
|
+
print(f" ... (+{len(oversized) - 10} more)")
|
|
2768
|
+
|
|
2769
|
+
print(f" * Vaulted Always-On / Guardrail Skills: {len(vaulted_guardrails)}")
|
|
2770
|
+
for g in vaulted_guardrails[:10]:
|
|
2771
|
+
print(f" [!] {g['name']}: {', '.join(g['signals'])}")
|
|
2772
|
+
if len(vaulted_guardrails) > 10:
|
|
2773
|
+
print(f" ... (+{len(vaulted_guardrails) - 10} more)")
|
|
2774
|
+
print("")
|
|
2314
2775
|
|
|
2776
|
+
if remaining_broken_pub and not fix:
|
|
2777
|
+
print("Tip: Run with '--compat --fix' to materialize runtime-in-place companion files without L1 SKILL.md bloat.\n")
|
|
2778
|
+
|
|
2779
|
+
if issues or remaining_broken_pub:
|
|
2780
|
+
return 1
|
|
2781
|
+
print("[OK] L2 Compatibility Audit passed with no unresolved path-dependent skills.\n")
|
|
2315
2782
|
return 0
|
|
2316
2783
|
|
|
2317
2784
|
def search(self, query, category=None, limit=10, as_json=False):
|
|
@@ -2466,51 +2933,174 @@ class SkillVault:
|
|
|
2466
2933
|
print("")
|
|
2467
2934
|
return 0
|
|
2468
2935
|
|
|
2936
|
+
@staticmethod
|
|
2937
|
+
def _inspect_dedupe_entry(idx, item, dir_path):
|
|
2938
|
+
"""Extract canonical name, frontmatter alias, content hash, and recency metadata for dedupe."""
|
|
2939
|
+
canon_name = skill_router.canonicalize_skill_name(item.get("name", ""))
|
|
2940
|
+
fm_canon_name = None
|
|
2941
|
+
content_hash = None
|
|
2942
|
+
size_bytes = 0
|
|
2943
|
+
skill_md = dir_path / "SKILL.md"
|
|
2944
|
+
if skill_md.exists():
|
|
2945
|
+
try:
|
|
2946
|
+
raw_bytes = skill_md.read_bytes()
|
|
2947
|
+
size_bytes = len(raw_bytes)
|
|
2948
|
+
if size_bytes >= 64:
|
|
2949
|
+
content_hash = hashlib.sha256(raw_bytes).hexdigest()
|
|
2950
|
+
content = raw_bytes.decode("utf-8", errors="ignore")
|
|
2951
|
+
fm_match = re.match(r"^---\s*\n(.*?)\n---(?:\s*\n|\s*\Z)", content, re.DOTALL)
|
|
2952
|
+
if fm_match:
|
|
2953
|
+
n_match = re.search(r"^name:\s*([^\n]+)", fm_match.group(1), re.MULTILINE | re.IGNORECASE)
|
|
2954
|
+
if n_match:
|
|
2955
|
+
fm_raw = n_match.group(1).strip().strip("'\"")
|
|
2956
|
+
if fm_raw:
|
|
2957
|
+
fm_canon_name = skill_router.canonicalize_skill_name(fm_raw) or None
|
|
2958
|
+
except OSError:
|
|
2959
|
+
pass
|
|
2960
|
+
ver_tuple, mtime = get_skill_metadata(dir_path)
|
|
2961
|
+
return {
|
|
2962
|
+
"idx": idx,
|
|
2963
|
+
"item": item,
|
|
2964
|
+
"dir_path": dir_path,
|
|
2965
|
+
"canon_name": canon_name,
|
|
2966
|
+
"fm_canon_name": fm_canon_name,
|
|
2967
|
+
"content_hash": content_hash,
|
|
2968
|
+
"size_bytes": size_bytes,
|
|
2969
|
+
"ver_tuple": ver_tuple,
|
|
2970
|
+
"mtime": mtime,
|
|
2971
|
+
}
|
|
2972
|
+
|
|
2973
|
+
@staticmethod
|
|
2974
|
+
def _dedupe_candidate_beats(cand_info, win_info):
|
|
2975
|
+
"""Return True if cand_info is newer or preferred over win_info."""
|
|
2976
|
+
rec = compare_skill_recency(cand_info["dir_path"], win_info["dir_path"])
|
|
2977
|
+
if rec != 0:
|
|
2978
|
+
return rec > 0
|
|
2979
|
+
cand_name = cand_info["item"]["name"]
|
|
2980
|
+
win_name = win_info["item"]["name"]
|
|
2981
|
+
cand_hyphen = "-" in cand_name and "_" not in cand_name
|
|
2982
|
+
win_hyphen = "-" in win_name and "_" not in win_name
|
|
2983
|
+
if cand_hyphen != win_hyphen:
|
|
2984
|
+
return cand_hyphen
|
|
2985
|
+
if cand_info["size_bytes"] != win_info["size_bytes"]:
|
|
2986
|
+
return cand_info["size_bytes"] > win_info["size_bytes"]
|
|
2987
|
+
return cand_name.lower() < win_name.lower()
|
|
2988
|
+
|
|
2989
|
+
@staticmethod
|
|
2990
|
+
def _format_dedupe_meta(info):
|
|
2991
|
+
ver_str = ".".join(map(str, info["ver_tuple"])) if info["ver_tuple"] is not None else "none"
|
|
2992
|
+
mtime_str = (
|
|
2993
|
+
datetime.fromtimestamp(info["mtime"]).strftime("%Y-%m-%d %H:%M")
|
|
2994
|
+
if info["mtime"] > 0
|
|
2995
|
+
else "unknown"
|
|
2996
|
+
)
|
|
2997
|
+
return f"[ver={ver_str}, mtime={mtime_str}]"
|
|
2998
|
+
|
|
2469
2999
|
def dedupe(self, dry_run=False):
|
|
2470
|
-
"""Consolidate
|
|
3000
|
+
"""Consolidate duplicate skills in L2 (canonical name, frontmatter name, or identical content), keeping the newest version."""
|
|
2471
3001
|
manifest = self.load_manifest()
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
3002
|
+
infos = [
|
|
3003
|
+
self._inspect_dedupe_entry(i, item, self.resolve_portable_path(item.get("archived_path", "")))
|
|
3004
|
+
for i, item in enumerate(manifest)
|
|
3005
|
+
]
|
|
2476
3006
|
|
|
2477
|
-
|
|
3007
|
+
# Union-Find over manifest entries sharing canonical name, frontmatter name, or SKILL.md SHA-256
|
|
3008
|
+
parent = list(range(len(infos)))
|
|
3009
|
+
|
|
3010
|
+
def _find(x):
|
|
3011
|
+
while parent[x] != x:
|
|
3012
|
+
parent[x] = parent[parent[x]]
|
|
3013
|
+
x = parent[x]
|
|
3014
|
+
return x
|
|
3015
|
+
|
|
3016
|
+
def _union(a, b):
|
|
3017
|
+
ra, rb = _find(a), _find(b)
|
|
3018
|
+
if ra != rb:
|
|
3019
|
+
parent[rb] = ra
|
|
3020
|
+
|
|
3021
|
+
buckets = {}
|
|
3022
|
+
for info in infos:
|
|
3023
|
+
idx = info["idx"]
|
|
3024
|
+
keys = []
|
|
3025
|
+
if info["canon_name"]:
|
|
3026
|
+
keys.append(("name", info["canon_name"]))
|
|
3027
|
+
if info["fm_canon_name"]:
|
|
3028
|
+
keys.append(("name", info["fm_canon_name"]))
|
|
3029
|
+
if info["content_hash"]:
|
|
3030
|
+
keys.append(("sha256", info["content_hash"]))
|
|
3031
|
+
for key in keys:
|
|
3032
|
+
buckets.setdefault(key, []).append(idx)
|
|
3033
|
+
|
|
3034
|
+
for key_indices in buckets.values():
|
|
3035
|
+
if len(key_indices) > 1:
|
|
3036
|
+
head = key_indices[0]
|
|
3037
|
+
for other in key_indices[1:]:
|
|
3038
|
+
_union(head, other)
|
|
3039
|
+
|
|
3040
|
+
components = {}
|
|
3041
|
+
for info in infos:
|
|
3042
|
+
components.setdefault(_find(info["idx"]), []).append(info)
|
|
3043
|
+
|
|
3044
|
+
dup_components = [grp for grp in components.values() if len(grp) > 1]
|
|
2478
3045
|
print("==================================================")
|
|
2479
3046
|
print(" SKILL VAULT DUPLICATE CHECK")
|
|
2480
3047
|
print(f" Total Manifest Entries: {len(manifest)}")
|
|
2481
|
-
print(f" Duplicate Groups Found: {len(
|
|
3048
|
+
print(f" Duplicate Groups Found: {len(dup_components)}")
|
|
2482
3049
|
print("==================================================\n")
|
|
2483
3050
|
|
|
2484
|
-
if not
|
|
2485
|
-
print("[OK] No duplicate
|
|
3051
|
+
if not dup_components:
|
|
3052
|
+
print("[OK] No duplicate skills found in vault.")
|
|
2486
3053
|
return 0
|
|
2487
3054
|
|
|
2488
3055
|
to_remove = []
|
|
2489
|
-
kept_entries =
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
3056
|
+
kept_entries = []
|
|
3057
|
+
prepared_groups = []
|
|
3058
|
+
for grp in components.values():
|
|
3059
|
+
if len(grp) == 1:
|
|
3060
|
+
kept_entries.append(grp[0]["item"])
|
|
2493
3061
|
continue
|
|
2494
3062
|
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
3063
|
+
win_info = grp[0]
|
|
3064
|
+
for cand_info in grp[1:]:
|
|
3065
|
+
if self._dedupe_candidate_beats(cand_info, win_info):
|
|
3066
|
+
win_info = cand_info
|
|
3067
|
+
kept_entries.append(win_info["item"])
|
|
3068
|
+
|
|
3069
|
+
reasons = set()
|
|
3070
|
+
for i in range(len(grp)):
|
|
3071
|
+
for j in range(i + 1, len(grp)):
|
|
3072
|
+
a, b = grp[i], grp[j]
|
|
3073
|
+
if a["canon_name"] and a["canon_name"] == b["canon_name"]:
|
|
3074
|
+
reasons.add("canonical-name")
|
|
3075
|
+
else:
|
|
3076
|
+
a_names = {n for n in (a["canon_name"], a["fm_canon_name"]) if n}
|
|
3077
|
+
b_names = {n for n in (b["canon_name"], b["fm_canon_name"]) if n}
|
|
3078
|
+
if a_names & b_names:
|
|
3079
|
+
reasons.add("frontmatter-name")
|
|
3080
|
+
if a["content_hash"] and a["content_hash"] == b["content_hash"]:
|
|
3081
|
+
reasons.add("identical-content")
|
|
3082
|
+
|
|
3083
|
+
group_label = win_info["canon_name"] or win_info["item"]["name"]
|
|
3084
|
+
losers = [c for c in grp if c["idx"] != win_info["idx"]]
|
|
3085
|
+
losers.sort(key=lambda c: c["item"]["name"].lower())
|
|
3086
|
+
prepared_groups.append((group_label, sorted(reasons), win_info, losers))
|
|
3087
|
+
|
|
3088
|
+
prepared_groups.sort(key=lambda g: g[0].lower())
|
|
3089
|
+
for group_label, reasons, win_info, losers in prepared_groups:
|
|
3090
|
+
reasons_str = ", ".join(reasons) if reasons else "canonical-name"
|
|
3091
|
+
print(f"Group '{group_label}' (matched by: {reasons_str}):")
|
|
3092
|
+
win_item = win_info["item"]
|
|
3093
|
+
print(
|
|
3094
|
+
f" [KEEP] {win_item['name']} ({win_item.get('category', 'General & Utility Skills')}) "
|
|
3095
|
+
f"{self._format_dedupe_meta(win_info)} -> {win_info['dir_path']}"
|
|
3096
|
+
)
|
|
3097
|
+
for cand_info in losers:
|
|
3098
|
+
cand_item = cand_info["item"]
|
|
3099
|
+
print(
|
|
3100
|
+
f" [REMOVE] {cand_item['name']} ({cand_item.get('category', 'General & Utility Skills')}) "
|
|
3101
|
+
f"{self._format_dedupe_meta(cand_info)} -> {cand_info['dir_path']}"
|
|
3102
|
+
)
|
|
3103
|
+
to_remove.append((cand_item, cand_info["dir_path"], win_info["dir_path"]))
|
|
2514
3104
|
|
|
2515
3105
|
if dry_run:
|
|
2516
3106
|
print(f"\n[Dry Run] Would consolidate {len(to_remove)} duplicate skill(s). No files were modified.")
|
|
@@ -2521,7 +3111,7 @@ class SkillVault:
|
|
|
2521
3111
|
shutil.rmtree(cand_dir)
|
|
2522
3112
|
print(f"[Removed] {cand_dir}")
|
|
2523
3113
|
|
|
2524
|
-
self.save_manifest(
|
|
3114
|
+
self.save_manifest(kept_entries)
|
|
2525
3115
|
self.reindex()
|
|
2526
3116
|
print(f"\n[OK] Consolidated {len(to_remove)} duplicate skill(s).")
|
|
2527
3117
|
return 0
|
|
@@ -2832,7 +3422,7 @@ class SkillVault:
|
|
|
2832
3422
|
plugin_meta = {
|
|
2833
3423
|
"name": "skill-vault",
|
|
2834
3424
|
"displayName": "Skill Vault",
|
|
2835
|
-
"version": "2.
|
|
3425
|
+
"version": "2.1.0",
|
|
2836
3426
|
"description": "Automatic background skill router, cold-storage archive, and read-only JIT MCP server.",
|
|
2837
3427
|
"author": "jcorpac",
|
|
2838
3428
|
"license": "MIT",
|
|
@@ -3221,8 +3811,10 @@ def main():
|
|
|
3221
3811
|
p_idx = subparsers.add_parser("reindex", help="Rebuild INDEX.md, search_index.json, and sync manifest")
|
|
3222
3812
|
|
|
3223
3813
|
# Verify / Integrity Check
|
|
3224
|
-
p_ver = subparsers.add_parser("verify", help="Verify archive integrity
|
|
3814
|
+
p_ver = subparsers.add_parser("verify", help="Verify archive integrity and L2 compatibility")
|
|
3225
3815
|
p_ver.add_argument("--fix", action="store_true", help="Automatically repair any detected discrepancies")
|
|
3816
|
+
p_ver.add_argument("--compat", action="store_true", help="Audit L2 compatibility (path dependencies, cross-skill refs, oversized SKILL.md, guardrails)")
|
|
3817
|
+
p_ver.add_argument("--json", action="store_true", help="Output structured JSON")
|
|
3226
3818
|
|
|
3227
3819
|
# Search
|
|
3228
3820
|
p_srch = subparsers.add_parser("search", help="Search archived skills by keyword, intent, or domain")
|
|
@@ -3239,7 +3831,10 @@ def main():
|
|
|
3239
3831
|
p_route.add_argument("--json", action="store_true", help="Output structured JSON")
|
|
3240
3832
|
|
|
3241
3833
|
# Dedupe
|
|
3242
|
-
p_dedupe = subparsers.add_parser(
|
|
3834
|
+
p_dedupe = subparsers.add_parser(
|
|
3835
|
+
"dedupe",
|
|
3836
|
+
help="Consolidate duplicate skills in archive (canonical name, frontmatter name, or identical content), keeping the newest version",
|
|
3837
|
+
)
|
|
3243
3838
|
p_dedupe.add_argument("--dry-run", action="store_true", help="Preview duplicates without deleting files")
|
|
3244
3839
|
|
|
3245
3840
|
# Stats
|
|
@@ -3351,7 +3946,7 @@ def main():
|
|
|
3351
3946
|
elif args.command == "reindex":
|
|
3352
3947
|
mgr.reindex()
|
|
3353
3948
|
elif args.command == "verify":
|
|
3354
|
-
sys.exit(mgr.verify(fix=args.fix))
|
|
3949
|
+
sys.exit(mgr.verify(fix=args.fix, compat=args.compat, as_json=args.json))
|
|
3355
3950
|
elif args.command == "search":
|
|
3356
3951
|
mgr.search(query=args.query, category=args.category, limit=args.limit, as_json=args.json)
|
|
3357
3952
|
elif args.command == "route":
|