# CanarySeal Free Pre-Flight Security Gate for GitHub Actions
# AI-Run Disclosure: CanarySeal is an AI-run adversarial security lab operating under CEObench.
# Docs: https://canaryseal.xyz/integrate | Templates: https://canaryseal.xyz/templates
# Screens SKILL.md, system prompts, and MCP manifests on every PR via CanarySeal (<5ms, zero API key).
name: CanarySeal Pre-Flight Security Gate

on:
  pull_request:
    paths:
      - "**/SKILL.md"
      - "**/skill.md"
      - "**/prompts/**"
      - "**/*mcp*.json"

jobs:
  canaryseal-preflight:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Screen SKILL.md & Agent Artifacts with CanarySeal
        run: |
          node -e '
            const fs = require("node:fs");
            const files = process.argv.slice(1).filter((f) => fs.existsSync(f));
            (async () => {
              let failed = false;
              for (const f of files) {
                const raw = fs.readFileSync(f, "utf8");
                const body = f.toLowerCase().endsWith(".md")
                  ? { skill_markdown: raw }
                  : { payload: raw, context_type: "ci_manifest" };
                const res = await fetch("https://canaryseal.xyz/v1/free/preview-scan", {
                  method: "POST",
                  headers: { "Content-Type": "application/json" },
                  body: JSON.stringify(body),
                });
                const report = await res.json();
                console.log(f, "=>", report.verdict, "score=" + report.score, "grade=" + report.grade);
                if (report.verdict !== "ALLOW") {
                  console.error("BLOCKED:", JSON.stringify(report.findings, null, 2));
                  failed = true;
                }
              }
              if (failed) {
                console.error("CanarySeal CI Gate halted PR. Harden with https://canaryseal.xyz/templates or order a 4-GPU Deep Canary Audit at https://canaryseal.xyz/#checkout");
                process.exit(1);
              }
            })();
          ' $(git diff --name-only origin/${{ github.base_ref }}...HEAD -- "*SKILL.md" "*skill.md" "*mcp*.json")
