Buckets:
| """Shared helpers: SKILL.md frontmatter parsing and CJK ratio.""" | |
| import re, yaml | |
| _Loader = getattr(yaml, "CSafeLoader", yaml.SafeLoader) | |
| FM = re.compile(r"\A?---\s*\r?\n(.*?)\r?\n---\s*(?:\r?\n|\Z)", re.S) | |
| CJK = re.compile(r"[-ヿ㐀-䶿一-鿿가-]") | |
| def parse_skill_md(text): | |
| """Returns (frontmatter_valid, name, description, frontmatter_raw, body).""" | |
| if not text: return False, None, None, None, text or "" | |
| m = FM.match(text) | |
| if not m: return False, None, None, None, text | |
| raw, body = m.group(1), text[m.end():] | |
| try: | |
| d = yaml.load(raw, Loader=_Loader) # libyaml C loader: ~10x faster than pure-Python safe_load | |
| if not isinstance(d, dict): raise ValueError | |
| name, desc = d.get("name"), d.get("description") | |
| return bool(name and desc), None if name is None else str(name), None if desc is None else str(desc), raw, body | |
| except Exception: # lenient fallback for invalid YAML (common: unquoted colons) | |
| g = lambda k: (re.search(rf"^{k}:\s*(.+)$", raw, re.M) or [None, None])[1] | |
| return False, g("name"), g("description"), raw, body | |
| def cjk_ratio(text): | |
| return len(CJK.findall(text)) / max(len(text), 1) if text else 0.0 | |
Xet Storage Details
- Size:
- 1.21 kB
- Xet hash:
- f8a2e3c88e09a8d2226931e592f016c7f06cd67aa8227046b3f6e7df9dde9de2
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.