pleme-doc-gen 0.1.6

Rust replacement for the M0 Python _gen-patterns.py + _gen-docs.py scripts in pleme-io/actions. Walks every action.yml + emits substrate's patterns-full.nix + per-action README.md + root catalog. Per the NO-SHELL prime directive.
//! Category classifier β€” mirrors the _gen-patterns.py CATEGORY_MAP.
//! Kept as a static const table so misclassifications are easy to
//! audit + fix in one place.

const MAP: &[(&str, &str)] = &[
    ("cargo", "rust"),
    ("rust-", "rust"),
    ("npm-", "npm"),
    ("python-", "python"),
    ("helm-", "helm"),
    ("caixa-", "caixa"),
    ("gem-", "ruby"),
    ("ansible-", "ansible"),
    ("go-", "language"),
    ("gradle-", "language"),
    ("maven-", "language"),
    ("dotnet-", "language"),
    ("swift-", "language"),
    ("xcodebuild", "language"),
    ("mix-", "language"),
    ("hex-", "language"),
    ("zig-", "language"),
    ("golangci-", "language"),
    ("goreleaser", "language"),
    ("wasm-", "language"),
    ("aws-", "cloud"),
    ("gcp-", "cloud"),
    ("cloudflare-", "cloud"),
    ("azure-", "cloud"),
    ("vercel-", "cloud"),
    ("netlify-", "cloud"),
    ("render-", "cloud"),
    ("railway-", "cloud"),
    ("heroku-", "cloud"),
    ("doctl-", "cloud"),
    ("fly-", "cloud"),
    ("datadog-", "observability"),
    ("grafana-", "observability"),
    ("honeycomb-", "observability"),
    ("prometheus-", "observability"),
    ("sentry-", "observability"),
    ("otel-", "observability"),
    ("loki-", "observability"),
    ("pyroscope-", "observability"),
    ("security-", "security"),
    ("sbom-", "security"),
    ("license-header", "security"),
    ("license-finder", "security"),
    ("provenance-", "security"),
    ("image-scan", "security"),
    ("cosign-", "security"),
    ("tfsec", "security"),
    ("checkov", "security"),
    ("bandit", "security"),
    ("gosec", "security"),
    ("conftest", "security"),
    ("kics-", "security"),
    ("snyk-", "security"),
    ("vault-", "security"),
    ("gh-secrets-", "security"),
    ("slsa-", "security"),
    ("cyclonedx-", "security"),
    ("secrets-scan", "security"),
    ("docker-", "container"),
    ("ko-", "container"),
    ("oci-", "container"),
    ("podman-", "container"),
    ("buildah-", "container"),
    ("skopeo-", "container"),
    ("crane-", "container"),
    ("buildkit-", "container"),
    ("kubectl-", "k8s"),
    ("flux-", "k8s"),
    ("argocd-", "k8s"),
    ("kustomize-", "k8s"),
    ("k8s-", "k8s"),
    ("velero-", "k8s"),
    ("helmfile-", "k8s"),
    ("tanka-", "k8s"),
    ("helm-deploy", "k8s"),
    ("helm-oci-publish", "helm"),
    ("terraform-", "iac"),
    ("pulumi-", "iac"),
    ("iac-", "iac"),
    ("db-", "db"),
    ("atlas-", "db"),
    ("prisma-", "db"),
    ("flyway-", "db"),
    ("sqitch-", "db"),
    ("playwright-", "frontend"),
    ("cypress-", "frontend"),
    ("storybook-", "frontend"),
    ("percy-", "frontend"),
    ("lighthouse-", "frontend"),
    ("fastlane-", "mobile"),
    ("app-store-", "mobile"),
    ("eas-", "mobile"),
    ("flutter-", "mobile"),
    ("slack-", "comms"),
    ("discord-", "comms"),
    ("email-", "comms"),
    ("pagerduty-", "comms"),
    ("matrix-", "comms"),
    ("teams-", "comms"),
    ("telegram-", "comms"),
    ("twilio-", "comms"),
    ("mattermost-", "comms"),
    ("nats-", "messaging"),
    ("kafka-", "messaging"),
    ("mkdocs-", "docs"),
    ("docusaurus-", "docs"),
    ("mdbook-", "docs"),
    ("hugo-", "docs"),
    ("vitepress-", "docs"),
    ("zola-", "docs"),
    ("changelog-", "docs"),
    ("docs-", "docs"),
    ("api-spec-", "docs"),
    ("toc-", "docs"),
    ("mutation-", "quality"),
    ("benchmark-", "quality"),
    ("sonarqube-", "quality"),
    ("pa11y-", "quality"),
    ("dependency-", "sdlc"),
    ("nix-flake-update", "sdlc"),
    ("pr-comment", "sdlc"),
    ("issue-create", "sdlc"),
    ("status-badge", "sdlc"),
    ("dependabot-", "sdlc"),
    ("changesets", "release-mgmt"),
    ("semantic-", "release-mgmt"),
    ("release-please", "release-mgmt"),
    ("release-promote", "release-mgmt"),
    ("yank-version", "release-mgmt"),
    ("onboard-", "sdlc"),
    ("akeyless-", "akeyless"),
    ("wireguard-", "networking"),
    ("tailscale-", "networking"),
    ("artifact-fetch", "storage"),
    ("s3-mirror", "storage"),
    ("gcs-sync", "storage"),
    ("restic-", "backup"),
    ("temporal-", "workflow"),
    ("airflow-", "workflow"),
    ("devcontainer-", "devx"),
    ("pre-commit-", "devx"),
    ("json-schema-", "data"),
    ("yaml-lint", "data"),
    ("nix-", "nix"),
    ("nix-flake-check", "validation"),
    ("branch-protect-", "hygiene"),
    ("codeowners-", "hygiene"),
    ("stale-", "hygiene"),
    ("gh-team-", "hygiene"),
    ("tlisp-lint", "validation"),
    ("action-shell-lint", "meta"),
    ("adoption-audit", "meta"),
    ("defaction-render", "meta"),
    ("tatara-script", "runtime"),
    ("git-", "git"),
    ("gh-", "gh"),
    ("derive-version-", "gh"),
    ("detect-repo-type", "dispatch"),
    ("spec-watch", "spec"),
    ("caixa-detect", "dispatch"),
    ("rust-gate", "validation"),
    ("npm-gate", "validation"),
    ("python-gate", "validation"),
    ("typecheck-", "validation"),
    ("rust-cross-", "build"),
    ("rust-workspace-publish", "publish"),
    ("rust-workspace-bump", "bump"),
    ("substrate-bump", "bump"),
];

