@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_router.py
CHANGED
|
@@ -120,6 +120,7 @@ STOPWORDS = {
|
|
|
120
120
|
SHORT_DOMAIN_TOKENS = {
|
|
121
121
|
"ai", "ml", "db", "ui", "ux", "ci", "cd", "qa", "tf", "go",
|
|
122
122
|
"ik", "js", "ts", "py", "bq", "vm", "os", "io", "ip", "pr",
|
|
123
|
+
"uv",
|
|
123
124
|
}
|
|
124
125
|
|
|
125
126
|
# Broad tech terms that should not trigger skill injection on their own as a solo 1-token query
|
|
@@ -221,8 +222,10 @@ def tokenize(text, include_stems=True):
|
|
|
221
222
|
|
|
222
223
|
|
|
223
224
|
def canonicalize_skill_name(name):
|
|
224
|
-
"""Return canonical deduplication key normalizing case and
|
|
225
|
-
|
|
225
|
+
"""Return canonical deduplication key normalizing case and separator differences (-, _, ., spaces)."""
|
|
226
|
+
raw = str(name or "").strip().lower()
|
|
227
|
+
alnum = re.sub(r"[^a-z0-9]+", "", raw)
|
|
228
|
+
return alnum or raw
|
|
226
229
|
|
|
227
230
|
|
|
228
231
|
def _parse_version_tuple(ver_str):
|
|
@@ -233,6 +236,22 @@ def _parse_version_tuple(ver_str):
|
|
|
233
236
|
return tuple(int(n) for n in nums) if nums else None
|
|
234
237
|
|
|
235
238
|
|
|
239
|
+
def _compare_version_tuples(ver_a, ver_b):
|
|
240
|
+
"""Compare two version tuples with zero-padding. Returns 1, -1, or 0."""
|
|
241
|
+
if ver_a is None or ver_b is None:
|
|
242
|
+
return 0
|
|
243
|
+
ta = tuple(ver_a)
|
|
244
|
+
tb = tuple(ver_b)
|
|
245
|
+
max_len = max(len(ta), len(tb))
|
|
246
|
+
pa = ta + (0,) * (max_len - len(ta))
|
|
247
|
+
pb = tb + (0,) * (max_len - len(tb))
|
|
248
|
+
if pa > pb:
|
|
249
|
+
return 1
|
|
250
|
+
if pa < pb:
|
|
251
|
+
return -1
|
|
252
|
+
return 0
|
|
253
|
+
|
|
254
|
+
|
|
236
255
|
def _parse_frontmatter(content):
|
|
237
256
|
"""Parse YAML frontmatter fields from SKILL.md without external YAML dependencies."""
|
|
238
257
|
fm_match = re.match(r"^---\s*\n(.*?)\n---(?:\s*\n|\s*\Z)", content, re.DOTALL)
|
|
@@ -246,6 +265,8 @@ def _parse_frontmatter(content):
|
|
|
246
265
|
# Scalar fields
|
|
247
266
|
for field in ("name", "version", "category"):
|
|
248
267
|
m = re.search(rf"^{field}:\s*([^\n]+)", fm_text, re.MULTILINE | re.IGNORECASE)
|
|
268
|
+
if not m and field == "version":
|
|
269
|
+
m = re.search(r"^[ \t]+version:\s*([^\n]+)", fm_text, re.MULTILINE | re.IGNORECASE)
|
|
249
270
|
if m:
|
|
250
271
|
val = m.group(1).strip().strip("'\"")
|
|
251
272
|
if val:
|
|
@@ -414,24 +435,25 @@ def _is_newer_entry(cand, existing):
|
|
|
414
435
|
"""Return True if cand entry is strictly newer/preferred over existing entry."""
|
|
415
436
|
va = cand.get("version_tuple")
|
|
416
437
|
vb = existing.get("version_tuple")
|
|
417
|
-
if va is not None and vb is not None
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
if va is None and vb is not None:
|
|
422
|
-
return False
|
|
438
|
+
if va is not None and vb is not None:
|
|
439
|
+
vcmp = _compare_version_tuples(va, vb)
|
|
440
|
+
if vcmp != 0:
|
|
441
|
+
return vcmp > 0
|
|
423
442
|
|
|
424
443
|
ma = cand.get("mtime", 0.0)
|
|
425
444
|
mb = existing.get("mtime", 0.0)
|
|
426
445
|
if abs(ma - mb) > 1.0:
|
|
427
446
|
return ma > mb
|
|
428
447
|
|
|
448
|
+
if (va is not None) != (vb is not None):
|
|
449
|
+
return va is not None
|
|
450
|
+
|
|
429
451
|
# Tie-breaker: prefer hyphenated names over underscored names
|
|
430
452
|
cand_hyphen = "-" in cand["name"] and "_" not in cand["name"]
|
|
431
453
|
exist_hyphen = "-" in existing["name"] and "_" not in existing["name"]
|
|
432
454
|
if cand_hyphen != exist_hyphen:
|
|
433
455
|
return cand_hyphen
|
|
434
|
-
return cand["name"] < existing["name"]
|
|
456
|
+
return cand["name"].lower() < existing["name"].lower()
|
|
435
457
|
|
|
436
458
|
|
|
437
459
|
def _resolve_archived_skill_dir(base_dir, archive_dir, raw_archived_path):
|
|
@@ -481,6 +503,24 @@ def build_search_index(archive_dir, manifest, base_dir=None, resolve_path_fn=Non
|
|
|
481
503
|
entry["resolved_path"] = str(skill_dir)
|
|
482
504
|
entry["aliases"] = [name]
|
|
483
505
|
|
|
506
|
+
raw_rt = item.get("runtime_dir")
|
|
507
|
+
if raw_rt:
|
|
508
|
+
rt_cand = None
|
|
509
|
+
if resolve_path_fn is not None:
|
|
510
|
+
rt_cand = Path(resolve_path_fn(raw_rt))
|
|
511
|
+
else:
|
|
512
|
+
p_rt = Path(raw_rt)
|
|
513
|
+
if p_rt.is_absolute():
|
|
514
|
+
rt_cand = p_rt
|
|
515
|
+
elif base_dir is not None and (Path(base_dir) / p_rt).exists():
|
|
516
|
+
rt_cand = (Path(base_dir) / p_rt).resolve()
|
|
517
|
+
else:
|
|
518
|
+
rt_cand = _resolve_archived_skill_dir(base_dir, archive_path, raw_rt)
|
|
519
|
+
if rt_cand and rt_cand.exists() and rt_cand.is_dir():
|
|
520
|
+
entry["runtime_dir"] = str(rt_cand.resolve())
|
|
521
|
+
if not entry.get("companion_files"):
|
|
522
|
+
entry["companion_files"] = _list_companion_files(rt_cand)
|
|
523
|
+
|
|
484
524
|
ckey = entry["canonical_key"]
|
|
485
525
|
if ckey not in deduped:
|
|
486
526
|
deduped[ckey] = entry
|
|
@@ -548,7 +588,11 @@ def load_or_build_index(archive_dir, base_dir=None, resolve_path_fn=None):
|
|
|
548
588
|
data = json.load(f)
|
|
549
589
|
if (
|
|
550
590
|
isinstance(data, dict)
|
|
551
|
-
and data.get("schema_version")
|
|
591
|
+
and isinstance(data.get("schema_version"), int)
|
|
592
|
+
and data.get("schema_version") >= INDEX_SCHEMA_VERSION
|
|
593
|
+
and isinstance(data.get("skills"), list)
|
|
594
|
+
and isinstance(data.get("df"), dict)
|
|
595
|
+
and isinstance(data.get("avg_len"), dict)
|
|
552
596
|
and float(data.get("manifest_mtime", 0.0)) >= manifest_mtime - 0.5
|
|
553
597
|
):
|
|
554
598
|
return data
|
|
@@ -608,7 +652,7 @@ def search_index(
|
|
|
608
652
|
# Extract distinct semantic concepts without summing base + stem duplicates
|
|
609
653
|
concept_tokens = list(dict.fromkeys(tokenize(query, include_stems=False)))
|
|
610
654
|
|
|
611
|
-
if not
|
|
655
|
+
if not raw_query and not category:
|
|
612
656
|
return []
|
|
613
657
|
|
|
614
658
|
specific_concepts = [
|
|
@@ -629,7 +673,7 @@ def search_index(
|
|
|
629
673
|
if category and entry_cat.lower() != category.strip().lower():
|
|
630
674
|
continue
|
|
631
675
|
|
|
632
|
-
if not
|
|
676
|
+
if not raw_query and category:
|
|
633
677
|
results.append({
|
|
634
678
|
"name": entry["name"],
|
|
635
679
|
"canonical_key": ckey,
|
|
@@ -639,6 +683,7 @@ def search_index(
|
|
|
639
683
|
"description": entry.get("description", ""),
|
|
640
684
|
"archived_path": entry.get("archived_path", ""),
|
|
641
685
|
"resolved_path": entry.get("resolved_path", ""),
|
|
686
|
+
"runtime_dir": entry.get("runtime_dir", ""),
|
|
642
687
|
"skill_md_bytes": entry.get("skill_md_bytes", 0),
|
|
643
688
|
"companion_files": entry.get("companion_files", []),
|
|
644
689
|
"aliases": entry.get("aliases", [entry["name"]]),
|
|
@@ -736,15 +781,17 @@ def search_index(
|
|
|
736
781
|
for alias in entry.get("aliases", [entry["name"]]):
|
|
737
782
|
alias_l = alias.lower()
|
|
738
783
|
alias_spaces = re.sub(r"[-_]+", " ", alias_l)
|
|
739
|
-
if (
|
|
740
|
-
|
|
741
|
-
and (
|
|
784
|
+
if len(alias_l) >= 4:
|
|
785
|
+
if (
|
|
742
786
|
re.search(rf"(?<![a-z0-9]){re.escape(alias_l)}(?![a-z0-9])", raw_query)
|
|
743
787
|
or re.search(rf"(?<![a-z0-9]){re.escape(alias_spaces)}(?![a-z0-9])", raw_query_norm)
|
|
744
|
-
)
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
788
|
+
):
|
|
789
|
+
exact_name_hit = True
|
|
790
|
+
break
|
|
791
|
+
elif len(alias_l) >= 2 and alias_l not in STOPWORDS:
|
|
792
|
+
if raw_query == alias_l or raw_query_norm == alias_spaces:
|
|
793
|
+
exact_name_hit = True
|
|
794
|
+
break
|
|
748
795
|
|
|
749
796
|
if exact_name_hit:
|
|
750
797
|
bm25_score += 10.0
|
|
@@ -797,6 +844,7 @@ def search_index(
|
|
|
797
844
|
"description": entry.get("description", ""),
|
|
798
845
|
"archived_path": entry.get("archived_path", ""),
|
|
799
846
|
"resolved_path": entry.get("resolved_path", ""),
|
|
847
|
+
"runtime_dir": entry.get("runtime_dir", ""),
|
|
800
848
|
"skill_md_bytes": entry.get("skill_md_bytes", 0),
|
|
801
849
|
"companion_files": entry.get("companion_files", []),
|
|
802
850
|
"aliases": entry.get("aliases", [entry["name"]]),
|
|
@@ -823,19 +871,89 @@ def _resolve_skill_md_for_candidate(cand, archive_dir, base_dir=None):
|
|
|
823
871
|
return None, None
|
|
824
872
|
|
|
825
873
|
|
|
874
|
+
def _extract_markdown_headings(text, max_headings=12):
|
|
875
|
+
"""Extract top-level (h1-h3) Markdown headings outside fenced code blocks."""
|
|
876
|
+
headings = []
|
|
877
|
+
seen = set()
|
|
878
|
+
in_fence = False
|
|
879
|
+
fence_marker = None
|
|
880
|
+
for line in text.splitlines():
|
|
881
|
+
stripped = line.lstrip()
|
|
882
|
+
if stripped.startswith("```") or stripped.startswith("~~~"):
|
|
883
|
+
marker = stripped[:3]
|
|
884
|
+
if not in_fence:
|
|
885
|
+
in_fence = True
|
|
886
|
+
fence_marker = marker
|
|
887
|
+
elif marker == fence_marker:
|
|
888
|
+
in_fence = False
|
|
889
|
+
fence_marker = None
|
|
890
|
+
continue
|
|
891
|
+
if in_fence:
|
|
892
|
+
continue
|
|
893
|
+
m = re.match(r"^#{1,3}\s+(.+?)\s*#*\s*$", line)
|
|
894
|
+
if m:
|
|
895
|
+
title = " ".join(m.group(1).split())
|
|
896
|
+
if title and title.lower() not in seen:
|
|
897
|
+
seen.add(title.lower())
|
|
898
|
+
headings.append(title)
|
|
899
|
+
if len(headings) >= max_headings:
|
|
900
|
+
break
|
|
901
|
+
return headings
|
|
902
|
+
|
|
903
|
+
|
|
826
904
|
def _truncate_skill_body(text, max_chars, skill_name):
|
|
827
|
-
"""Truncate overly long SKILL.md cleanly on a line boundary with MCP
|
|
905
|
+
"""Truncate overly long SKILL.md cleanly on a line boundary with omitted section outline and MCP hint."""
|
|
828
906
|
if len(text) <= max_chars:
|
|
829
907
|
return text, False
|
|
830
|
-
|
|
908
|
+
|
|
909
|
+
total_lines = text.count("\n") + 1
|
|
910
|
+
|
|
911
|
+
def _build_notice(snippet_text):
|
|
912
|
+
shown_lines = snippet_text.count("\n") + 1
|
|
913
|
+
tail = text[len(snippet_text):]
|
|
914
|
+
omitted = _extract_markdown_headings(tail, max_headings=10)
|
|
915
|
+
if omitted:
|
|
916
|
+
parts = []
|
|
917
|
+
h_len = 0
|
|
918
|
+
for h in omitted:
|
|
919
|
+
add_len = len(h) + (2 if parts else 0)
|
|
920
|
+
if h_len + add_len > 250 and parts:
|
|
921
|
+
parts.append("...")
|
|
922
|
+
break
|
|
923
|
+
parts.append(h)
|
|
924
|
+
h_len += add_len
|
|
925
|
+
headings_str = ", ".join(parts)
|
|
926
|
+
return (
|
|
927
|
+
f"\n\n[... truncated at line {shown_lines}/{total_lines} ({len(snippet_text)}/{len(text)} chars) — "
|
|
928
|
+
f"OMITTED SECTIONS: {headings_str}. Call MCP load_skill(name=\"{skill_name}\", section=\"<heading>\") "
|
|
929
|
+
f"or load_skill(name=\"{skill_name}\", start_line={shown_lines + 1}) before executing omitted steps ...]"
|
|
930
|
+
)
|
|
931
|
+
return (
|
|
932
|
+
f"\n\n[... truncated at line {shown_lines}/{total_lines} ({len(snippet_text)}/{len(text)} chars); "
|
|
933
|
+
f"call MCP load_skill(name=\"{skill_name}\", start_line={shown_lines + 1}) if remaining sections are needed ...]"
|
|
934
|
+
)
|
|
935
|
+
|
|
936
|
+
cutoff = max(max_chars - 560, min(max_chars // 2, 500))
|
|
831
937
|
snippet = text[:cutoff]
|
|
832
938
|
last_nl = snippet.rfind("\n")
|
|
833
939
|
if last_nl > cutoff * 0.6:
|
|
834
940
|
snippet = snippet[:last_nl]
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
941
|
+
|
|
942
|
+
notice = _build_notice(snippet)
|
|
943
|
+
if len(snippet) + len(notice) > max_chars:
|
|
944
|
+
excess = len(snippet) + len(notice) - max_chars
|
|
945
|
+
new_cut = max(0, len(snippet) - excess)
|
|
946
|
+
snippet = snippet[:new_cut]
|
|
947
|
+
last_nl = snippet.rfind("\n")
|
|
948
|
+
if last_nl > new_cut * 0.5:
|
|
949
|
+
snippet = snippet[:last_nl]
|
|
950
|
+
notice = _build_notice(snippet)
|
|
951
|
+
if len(snippet) + len(notice) > max_chars:
|
|
952
|
+
snippet = snippet[: max(0, max_chars - len(notice))]
|
|
953
|
+
notice = _build_notice(snippet)
|
|
954
|
+
if len(snippet) + len(notice) > max_chars:
|
|
955
|
+
return (snippet + notice)[:max_chars], True
|
|
956
|
+
|
|
839
957
|
return snippet + notice, True
|
|
840
958
|
|
|
841
959
|
|
|
@@ -935,8 +1053,15 @@ def route_prompt(
|
|
|
935
1053
|
if raw_text:
|
|
936
1054
|
budget = min(max_single_chars, remaining_chars)
|
|
937
1055
|
body_text, truncated = _truncate_skill_body(raw_text, budget, cand["name"])
|
|
1056
|
+
rt_dir = cand.get("runtime_dir")
|
|
1057
|
+
effective_dir = (
|
|
1058
|
+
Path(rt_dir).resolve()
|
|
1059
|
+
if rt_dir and Path(rt_dir).exists()
|
|
1060
|
+
else skill_dir
|
|
1061
|
+
)
|
|
938
1062
|
item = dict(cand)
|
|
939
|
-
item["skill_dir"] = str(
|
|
1063
|
+
item["skill_dir"] = str(effective_dir)
|
|
1064
|
+
item["archive_dir"] = str(skill_dir)
|
|
940
1065
|
item["skill_md_path"] = str(md_path)
|
|
941
1066
|
item["content"] = body_text
|
|
942
1067
|
item["truncated"] = truncated
|
|
@@ -946,7 +1071,13 @@ def route_prompt(
|
|
|
946
1071
|
if len(pointer_items) < max_pointers:
|
|
947
1072
|
item = dict(cand)
|
|
948
1073
|
_, skill_dir = _resolve_skill_md_for_candidate(cand, archive_dir, base_dir)
|
|
949
|
-
|
|
1074
|
+
rt_dir = cand.get("runtime_dir")
|
|
1075
|
+
if rt_dir and Path(rt_dir).exists():
|
|
1076
|
+
item["skill_dir"] = str(Path(rt_dir).resolve())
|
|
1077
|
+
item["archive_dir"] = str(skill_dir) if skill_dir else cand.get("resolved_path", "")
|
|
1078
|
+
else:
|
|
1079
|
+
item["skill_dir"] = str(skill_dir) if skill_dir else cand.get("resolved_path", "")
|
|
1080
|
+
item["skill_md_path"] = str(Path(skill_dir) / "SKILL.md") if skill_dir else cand.get("archived_path", "")
|
|
950
1081
|
pointer_items.append(item)
|
|
951
1082
|
|
|
952
1083
|
if not inline_items and not pointer_items:
|
|
@@ -982,7 +1113,9 @@ def route_prompt(
|
|
|
982
1113
|
for item in pointer_items:
|
|
983
1114
|
desc = item.get("description", "").strip()
|
|
984
1115
|
short_desc = desc[:130] + "..." if len(desc) > 130 else desc
|
|
985
|
-
skill_md_loc =
|
|
1116
|
+
skill_md_loc = item.get("skill_md_path") or (
|
|
1117
|
+
str(Path(item["skill_dir"]) / "SKILL.md") if item.get("skill_dir") else item.get("archived_path", "")
|
|
1118
|
+
)
|
|
986
1119
|
sections.append(
|
|
987
1120
|
f'- **{item["name"]}** [{item["category"]}]: {short_desc} (`{skill_md_loc}`)'
|
|
988
1121
|
)
|