@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/mcp_server.py
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
"""Skill Vault Read-Only MCP Stdio Server.
|
|
3
3
|
|
|
4
|
-
Provides
|
|
5
|
-
(supporting both newline-delimited JSON and Content-Length framing) so coding
|
|
6
|
-
|
|
4
|
+
Provides three read-only fallback tools (`search_skills`, `list_skills`, `load_skill`) over
|
|
5
|
+
JSON-RPC 2.0 (supporting both newline-delimited JSON and Content-Length framing) so coding
|
|
6
|
+
agents can discover and inspect cold-storage skills mid-turn without shell approvals or L1 mutations.
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
9
|
import argparse
|
|
10
10
|
import json
|
|
11
11
|
import os
|
|
12
12
|
from pathlib import Path
|
|
13
|
+
import re
|
|
13
14
|
import sys
|
|
14
15
|
|
|
15
16
|
SCRIPT_DIR = Path(__file__).resolve().parent
|
|
@@ -19,7 +20,7 @@ if str(SCRIPT_DIR) not in sys.path:
|
|
|
19
20
|
import skill_router # noqa: E402
|
|
20
21
|
|
|
21
22
|
SERVER_NAME = "skill-vault"
|
|
22
|
-
SERVER_VERSION = "2.
|
|
23
|
+
SERVER_VERSION = "2.1.0"
|
|
23
24
|
MAX_READ_BYTES = 102400 # 100 KB safety cap per tool call
|
|
24
25
|
|
|
25
26
|
TOOLS_SPEC = [
|
|
@@ -27,7 +28,7 @@ TOOLS_SPEC = [
|
|
|
27
28
|
"name": "search_skills",
|
|
28
29
|
"description": (
|
|
29
30
|
"Search vaulted cold-storage skills by keyword, intent, or category. "
|
|
30
|
-
"Pass an empty query to list all
|
|
31
|
+
"Pass an empty query to list categories and counts, or use list_skills to list all skill names in one call."
|
|
31
32
|
),
|
|
32
33
|
"inputSchema": {
|
|
33
34
|
"type": "object",
|
|
@@ -45,6 +46,11 @@ TOOLS_SPEC = [
|
|
|
45
46
|
"description": "Maximum results to return (default 8, max 25).",
|
|
46
47
|
"default": 8,
|
|
47
48
|
},
|
|
49
|
+
"offset": {
|
|
50
|
+
"type": "integer",
|
|
51
|
+
"description": "Pagination offset into sorted results (default 0).",
|
|
52
|
+
"default": 0,
|
|
53
|
+
},
|
|
48
54
|
},
|
|
49
55
|
"required": ["query"],
|
|
50
56
|
},
|
|
@@ -55,11 +61,41 @@ TOOLS_SPEC = [
|
|
|
55
61
|
"openWorldHint": False,
|
|
56
62
|
},
|
|
57
63
|
},
|
|
64
|
+
{
|
|
65
|
+
"name": "list_skills",
|
|
66
|
+
"description": (
|
|
67
|
+
"List all vaulted cold-storage skill names grouped by category in a single compact call "
|
|
68
|
+
"(no 25-item limit). Optionally filter by category or include short 1-line descriptions."
|
|
69
|
+
),
|
|
70
|
+
"inputSchema": {
|
|
71
|
+
"type": "object",
|
|
72
|
+
"properties": {
|
|
73
|
+
"category": {
|
|
74
|
+
"type": "string",
|
|
75
|
+
"description": "Optional category name filter (case-insensitive).",
|
|
76
|
+
},
|
|
77
|
+
"include_descriptions": {
|
|
78
|
+
"type": "boolean",
|
|
79
|
+
"description": (
|
|
80
|
+
"Include truncated 1-line descriptions per skill "
|
|
81
|
+
"(default false for compact names-only output)."
|
|
82
|
+
),
|
|
83
|
+
"default": False,
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
"annotations": {
|
|
88
|
+
"readOnlyHint": True,
|
|
89
|
+
"destructiveHint": False,
|
|
90
|
+
"idempotentHint": True,
|
|
91
|
+
"openWorldHint": False,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
58
94
|
{
|
|
59
95
|
"name": "load_skill",
|
|
60
96
|
"description": (
|
|
61
|
-
"Load
|
|
62
|
-
"companion file (e.g. 'references/guide.md') inside that skill's directory."
|
|
97
|
+
"Load SKILL.md instructions (full, by heading section, or by line range) for a vaulted skill, "
|
|
98
|
+
"or read a specific companion file (e.g. 'references/guide.md') inside that skill's directory."
|
|
63
99
|
),
|
|
64
100
|
"inputSchema": {
|
|
65
101
|
"type": "object",
|
|
@@ -72,6 +108,18 @@ TOOLS_SPEC = [
|
|
|
72
108
|
"type": "string",
|
|
73
109
|
"description": "Optional relative path to a companion file inside the skill folder.",
|
|
74
110
|
},
|
|
111
|
+
"section": {
|
|
112
|
+
"type": "string",
|
|
113
|
+
"description": "Optional Markdown heading name/substring to extract a single section from SKILL.md (case-insensitive).",
|
|
114
|
+
},
|
|
115
|
+
"start_line": {
|
|
116
|
+
"type": "integer",
|
|
117
|
+
"description": "Optional 1-based start line to read a line range from SKILL.md or a companion file.",
|
|
118
|
+
},
|
|
119
|
+
"end_line": {
|
|
120
|
+
"type": "integer",
|
|
121
|
+
"description": "Optional 1-based inclusive end line for line-range reads.",
|
|
122
|
+
},
|
|
75
123
|
},
|
|
76
124
|
"required": ["name"],
|
|
77
125
|
},
|
|
@@ -148,10 +196,40 @@ def _resolve_base_and_archive(cli_base=None):
|
|
|
148
196
|
return fallback, fallback / "skill_archive"
|
|
149
197
|
|
|
150
198
|
|
|
199
|
+
_INDEX_CACHE = {}
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def _file_sig(path):
|
|
203
|
+
try:
|
|
204
|
+
st = Path(path).stat()
|
|
205
|
+
return (st.st_mtime_ns, st.st_size)
|
|
206
|
+
except OSError:
|
|
207
|
+
return None
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def clear_index_cache():
|
|
211
|
+
"""Clear the in-memory search index cache."""
|
|
212
|
+
_INDEX_CACHE.clear()
|
|
213
|
+
|
|
214
|
+
|
|
151
215
|
def _load_index(base_dir, archive_dir):
|
|
152
|
-
|
|
216
|
+
archive_path = Path(archive_dir).resolve()
|
|
217
|
+
cache_key = str(archive_path)
|
|
218
|
+
if not archive_path.exists():
|
|
219
|
+
_INDEX_CACHE.pop(cache_key, None)
|
|
153
220
|
return {"doc_count": 0, "skills": [], "df": {}, "avg_len": {}}
|
|
154
|
-
|
|
221
|
+
|
|
222
|
+
index_sig = _file_sig(archive_path / "search_index.json")
|
|
223
|
+
manifest_sig = _file_sig(archive_path / "backup_manifest.json")
|
|
224
|
+
cached = _INDEX_CACHE.get(cache_key)
|
|
225
|
+
if cached is not None and cached[0] == index_sig and cached[1] == manifest_sig:
|
|
226
|
+
return cached[2]
|
|
227
|
+
|
|
228
|
+
data = skill_router.load_or_build_index(archive_dir=archive_path, base_dir=base_dir)
|
|
229
|
+
new_index_sig = _file_sig(archive_path / "search_index.json")
|
|
230
|
+
new_manifest_sig = _file_sig(archive_path / "backup_manifest.json")
|
|
231
|
+
_INDEX_CACHE[cache_key] = (new_index_sig, new_manifest_sig, data)
|
|
232
|
+
return data
|
|
155
233
|
|
|
156
234
|
|
|
157
235
|
def _tool_result(text, is_error=False):
|
|
@@ -161,6 +239,78 @@ def _tool_result(text, is_error=False):
|
|
|
161
239
|
}
|
|
162
240
|
|
|
163
241
|
|
|
242
|
+
def _short_desc(text, max_len=160):
|
|
243
|
+
collapsed = " ".join(str(text or "").split())
|
|
244
|
+
if len(collapsed) <= max_len:
|
|
245
|
+
return collapsed
|
|
246
|
+
return collapsed[: max_len - 3].rstrip() + "..."
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def _handle_list_skills(args, base_dir, archive_dir):
|
|
250
|
+
category = args.get("category")
|
|
251
|
+
if category is not None:
|
|
252
|
+
category = str(category).strip() or None
|
|
253
|
+
|
|
254
|
+
raw_inc = args.get("include_descriptions", False)
|
|
255
|
+
if isinstance(raw_inc, bool):
|
|
256
|
+
include_descriptions = raw_inc
|
|
257
|
+
elif isinstance(raw_inc, str):
|
|
258
|
+
include_descriptions = raw_inc.strip().lower() in ("true", "1", "yes")
|
|
259
|
+
else:
|
|
260
|
+
include_descriptions = bool(raw_inc)
|
|
261
|
+
|
|
262
|
+
index_data = _load_index(base_dir, archive_dir)
|
|
263
|
+
skills = index_data.get("skills", [])
|
|
264
|
+
|
|
265
|
+
grouped = {}
|
|
266
|
+
for entry in skills:
|
|
267
|
+
cat = entry.get("category") or "General & Utility Skills"
|
|
268
|
+
grouped.setdefault(cat, []).append(entry)
|
|
269
|
+
|
|
270
|
+
all_categories = sorted(grouped.keys(), key=str.lower)
|
|
271
|
+
|
|
272
|
+
if category:
|
|
273
|
+
cat_lower = category.lower()
|
|
274
|
+
filtered_items = [
|
|
275
|
+
(cat, items) for cat, items in grouped.items() if cat.lower() == cat_lower
|
|
276
|
+
]
|
|
277
|
+
else:
|
|
278
|
+
filtered_items = list(grouped.items())
|
|
279
|
+
|
|
280
|
+
filtered_items.sort(key=lambda kv: (-len(kv[1]), kv[0].lower()))
|
|
281
|
+
|
|
282
|
+
cat_blocks = []
|
|
283
|
+
total_matching = 0
|
|
284
|
+
for cat, items in filtered_items:
|
|
285
|
+
sorted_entries = sorted(items, key=lambda s: s.get("name", "").lower())
|
|
286
|
+
total_matching += len(sorted_entries)
|
|
287
|
+
if include_descriptions:
|
|
288
|
+
skill_list = [
|
|
289
|
+
{
|
|
290
|
+
"name": s["name"],
|
|
291
|
+
"description": _short_desc(s.get("description", "")),
|
|
292
|
+
}
|
|
293
|
+
for s in sorted_entries
|
|
294
|
+
]
|
|
295
|
+
else:
|
|
296
|
+
skill_list = [s["name"] for s in sorted_entries]
|
|
297
|
+
cat_blocks.append({
|
|
298
|
+
"category": cat,
|
|
299
|
+
"count": len(sorted_entries),
|
|
300
|
+
"skills": skill_list,
|
|
301
|
+
})
|
|
302
|
+
|
|
303
|
+
payload = {
|
|
304
|
+
"total_skills": total_matching,
|
|
305
|
+
"category_count": len(cat_blocks),
|
|
306
|
+
"categories": cat_blocks,
|
|
307
|
+
}
|
|
308
|
+
if category and total_matching == 0:
|
|
309
|
+
payload["available_categories"] = all_categories
|
|
310
|
+
|
|
311
|
+
return _tool_result(json.dumps(payload, indent=2, ensure_ascii=False))
|
|
312
|
+
|
|
313
|
+
|
|
164
314
|
def _handle_search_skills(args, base_dir, archive_dir):
|
|
165
315
|
query = str(args.get("query") or "")
|
|
166
316
|
category = args.get("category")
|
|
@@ -171,6 +321,10 @@ def _handle_search_skills(args, base_dir, archive_dir):
|
|
|
171
321
|
except (TypeError, ValueError):
|
|
172
322
|
limit = 8
|
|
173
323
|
limit = max(1, min(limit, 25))
|
|
324
|
+
try:
|
|
325
|
+
offset = max(0, int(args.get("offset", 0)))
|
|
326
|
+
except (TypeError, ValueError):
|
|
327
|
+
offset = 0
|
|
174
328
|
|
|
175
329
|
index_data = _load_index(base_dir, archive_dir)
|
|
176
330
|
skills = index_data.get("skills", [])
|
|
@@ -189,36 +343,55 @@ def _handle_search_skills(args, base_dir, archive_dir):
|
|
|
189
343
|
}
|
|
190
344
|
return _tool_result(json.dumps(summary, indent=2, ensure_ascii=False))
|
|
191
345
|
|
|
192
|
-
|
|
346
|
+
all_matches = skill_router.search_index(
|
|
193
347
|
index_data=index_data,
|
|
194
348
|
query=query,
|
|
195
349
|
category=category,
|
|
196
|
-
limit=
|
|
350
|
+
limit=None,
|
|
197
351
|
)
|
|
198
352
|
|
|
199
|
-
# Substring fallback for partial fragments (e.g., "proto") if
|
|
200
|
-
if not
|
|
353
|
+
# Substring fallback for partial fragments (e.g., "proto") if BM25 returned nothing
|
|
354
|
+
if not all_matches and query.strip():
|
|
201
355
|
q_lower = query.strip().lower()
|
|
356
|
+
word_pat = re.compile(rf"(?<![a-z0-9]){re.escape(q_lower)}(?![a-z0-9])")
|
|
202
357
|
fallback = []
|
|
203
358
|
for entry in skills:
|
|
204
|
-
|
|
359
|
+
entry_cat = entry.get("category", "General & Utility Skills")
|
|
360
|
+
if category and entry_cat.lower() != category.lower():
|
|
361
|
+
continue
|
|
362
|
+
name_l = entry.get("name", "").lower()
|
|
363
|
+
aliases_l = [a.lower() for a in entry.get("aliases", [entry.get("name", "")])]
|
|
364
|
+
desc_l = entry.get("description", "").lower()
|
|
365
|
+
cat_l = entry_cat.lower()
|
|
366
|
+
|
|
367
|
+
if q_lower == name_l or q_lower in aliases_l:
|
|
368
|
+
score = 10.0
|
|
369
|
+
elif q_lower in name_l or any(q_lower in a for a in aliases_l):
|
|
370
|
+
score = 5.0
|
|
371
|
+
elif word_pat.search(desc_l):
|
|
372
|
+
score = 2.0
|
|
373
|
+
elif q_lower in desc_l or q_lower in cat_l:
|
|
374
|
+
score = 1.0
|
|
375
|
+
else:
|
|
205
376
|
continue
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
377
|
+
|
|
378
|
+
fallback.append({
|
|
379
|
+
"name": entry["name"],
|
|
380
|
+
"category": entry_cat,
|
|
381
|
+
"score": score,
|
|
382
|
+
"description": entry.get("description", ""),
|
|
383
|
+
"companion_files": entry.get("companion_files", []),
|
|
384
|
+
})
|
|
385
|
+
fallback.sort(key=lambda m: (-m["score"], m["name"].lower()))
|
|
386
|
+
all_matches = fallback
|
|
387
|
+
|
|
388
|
+
total_matches = len(all_matches)
|
|
389
|
+
matches = all_matches[offset : offset + limit]
|
|
219
390
|
|
|
220
391
|
payload = {
|
|
221
392
|
"query": query,
|
|
393
|
+
"total_matches": total_matches,
|
|
394
|
+
"offset": offset,
|
|
222
395
|
"count": len(matches),
|
|
223
396
|
"results": [
|
|
224
397
|
{
|
|
@@ -248,6 +421,76 @@ def _find_skill_entry(index_data, skill_name):
|
|
|
248
421
|
return None
|
|
249
422
|
|
|
250
423
|
|
|
424
|
+
def _extract_markdown_section(content, section_query):
|
|
425
|
+
"""Extract a single Markdown heading section outside fenced code blocks."""
|
|
426
|
+
lines = content.splitlines()
|
|
427
|
+
headings = []
|
|
428
|
+
in_fence = False
|
|
429
|
+
fence_marker = None
|
|
430
|
+
for idx, line in enumerate(lines):
|
|
431
|
+
stripped = line.lstrip()
|
|
432
|
+
if stripped.startswith("```") or stripped.startswith("~~~"):
|
|
433
|
+
marker = stripped[:3]
|
|
434
|
+
if not in_fence:
|
|
435
|
+
in_fence = True
|
|
436
|
+
fence_marker = marker
|
|
437
|
+
elif marker == fence_marker:
|
|
438
|
+
in_fence = False
|
|
439
|
+
fence_marker = None
|
|
440
|
+
continue
|
|
441
|
+
if in_fence:
|
|
442
|
+
continue
|
|
443
|
+
m = re.match(r"^(#{1,6})\s+(.+?)\s*#*\s*$", line)
|
|
444
|
+
if m:
|
|
445
|
+
level = len(m.group(1))
|
|
446
|
+
title = " ".join(m.group(2).split())
|
|
447
|
+
if title:
|
|
448
|
+
headings.append((idx, level, title))
|
|
449
|
+
|
|
450
|
+
all_titles = [t for _, _, t in headings]
|
|
451
|
+
q_lower = section_query.strip().lower()
|
|
452
|
+
matched = None
|
|
453
|
+
for idx, level, title in headings:
|
|
454
|
+
if title.lower() == q_lower:
|
|
455
|
+
matched = (idx, level, title)
|
|
456
|
+
break
|
|
457
|
+
if matched is None:
|
|
458
|
+
for idx, level, title in headings:
|
|
459
|
+
if q_lower in title.lower():
|
|
460
|
+
matched = (idx, level, title)
|
|
461
|
+
break
|
|
462
|
+
if matched is None:
|
|
463
|
+
return None, 0, 0, None, all_titles
|
|
464
|
+
|
|
465
|
+
start_idx, m_level, m_title = matched
|
|
466
|
+
end_idx = len(lines)
|
|
467
|
+
for idx, level, _ in headings:
|
|
468
|
+
if idx > start_idx and level <= m_level:
|
|
469
|
+
end_idx = idx
|
|
470
|
+
break
|
|
471
|
+
section_text = "\n".join(lines[start_idx:end_idx])
|
|
472
|
+
return section_text, start_idx + 1, end_idx, m_title, all_titles
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
def _slice_lines(content, start_line=None, end_line=None):
|
|
476
|
+
"""Slice 1-based inclusive line range from text content."""
|
|
477
|
+
lines = content.splitlines()
|
|
478
|
+
total = len(lines)
|
|
479
|
+
s = max(1, start_line if start_line is not None else 1)
|
|
480
|
+
e = min(total, end_line) if end_line is not None else total
|
|
481
|
+
if total == 0 or s > total:
|
|
482
|
+
return "", s, min(e, total), total
|
|
483
|
+
return "\n".join(lines[s - 1 : e]), s, e, total
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
def _cap_utf8_text(text, max_bytes=MAX_READ_BYTES):
|
|
487
|
+
raw = text.encode("utf-8", errors="replace")
|
|
488
|
+
if len(raw) <= max_bytes:
|
|
489
|
+
return text
|
|
490
|
+
capped = raw[:max_bytes].decode("utf-8", errors="replace")
|
|
491
|
+
return capped + f"\n\n[... truncated at {max_bytes} bytes ...]"
|
|
492
|
+
|
|
493
|
+
|
|
251
494
|
def _handle_load_skill(args, base_dir, archive_dir):
|
|
252
495
|
skill_name = str(args.get("name") or "").strip()
|
|
253
496
|
if not skill_name:
|
|
@@ -257,6 +500,31 @@ def _handle_load_skill(args, base_dir, archive_dir):
|
|
|
257
500
|
if rel_file is not None:
|
|
258
501
|
rel_file = str(rel_file).strip() or None
|
|
259
502
|
|
|
503
|
+
section = args.get("section")
|
|
504
|
+
if section is not None:
|
|
505
|
+
section = str(section).strip() or None
|
|
506
|
+
|
|
507
|
+
start_line = None
|
|
508
|
+
if args.get("start_line") is not None and args.get("start_line") != "":
|
|
509
|
+
try:
|
|
510
|
+
start_line = int(args["start_line"])
|
|
511
|
+
except (TypeError, ValueError):
|
|
512
|
+
return _tool_result("Error: 'start_line' must be a positive integer.", is_error=True)
|
|
513
|
+
if start_line < 1:
|
|
514
|
+
return _tool_result("Error: 'start_line' must be a positive integer.", is_error=True)
|
|
515
|
+
|
|
516
|
+
end_line = None
|
|
517
|
+
if args.get("end_line") is not None and args.get("end_line") != "":
|
|
518
|
+
try:
|
|
519
|
+
end_line = int(args["end_line"])
|
|
520
|
+
except (TypeError, ValueError):
|
|
521
|
+
return _tool_result("Error: 'end_line' must be a positive integer.", is_error=True)
|
|
522
|
+
if end_line < 1:
|
|
523
|
+
return _tool_result("Error: 'end_line' must be a positive integer.", is_error=True)
|
|
524
|
+
|
|
525
|
+
if start_line is not None and end_line is not None and end_line < start_line:
|
|
526
|
+
return _tool_result("Error: 'end_line' must be >= 'start_line'.", is_error=True)
|
|
527
|
+
|
|
260
528
|
index_data = _load_index(base_dir, archive_dir)
|
|
261
529
|
entry = _find_skill_entry(index_data, skill_name)
|
|
262
530
|
if not entry:
|
|
@@ -266,71 +534,118 @@ def _handle_load_skill(args, base_dir, archive_dir):
|
|
|
266
534
|
is_error=True,
|
|
267
535
|
)
|
|
268
536
|
|
|
269
|
-
|
|
537
|
+
archive_skill_dir = None
|
|
270
538
|
if entry.get("resolved_path") and Path(entry["resolved_path"]).exists():
|
|
271
|
-
|
|
539
|
+
archive_skill_dir = Path(entry["resolved_path"]).resolve()
|
|
272
540
|
elif entry.get("archived_path"):
|
|
273
541
|
cand = skill_router._resolve_archived_skill_dir(base_dir, archive_dir, entry["archived_path"])
|
|
274
542
|
if cand.exists():
|
|
275
|
-
|
|
543
|
+
archive_skill_dir = cand.resolve()
|
|
276
544
|
|
|
277
|
-
if not
|
|
545
|
+
if not archive_skill_dir or not archive_skill_dir.exists():
|
|
278
546
|
return _tool_result(
|
|
279
547
|
f"Error: Archived directory for skill '{skill_name}' does not exist on disk.",
|
|
280
548
|
is_error=True,
|
|
281
549
|
)
|
|
282
550
|
|
|
551
|
+
runtime_dir = None
|
|
552
|
+
if entry.get("runtime_dir"):
|
|
553
|
+
cand_rt = Path(entry["runtime_dir"])
|
|
554
|
+
if cand_rt.exists() and cand_rt.is_dir():
|
|
555
|
+
runtime_dir = cand_rt.resolve()
|
|
556
|
+
|
|
283
557
|
if rel_file:
|
|
284
|
-
# Strict path traversal check
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
)
|
|
292
|
-
target = (skill_dir / req_path).resolve()
|
|
293
|
-
if skill_dir not in target.parents:
|
|
294
|
-
return _tool_result(
|
|
295
|
-
"Error: Path traversal denied; companion file must reside inside the skill directory.",
|
|
296
|
-
is_error=True,
|
|
297
|
-
)
|
|
298
|
-
except Exception as exc:
|
|
299
|
-
return _tool_result(f"Error resolving path: {exc}", is_error=True)
|
|
558
|
+
# Strict path traversal check across candidate roots (runtime_dir then archive_skill_dir)
|
|
559
|
+
req_path = Path(rel_file)
|
|
560
|
+
if req_path.is_absolute():
|
|
561
|
+
return _tool_result(
|
|
562
|
+
"Error: Absolute paths are not allowed; provide a relative path inside the skill directory.",
|
|
563
|
+
is_error=True,
|
|
564
|
+
)
|
|
300
565
|
|
|
301
|
-
if
|
|
566
|
+
roots = [runtime_dir, archive_skill_dir] if runtime_dir and runtime_dir != archive_skill_dir else [archive_skill_dir]
|
|
567
|
+
target = None
|
|
568
|
+
for root_dir in roots:
|
|
569
|
+
try:
|
|
570
|
+
cand_target = (root_dir / req_path).resolve()
|
|
571
|
+
if root_dir not in cand_target.parents:
|
|
572
|
+
return _tool_result(
|
|
573
|
+
"Error: Path traversal denied; companion file must reside inside the skill directory.",
|
|
574
|
+
is_error=True,
|
|
575
|
+
)
|
|
576
|
+
except Exception as exc:
|
|
577
|
+
return _tool_result(f"Error resolving path: {exc}", is_error=True)
|
|
578
|
+
if cand_target.exists() and cand_target.is_file():
|
|
579
|
+
target = cand_target
|
|
580
|
+
break
|
|
581
|
+
|
|
582
|
+
if target is None:
|
|
302
583
|
return _tool_result(
|
|
303
584
|
f"Error: Companion file '{rel_file}' not found inside '{entry['name']}'.",
|
|
304
585
|
is_error=True,
|
|
305
586
|
)
|
|
306
587
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
text
|
|
312
|
-
|
|
588
|
+
lines_info = ""
|
|
589
|
+
if start_line is not None or end_line is not None:
|
|
590
|
+
full_text = target.read_text(encoding="utf-8", errors="replace")
|
|
591
|
+
text, s, e, total_lines = _slice_lines(full_text, start_line, end_line)
|
|
592
|
+
text = _cap_utf8_text(text)
|
|
593
|
+
lines_info = f"Lines: {s}-{e} of {total_lines}\n"
|
|
594
|
+
else:
|
|
595
|
+
raw = target.read_bytes()
|
|
596
|
+
truncated = len(raw) > MAX_READ_BYTES
|
|
597
|
+
text = raw[:MAX_READ_BYTES].decode("utf-8", errors="replace")
|
|
598
|
+
if truncated:
|
|
599
|
+
text += f"\n\n[... truncated at {MAX_READ_BYTES} bytes ...]"
|
|
600
|
+
header = f"# {entry['name']} :: {rel_file}\n{lines_info}\n"
|
|
313
601
|
return _tool_result(header + text)
|
|
314
602
|
|
|
315
|
-
skill_md =
|
|
603
|
+
skill_md = archive_skill_dir / "SKILL.md"
|
|
316
604
|
if not skill_md.exists():
|
|
317
605
|
return _tool_result(
|
|
318
606
|
f"Error: SKILL.md missing for skill '{entry['name']}'.",
|
|
319
607
|
is_error=True,
|
|
320
608
|
)
|
|
321
609
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
610
|
+
section_line = ""
|
|
611
|
+
if section is not None or start_line is not None or end_line is not None:
|
|
612
|
+
full_text = skill_md.read_text(encoding="utf-8", errors="replace")
|
|
613
|
+
total_lines = len(full_text.splitlines())
|
|
614
|
+
if section is not None:
|
|
615
|
+
sec_text, s, e, m_title, all_titles = _extract_markdown_section(full_text, section)
|
|
616
|
+
if sec_text is None:
|
|
617
|
+
avail = ", ".join(all_titles[:30]) if all_titles else "(none)"
|
|
618
|
+
return _tool_result(
|
|
619
|
+
f"Error: Section '{section}' not found in '{entry['name']}'. Available headings: {avail}",
|
|
620
|
+
is_error=True,
|
|
621
|
+
)
|
|
622
|
+
content = _cap_utf8_text(sec_text)
|
|
623
|
+
section_line = f"Section: {m_title} (lines {s}-{e} of {total_lines})\n"
|
|
624
|
+
else:
|
|
625
|
+
sliced, s, e, total_lines = _slice_lines(full_text, start_line, end_line)
|
|
626
|
+
content = _cap_utf8_text(sliced)
|
|
627
|
+
section_line = f"Lines: {s}-{e} of {total_lines}\n"
|
|
628
|
+
else:
|
|
629
|
+
raw = skill_md.read_bytes()
|
|
630
|
+
truncated = len(raw) > MAX_READ_BYTES
|
|
631
|
+
content = raw[:MAX_READ_BYTES].decode("utf-8", errors="replace")
|
|
632
|
+
if truncated:
|
|
633
|
+
content += f"\n\n[... truncated at {MAX_READ_BYTES} bytes ...]"
|
|
327
634
|
|
|
635
|
+
effective_dir = runtime_dir or archive_skill_dir
|
|
636
|
+
extra_rt = (
|
|
637
|
+
f"Archive Directory: {archive_skill_dir}\n"
|
|
638
|
+
if runtime_dir and runtime_dir != archive_skill_dir
|
|
639
|
+
else ""
|
|
640
|
+
)
|
|
328
641
|
companions = entry.get("companion_files", [])
|
|
329
642
|
comp_line = ", ".join(companions) if companions else "(none)"
|
|
330
643
|
header = (
|
|
331
644
|
f"Skill: {entry['name']}\n"
|
|
332
645
|
f"Category: {entry.get('category', 'General & Utility Skills')}\n"
|
|
333
|
-
f"Directory: {
|
|
646
|
+
f"Directory: {effective_dir}\n"
|
|
647
|
+
f"{extra_rt}"
|
|
648
|
+
f"{section_line}"
|
|
334
649
|
f"Companion Files: {comp_line}\n"
|
|
335
650
|
f"---\n"
|
|
336
651
|
)
|
|
@@ -405,6 +720,8 @@ def _dispatch_request(msg, base_dir, archive_dir):
|
|
|
405
720
|
args = params.get("arguments") or {}
|
|
406
721
|
if tool_name == "search_skills":
|
|
407
722
|
res = _handle_search_skills(args, base_dir, archive_dir)
|
|
723
|
+
elif tool_name == "list_skills":
|
|
724
|
+
res = _handle_list_skills(args, base_dir, archive_dir)
|
|
408
725
|
elif tool_name == "load_skill":
|
|
409
726
|
res = _handle_load_skill(args, base_dir, archive_dir)
|
|
410
727
|
else:
|