pub fn categorize(name: &str) -> &'static str {
    // Longest-prefix match
    let mut best_match: Option<(usize, &'static str)> = None;
    for (prefix, cat) in MAP {
        if name == *prefix || name.starts_with(prefix) {
            if best_match.map_or(true, |(len, _)| prefix.len() > len) {
                best_match = Some((prefix.len(), cat));
            }
        }
    }
    best_match.map_or("uncategorized", |(_, c)| c)
}

pub fn intro(category: &str) -> &'static str {
    match category {
        "rust" => "πŸ¦€ Rust ecosystem",
        "npm" => "πŸ“¦ npm ecosystem",
        "python" => "🐍 Python ecosystem",
        "helm" => "β›΅ Helm β€” chart packaging + deployment",
        "caixa" => "πŸ“¦ caixa β€” canonical SDLC primitive",
        "language" => "🌐 Multi-language (Go/Java/.NET/Swift/Elixir/Zig/WASM)",
        "cloud" => "☁️ Cloud providers",
        "k8s" => "☸️ Kubernetes β€” apply / deploy / reconcile / wait",
        "iac" => "πŸ—οΈ IaC β€” Terraform / Pulumi",
        "db" => "πŸ—„οΈ Database β€” migrations + backups",
        "frontend" => "πŸ–₯️ Frontend testing + deployment",
        "mobile" => "πŸ“± Mobile β€” Fastlane / App Store / EAS / Flutter",
        "observability" => "πŸ“Š Observability β€” markers / metrics / logs / profiles",
        "security" => "πŸ”’ Security β€” vuln scans / SBOM / signing / secrets",
        "comms" => "πŸ’¬ Notifications across N channels",
        "messaging" => "πŸ“‘ Message brokers β€” NATS / Kafka",
        "docs" => "πŸ“š Documentation generation + publishing",
        "quality" => "βœ… Code quality β€” mutation / benchmark / SonarQube / accessibility",
        "sdlc" => "πŸ”„ SDLC automation",
        "release-mgmt" => "πŸ“¦ Release management β€” Changesets / semantic-release",
        "akeyless" => "πŸ”‘ Akeyless secret management",
        "networking" => "🌐 Networking β€” WireGuard / Tailscale",
        "storage" => "πŸ’Ύ Storage β€” S3 / GCS / cross-workflow",
        "backup" => "πŸ›‘οΈ Backup β€” restic",
        "workflow" => "βš™οΈ Workflow orchestration β€” Temporal / Airflow",
        "devx" => "πŸ› οΈ Developer experience",
        "data" => "πŸ“‹ Data validation",
        "nix" => "❄️ Nix β€” build / cache push",
        "hygiene" => "🧹 Repo hygiene",
        "validation" => "🚦 Validation β€” per-language gates + universal lints",
        "meta" => "πŸͺž Meta β€” directive enforcement + audit + renderer",
        "runtime" => "βš™οΈ Runtime β€” tatara-script",
        "git" => "πŸ“ Git operations",
        "gh" => "πŸ™ GitHub API",
        "dispatch" => "🚏 Repo-type dispatch",
        "spec" => "πŸ“ Spec watching",
        "container" => "πŸ‹ Container build (Docker / ko / buildah / podman)",
        "build" => "πŸ”¨ Build β€” cross-compile / OCI / Ansible",
        "bump" => "⬆️ Version bumping",
        "publish" => "πŸ“€ Registry publishing",
        "ruby" => "πŸ’Ž Ruby gem",
        "ansible" => "πŸ…°οΈ Ansible Collection",
        _ => "πŸ”§ Uncategorized β€” needs a home",
    }
}