# /etc/caddy/Caddyfile — Direct Per-Repository Install Directory Routing (HTTP/3 + Precompressed Brotli-11)
{
    servers {
        protocols h1 h2 h3
    }
}

www.hyperstitionstud.io {
    redir https://hyperstitionstud.io{uri} permanent
}

hyperstitionstud.io {
    encode zstd gzip

    header {
        Alt-Svc "h3=\":443\"; ma=2592000"
        Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"
        X-Content-Type-Options "nosniff"
        Referrer-Policy "strict-origin-when-cross-origin"
        -Server
    }

    @immutable_media path *.pdf *.png *.mp3 *.graphml *.gexf *.canvas *.woff2
    header @immutable_media Cache-Control "public, max-age=86400, stale-while-revalidate=604800"

    @html_js path *.html *.js *.json
    header @html_js Cache-Control "public, max-age=300, stale-while-revalidate=86400"

    # 1. Repo Install Dir: encyclopedia-knowledge-graph -> https://hyperstitionstud.io/graph/*
    handle_path /graph/* {
        root * /var/www/hyperstitionstud.io/repos/encyclopedia-knowledge-graph
        file_server {
            precompressed br gzip
        }
    }
    redir /graph /graph/ permanent

    # 2. Repo Install Dir: technocapital-singularity-zoology -> /encyclopedia/*, /zoology/* & sibling PDF target
    handle_path /encyclopedia/* {
        root * /var/www/hyperstitionstud.io/repos/technocapital-singularity-zoology/encyclopedia
        file_server {
            precompressed br gzip
        }
    }
    handle_path /technocapital-singularity-zoology/* {
        root * /var/www/hyperstitionstud.io/repos/technocapital-singularity-zoology
        file_server {
            precompressed br gzip
        }
    }
    handle_path /zoology/* {
        root * /var/www/hyperstitionstud.io/repos/technocapital-singularity-zoology
        file_server {
            precompressed br gzip
        }
    }

    # 3. Repo Install Dir: ingglish-hyperdope-gematria -> /archive/*
    handle_path /archive/* {
        root * /var/www/hyperstitionstud.io/repos/ingglish-hyperdope-gematria/ingglish-aq-archive
        file_server {
            precompressed br gzip
        }
    }

    # 4. Repo Install Dir: haiperdohp-jemaytreeah -> /calc/* (Confluence of hyperdope-ci-build & hyperdope-gematria)
    handle_path /calc/* {
        root * /var/www/hyperstitionstud.io/repos/haiperdohp-jemaytreeah
        file_server {
            precompressed br gzip
        }
    }
    redir /calc /calc/ permanent

    # 5. Repo Install Dir: ingglish-hyperdope-ci -> /ci/* (4-Gate CI Audit & Onboarding PDF)
    handle_path /ci/* {
        root * /var/www/hyperstitionstud.io/repos/ingglish-hyperdope-ci
        file_server {
            precompressed br gzip
        }
    }
    redir /ci /ci/ permanent

    # 6. Stateless Read-Only Model Context Protocol (MCP) Streamable HTTP Endpoint -> /mcp & /mcp/*
    @mcp_route path /mcp /mcp/*
    handle @mcp_route {
        reverse_proxy 127.0.0.1:8095
    }

    # 7. Repo Install Dir: hyperstitionstudio-core -> /schemas/*, /learn/*, /gallery/* & Root Portal Homepage (/)
    handle_path /schemas/* {
        root * /var/www/hyperstitionstud.io/repos/hyperstitionstudio-core/schemas
        file_server {
            precompressed br gzip
        }
    }
    handle {
        root * /var/www/hyperstitionstud.io/repos/hyperstitionstudio-core/site
        file_server {
            precompressed br gzip
        }
    }
}
