Skip to content

A complete AI agency at your fingertips - From frontend wizards to Reddit community ninjas, from whimsy injectors to reality checkers. Each agent is a specialized expert with personality, processes, and proven deliverables.

Shell
3.9 KB
Raw Blame
#!/usr/bin/env bash
#
# check-runbooks.sh — enforce that strategy/runbooks.json stays in sync with the
# real agent roster.
#
# strategy/runbooks.json is the machine-readable roster for the NEXUS scenario
# runbooks: the Agency Agents app reads it to turn a runbook into a one-click
# team deploy, mapping each roster slug to a catalog agent. If a slug there
# doesn't resolve to a real agent file, the app can't deploy that team — so this
# check fails the build when:
#   1. runbooks.json is not valid JSON, or an entry has empty required metadata
#      or no deployable agent roster
#   2. any roster `agents[]` slug does not match an agent .md filename stem
#   3. any `doc` path does not exist
#   4. a runbook `slug` is duplicated
#
# Slugs are the agent .md filename stem (the corpus id), e.g.
# engineering/engineering-frontend-developer.md -> "engineering-frontend-developer".
# Uses python3 (already required by check-agent-originality.sh) for JSON; no jq,
# so it runs the same on macOS and CI. Mirrors scripts/check-divisions.sh.
#
# Usage: ./scripts/check-runbooks.sh

set -euo pipefail
cd "$(dirname "$0")/.."

command -v python3 >/dev/null 2>&1 || {
  echo "ERROR: python3 is required for the runbooks check." >&2
  exit 2
}

python3 - <<'PYEOF'
import json, os, subprocess, sys

JSON = "strategy/runbooks.json"
errors = []

if not os.path.isfile(JSON):
    print(f"ERROR {JSON} not found"); sys.exit(1)

try:
    data = json.load(open(JSON))
except json.JSONDecodeError as e:
    print(f"ERROR {JSON} is not valid JSON: {e}"); sys.exit(1)

# Real slugs = filename stems of tracked agent .md files under division dirs.
NON_DIVISION = {"integrations", "examples", "strategy", "scripts", ".github"}
tracked = subprocess.check_output(["git", "ls-files", "*/*.md"]).decode().splitlines()
real = {os.path.basename(p)[:-3] for p in tracked if p.split("/")[0] not in NON_DIVISION}

runbooks = data.get("runbooks")
if not isinstance(runbooks, list) or not runbooks:
    print(f"ERROR {JSON} has no 'runbooks' array"); sys.exit(1)

seen_slugs = set()
total_refs = 0
for index, rb in enumerate(runbooks, 1):
    if not isinstance(rb, dict):
        errors.append(f"runbook #{index} must be an object")
        continue
    rid = rb.get("slug", "<no slug>")
    for field in ("slug", "title", "mode", "doc"):
        value = rb.get(field)
        if not isinstance(value, str) or not value.strip():
            errors.append(f"runbook '{rid}' requires a nonempty '{field}' string")
    if isinstance(rid, str):
        if rid in seen_slugs:
            errors.append(f"duplicate runbook slug '{rid}'")
        seen_slugs.add(rid)
    doc = rb.get("doc")
    if isinstance(doc, str) and doc.strip() and not os.path.isfile(doc):
        errors.append(f"runbook '{rid}': doc path does not exist: {doc}")
    roster = rb.get("roster")
    if not isinstance(roster, list) or not roster:
        errors.append(f"runbook '{rid}' requires a nonempty 'roster' array")
        continue
    for group_index, g in enumerate(roster, 1):
        if not isinstance(g, dict):
            errors.append(f"runbook '{rid}' / group #{group_index} must be an object")
            continue
        agents = g.get("agents")
        if not isinstance(agents, list) or not agents:
            errors.append(f"runbook '{rid}' / group '{g.get('group','?')}' requires a nonempty 'agents' array")
            continue
        for slug in agents:
            total_refs += 1
            if not isinstance(slug, str) or slug not in real:
                errors.append(f"runbook '{rid}' / group '{g.get('group','?')}': "
                              f"slug '{slug}' does not match any agent .md filename stem")

if errors:
    print(f"FAILED: {len(errors)} runbook consistency error(s). "
          f"strategy/runbooks.json must reference real agent slugs.\n")
    for e in errors:
        print(f"  ERROR {e}")
    sys.exit(1)

print(f"PASSED: {len(runbooks)} runbooks, {total_refs} agent slug references — "
      f"all resolve to real agent files.")
PYEOF