Skip to content

An agent organization structured as a company — 15+ departments, 125+ skills, each independently installable, citing the standards and regulators that settle the question. Runs in Claude Code and ChatGPT.

9.0 KB
Raw Blame
#!/usr/bin/env python3
"""Generate the GitHub social preview card.

The card states the department and skill counts, so it drifts exactly the way the README used
to (D19). It is generated from the same tree walk instead of hand-drawn, and `--check` compares
the committed HTML against freshly generated output — a text comparison, so CI verifies it
without needing a browser.

  python3 scripts/build-social-card.py            regenerate HTML, then render the PNG
  python3 scripts/build-social-card.py --check    fail if the HTML is stale (CI)
  python3 scripts/build-social-card.py --html     regenerate HTML only, skip rendering

Rendering needs Chromium. The PNG is a build artifact committed for convenience: GitHub wants a
file upload, not a URL, so a copy in the repository is what you re-download when re-uploading it.
"""
import glob
import os
import shutil
import subprocess
import sys

HTML_OUT = "docs/assets/social-card.html"
PNG_OUT = "docs/assets/social-preview.png"
WIDTH, HEIGHT = 1280, 640  # GitHub's recommended social preview size; rendered at 2x

# Same glob as build-readme.py. Both walk the tree directly rather than sharing state, so the
# card and the README cannot report different numbers for the same commit.
def source_total():
    """Distinct sources in the catalog, read from the catalog rather than typed."""
    import importlib.util
    spec = importlib.util.spec_from_file_location("check_sources", "scripts/check-sources.py")
    module = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(module)
    return len({entry["id"] for _, entry in module.load()})


def counts():
    depts = sorted(
        os.path.basename(os.path.dirname(os.path.dirname(m)))
        for m in glob.glob("plugins/*/.claude-plugin/plugin.json")
    )
    skills = len(glob.glob("plugins/*/skills/*/SKILL.md"))
    return len(depts), skills


TEMPLATE = """<meta charset="utf-8">
<!-- GENERATED by scripts/build-social-card.py — edit that, not this file. -->
<style>
  /* Fixed {W}x{H} canvas. Every block is absolutely positioned: on a canvas of known size
     that is deterministic, where flex sizing silently failed to place the footer row. */
  * {{ margin:0; padding:0; box-sizing:border-box; }}
  html,body {{ width:{W}px; height:{H}px; overflow:hidden; }}
  body {{
    background:#0B0E14;
    font-family:"Liberation Sans","Helvetica Neue",Arial,sans-serif;
    color:#E6EDF3; position:relative;
  }}
  .grid {{
    position:absolute; inset:0;
    background-image:
      linear-gradient(rgba(255,255,255,.03) 1px, transparent 1px),
      linear-gradient(90deg, rgba(255,255,255,.03) 1px, transparent 1px);
    background-size:40px 40px;
  }}
  .glow {{
    position:absolute; width:820px; height:820px; right:-260px; top:-260px; border-radius:50%;
    background:radial-gradient(circle, rgba(217,119,87,.17) 0%, rgba(217,119,87,0) 65%);
  }}
  .bar {{
    position:absolute; left:0; top:0; width:8px; height:100%;
    background:linear-gradient(180deg,#D97757 0%,#C2663F 46%,#33404F 100%);
  }}
  .eyebrow {{
    position:absolute; left:80px; top:62px;
    font-family:"DejaVu Sans Mono",monospace;
    font-size:20px; letter-spacing:.14em; color:#69768A; text-transform:uppercase;
  }}
  h1 {{
    position:absolute; left:76px; top:96px;
    font-size:122px; font-weight:700; letter-spacing:-.048em; line-height:1; color:#fff;
  }}
  .tagline {{
    position:absolute; left:80px; top:246px;
    font-size:36px; color:#9FB0C3; letter-spacing:-.014em;
  }}
  .chip {{
    position:absolute; left:80px; top:318px;
    background:#151A22; border:1px solid #283040; border-radius:12px; padding:18px 26px;
    font-family:"DejaVu Sans Mono",monospace; font-size:26px; color:#B7C4D2;
  }}
  .chip .at {{ color:#D97757; font-weight:700; }}
  .rule {{
    position:absolute; left:80px; top:498px; width:604px; height:1px;
    background:linear-gradient(90deg,#2A3341 0%, rgba(42,51,65,0) 100%);
  }}
  .meta {{
    position:absolute; left:80px; top:534px;
    font-size:20px; letter-spacing:.12em; text-transform:uppercase; color:#7D8B9C;
    white-space:nowrap;
  }}
  .meta b {{ color:#E6EDF3; font-weight:700; }}
  .meta .sep {{ color:#3D4756; padding:0 13px; }}
  .chart {{ position:absolute; right:96px; top:150px; }}
</style>

<div class="grid"></div>
<div class="glow"></div>
<div class="bar"></div>

<div class="eyebrow">cbrock84 / headcount</div>
<h1>headcount</h1>
<div class="tagline">Add a department, not a prompt.</div>
<div class="chip">/plugin install security<span class="at">@headcount</span></div>

<div class="rule"></div>
<div class="meta">
  <b>{DEPTS}</b> departments <span class="sep">/</span>
  <b>{SKILLS}</b> skills <span class="sep">/</span>
  <b>{SOURCES}</b> cited sources <span class="sep">/</span>
  MIT <span class="sep">/</span> Claude Code &amp; ChatGPT
</div>

<!-- The chart is the organization's actual shape: one chief executive, departments beneath, and
     the reviewer-class departments (accent outline) hanging off a spine that runs from the top,
     because they report to the chief executive rather than into the function they oversee. -->
<div class="chart">
<svg width="342" height="342" viewBox="0 0 342 342" fill="none">
  <g stroke="#3A4553" stroke-width="2">
    <path d="M171 70 L171 104"/>
    <path d="M48 104 L294 104"/>
    <path d="M48 104 L48 136"/><path d="M122 104 L122 136"/>
    <path d="M220 104 L220 136"/><path d="M294 104 L294 136"/>
    <path d="M171 104 L171 228"/>
    <path d="M72 228 L270 228"/>
    <path d="M72 228 L72 258"/><path d="M171 228 L171 258"/>
    <path d="M270 228 L270 258"/>
  </g>
  <rect x="117" y="24" width="108" height="46" rx="10" fill="#D97757"/>
  <g fill="#31251F">
    <rect x="137" y="40" width="46" height="5" rx="2.5"/>
    <rect x="137" y="52" width="30" height="5" rx="2.5"/>
  </g>
  <g fill="#1A2029" stroke="#3A4553" stroke-width="2">
    <rect x="18" y="136" width="60" height="60" rx="9"/>
    <rect x="92" y="136" width="60" height="60" rx="9"/>
    <rect x="190" y="136" width="60" height="60" rx="9"/>
    <rect x="264" y="136" width="60" height="60" rx="9"/>
    <rect x="141" y="258" width="60" height="54" rx="9"/>
  </g>
  <g fill="#1A2029" stroke="#D97757" stroke-width="2">
    <rect x="42" y="258" width="60" height="54" rx="9"/>
    <rect x="240" y="258" width="60" height="54" rx="9"/>
  </g>
  <g fill="#3A4553">
    <rect x="30" y="152" width="36" height="5" rx="2.5"/><rect x="30" y="164" width="24" height="5" rx="2.5"/>
    <rect x="104" y="152" width="36" height="5" rx="2.5"/><rect x="104" y="164" width="24" height="5" rx="2.5"/>
    <rect x="202" y="152" width="36" height="5" rx="2.5"/><rect x="202" y="164" width="24" height="5" rx="2.5"/>
    <rect x="276" y="152" width="36" height="5" rx="2.5"/><rect x="276" y="164" width="24" height="5" rx="2.5"/>
    <rect x="153" y="274" width="36" height="5" rx="2.5"/><rect x="153" y="286" width="24" height="5" rx="2.5"/>
  </g>
  <g fill="#8A5039">
    <rect x="54" y="274" width="36" height="5" rx="2.5"/><rect x="54" y="286" width="24" height="5" rx="2.5"/>
    <rect x="252" y="274" width="36" height="5" rx="2.5"/><rect x="252" y="286" width="24" height="5" rx="2.5"/>
  </g>
</svg>
</div>
"""


