name: eval
# Structural eval: a skill package must be complete and within limits before
# it can be merged. Complements sanitize.yml (content gate).
on:
  pull_request:
  push:
    branches: [main]

jobs:
  structure:
    runs-on: windows
    steps:
      - uses: actions/checkout@v4
      - name: Validate package structure
        shell: python
        run: |
          import json, os, sys

          errors = []
          REQUIRED = [
              "SKILL.md",
              "manifest.json",
              "references/profile.md",
              "references/tasks.md",
              "references/skills.md",
              "references/tools.md",
          ]
          for f in REQUIRED:
              if not os.path.isfile(f):
                  errors.append(f"missing required file: {f}")

          if os.path.isfile("SKILL.md"):
              lines = open("SKILL.md", encoding="utf-8").read().splitlines()
              if len(lines) > 300:
                  errors.append(f"SKILL.md too long: {len(lines)} lines (max 300)")
              if not lines or lines[0].strip() != "---":
                  errors.append("SKILL.md missing frontmatter")

          if os.path.isfile("manifest.json"):
              m = json.load(open("manifest.json", encoding="utf-8"))
              for key in ("name", "version", "layer", "ids", "sources", "attribution"):
                  if key not in m:
                      errors.append(f"manifest.json missing key: {key}")

          if errors:
              print("EVAL FAILED:")
              print("\n".join(f"- {e}" for e in errors))
              sys.exit(1)
          print("eval: package structure OK.")
