Skip invalid skills CLI rows (#1553)
This commit is contained in:
@@ -52,6 +52,10 @@ def _preview_text(value, limit: int = 200) -> str:
|
||||
return text[:limit]
|
||||
|
||||
|
||||
def _skill_entries(skills):
|
||||
return [s for s in skills or [] if isinstance(s, dict)]
|
||||
|
||||
|
||||
def _summary(skill: dict) -> dict:
|
||||
return {
|
||||
"name": skill.get("name", ""),
|
||||
@@ -65,7 +69,7 @@ def _summary(skill: dict) -> dict:
|
||||
|
||||
|
||||
def cmd_list(args):
|
||||
out = _manager().load_all()
|
||||
out = _skill_entries(_manager().load_all())
|
||||
if args.category:
|
||||
out = [s for s in out if (s.get("category") or "general") == args.category]
|
||||
out.sort(key=lambda s: (-int(s.get("uses") or 0), s.get("name", "")))
|
||||
@@ -73,7 +77,7 @@ def cmd_list(args):
|
||||
|
||||
|
||||
def cmd_show(args):
|
||||
for s in _manager().load_all():
|
||||
for s in _skill_entries(_manager().load_all()):
|
||||
if s.get("name") == args.name:
|
||||
emit(s, args)
|
||||
return
|
||||
@@ -82,7 +86,7 @@ def cmd_show(args):
|
||||
|
||||
def cmd_categories(args):
|
||||
counts: dict[str, int] = {}
|
||||
for s in _manager().load_all():
|
||||
for s in _skill_entries(_manager().load_all()):
|
||||
c = s.get("category") or "general"
|
||||
counts[c] = counts.get(c, 0) + 1
|
||||
emit([{"category": c, "count": n} for c, n in sorted(counts.items())], args)
|
||||
@@ -91,7 +95,7 @@ def cmd_categories(args):
|
||||
def cmd_delete(args):
|
||||
# Locate the skill's directory and rm -rf it.
|
||||
skills_root = Path(_DATA_DIR) / "skills"
|
||||
for s in _manager().load_all():
|
||||
for s in _skill_entries(_manager().load_all()):
|
||||
if s.get("name") != args.name:
|
||||
continue
|
||||
cat = s.get("category") or "general"
|
||||
@@ -105,7 +109,7 @@ def cmd_delete(args):
|
||||
|
||||
|
||||
def cmd_export(args):
|
||||
for s in _manager().load_all():
|
||||
for s in _skill_entries(_manager().load_all()):
|
||||
if s.get("name") != args.name:
|
||||
continue
|
||||
cat = s.get("category") or "general"
|
||||
|
||||
Reference in New Issue
Block a user