def render_html():
    depts, skills = counts()
    return TEMPLATE.format(W=WIDTH, H=HEIGHT, DEPTS=depts, SKILLS=skills, SOURCES=source_total())


def find_chromium():
    """Playwright's bundled Chromium first, then anything on PATH."""
    pw = os.environ.get("PLAYWRIGHT_BROWSERS_PATH", "/opt/pw-browsers")
    candidates = [
        os.path.join(pw, "chromium"),
        *(shutil.which(n) for n in
          ("chromium", "chromium-browser", "google-chrome", "google-chrome-stable")),
    ]
    return next((c for c in candidates if c and os.path.exists(c)), None)


def main():
    content = render_html()

    if "--check" in sys.argv:
        current = open(HTML_OUT, encoding="utf-8").read() if os.path.exists(HTML_OUT) else ""
        if current != content:
            print(f"  {HTML_OUT} is stale — run: python3 scripts/build-social-card.py")
            return 1
        print("social card is current")
        return 0

    os.makedirs(os.path.dirname(HTML_OUT), exist_ok=True)
    open(HTML_OUT, "w", encoding="utf-8").write(content)
    depts, skills = counts()
    print(f"{HTML_OUT} regenerated — {depts} departments, {skills} skills")

    if "--html" in sys.argv:
        return 0

    chrome = find_chromium()
    if not chrome:
        print("  no Chromium found — HTML written, PNG not rendered.")
        print("  install Chromium, or open the HTML and screenshot it at "
              f"{WIDTH}x{HEIGHT}.")
        return 0

    subprocess.run([
        chrome, "--headless", "--no-sandbox", "--disable-gpu", "--hide-scrollbars",
        "--force-device-scale-factor=2", f"--window-size={WIDTH},{HEIGHT}",
        f"--screenshot={PNG_OUT}", HTML_OUT,
    ], check=True, capture_output=True)
    kb = os.path.getsize(PNG_OUT) // 1024
    print(f"{PNG_OUT} rendered — {WIDTH*2}x{HEIGHT*2}, {kb} KB "
          f"(GitHub's limit is 1 MB; upload at Settings -> General -> Social preview)")
    return 0


if __name__ == "__main__":
    sys.exit(main())