mgiovani/ai-arsenal / skills/anything-to-skill
anything-to-skill
VerifiedTurns a docs site, local folder, PDF or book, YouTube video, playlist or channel, or a topic into a source-grounded, token-efficient agent skill (hub SKILL.md, sectioned references, INDEX, evals), and can compact it into a lean expert skill. Use for "make a skill from these docs", "turn this channel into a skill". Not for a skill from your own description (use create-skill), improving one (use improve-skill) or finding third-party skills (use find-skills).
scripts/anything_to_skill/compact/swap.py
View on GitHubimport argparse
import json
import os
import shutil
import sys
from pathlib import Path
from anything_to_skill.compact import verify
from anything_to_skill.core.workspace import Workspace
from anything_to_skill.emit.verify import _skill_dir
def add_args(parser: argparse.ArgumentParser) -> None:
mode = parser.add_mutually_exclusive_group(required=True)
mode.add_argument(
'--apply',
action='store_true',
help='back up the emitted skill, then swap the compact one in',
)
mode.add_argument(
'--revert', action='store_true', help='restore the full skill saved by --apply'
)
parser.add_argument('--out', help='skill directory (default: the init --out answer)')
def _is_full(skill: Path) -> bool:
return (skill / 'references' / 'SOURCES.md').is_file()
def _swap_in(out: Path, source: Path) -> None:
"""Replace `out` by a copy of `source`: copy beside it, rename the old one away, rename in."""
stage = out.with_name(f'.{out.name}.a2s-compact-stage')
old = out.with_name(f'.{out.name}.a2s-compact-old')
for leftover in (stage, old):
if os.path.lexists(leftover):
raise FileExistsError(
f'{leftover} is left over from an interrupted run; inspect it, remove it, retry'
)
shutil.copytree(source, stage, symlinks=True)
moved = False
try:
if os.path.lexists(out):
out.rename(old)
moved = True
stage.rename(out)
except Exception:
shutil.rmtree(stage, ignore_errors=True)
if moved and not os.path.lexists(out):
old.rename(out)
raise
shutil.rmtree(old, ignore_errors=True)
def _fail(message: str) -> int:
print(f'compact: {message}', file=sys.stderr)
return 1
def _apply(ws: Workspace, out: Path) -> int:
if out.is_symlink():
return _fail(f'{out} is a symlink; pass the real directory with --out')
if os.path.lexists(ws.full_dir):
return _fail(f'{ws.full_dir} exists: already compacted. Run --revert first')
if not _is_full(out):
return _fail(
f'{out} is not a freshly emitted skill (no references/SOURCES.md); nothing changed'
)
report = verify.check(ws, ws.compact_dir)
if not report['ok']:
for r in report['findings']:
if r['severity'] == 'hard':
print(
f'HARD {r["file"]}:{r["line"] or "-"} {r["rule"]}: {r["message"]}',
file=sys.stderr,
)
return _fail('compact-verify has hard failures; nothing changed')
partial = ws.full_dir.with_name('full.partial')
shutil.rmtree(partial, ignore_errors=True)
shutil.copytree(out, partial, symlinks=True)
partial.rename(ws.full_dir)
_swap_in(out, ws.compact_dir)
print(
json.dumps(
{'skill': str(out), 'backup': str(ws.full_dir), 'tokens': report['tokens']}
)
)
return 0
def _revert(ws: Workspace, out: Path) -> int:
if not (ws.full_dir / 'SKILL.md').is_file() or not _is_full(ws.full_dir):
return _fail(f'no full skill saved in {ws.full_dir}; nothing to revert')
if out.is_symlink():
return _fail(f'{out} is a symlink; pass the real directory with --out')
if os.path.lexists(out) and _is_full(out):
return _fail(f'{out} already holds the full skill; nothing changed')
_swap_in(out, ws.full_dir)
shutil.rmtree(ws.full_dir)
print(json.dumps({'skill': str(out), 'restored': True}))
return 0
def run(ws: Workspace, args: argparse.Namespace) -> int:
"""`a2s.py compact --apply|--revert`: swap the verified compact skill in, or the full one back."""
out = _skill_dir(ws, args.out)
try:
return _apply(ws, out) if args.apply else _revert(ws, out)
except FileExistsError as exc:
return _fail(str(exc))
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| canvas-designanthropics/skillsCreate beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| docxanthropics/skillsUse this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| pdfanthropics/skillsUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| pptxanthropics/skillsUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |