from __future__ import annotations
import sys
from pathlib import Path
import tiktoken
SKILL_NAMES = [
"ilo-language",
"ilo-builtins",
"ilo-errors",
"ilo-tools",
"ilo-engines",
"ilo-agent",
"ilo-examples",
"ilo-edit-loop",
]
PER_MODULE_LIMIT = 1000
TOTAL_LIMIT = 5000
def main() -> int:
enc = tiktoken.get_encoding("cl100k_base")
skills_dir = Path(__file__).resolve().parent.parent / "skills" / "ilo"
total = 0
failed = False
for name in SKILL_NAMES:
path = skills_dir / f"{name}.md"
if not path.exists():
print(f"ERROR: missing skill file: {path}", file=sys.stderr)
failed = True
continue
tokens = len(enc.encode(path.read_text()))
total += tokens
flag = " OVER" if tokens > PER_MODULE_LIMIT else ""
print(f" {name:<14} {tokens:5d} tokens{flag}")
if tokens > PER_MODULE_LIMIT:
failed = True
print(f" {'TOTAL':<14} {total:5d} tokens")
if total > TOTAL_LIMIT:
print(
f"ERROR: total {total} exceeds aggregate budget {TOTAL_LIMIT}",
file=sys.stderr,
)
failed = True
return 1 if failed else 0
if __name__ == "__main__":
sys.exit(main())