Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

4.0 KB
Raw Blame
#!/usr/bin/env python3
"""Build the site's generated JS from source data. Run from the site/ directory.

  python3 scripts/build-data.py                regenerate manifests/variants/,
                                               manifests-data.js, models.js
  python3 scripts/build-data.py --sync-models  also scrape upstream's config.ts for
                                               model ids and merge them into
                                               models.json first (additive merge)

manifests/<slug>.hire.json is the SOURCE OF TRUTH for each role; per-provider
variants are derived (model/commandFlags carry over only on the role's native
provider). models.json is the source of truth for model SUGGESTIONS (a manifest
may use any model string; suggestions never validate).
"""
import json, os, re, sys, urllib.request

PROVIDERS = ['claude', 'antigravity', 'codex', 'cursor']
UPSTREAM_CONFIG = ('https://raw.githubusercontent.com/chaitanyagiri/munder-difflin/'
                   'main/src/renderer/src/store/config.ts')

# ── optional: sync models.json from upstream's hardcoded lists ──────────────
if '--sync-models' in sys.argv:
    src = urllib.request.urlopen(UPSTREAM_CONFIG, timeout=15).read().decode()
    def block(name):
        m = re.search(name + r'[^=]*=\s*\[(.*?)\];', src, re.S)
        return re.findall(r"id:\s*'([^']+)'", m.group(1)) if m else []
    models = json.load(open('models.json'))
    for prov, name in [('claude', 'AGENT_MODELS'), ('antigravity', 'ANTIGRAVITY_MODELS')]:
        ups = block(name)
        local_only = [m for m in models.get(prov, []) if m not in ups]
        models[prov] = ups + local_only
        print(f'{prov}: {len(ups)} upstream + {len(local_only)} local-only')
    import datetime
    models['updated'] = datetime.date.today().isoformat()
    with open('models.json', 'w') as out:
        json.dump(models, out, indent=2, ensure_ascii=False); out.write('\n')
    print('models.json synced from upstream config.ts')

# ── manifests → variants + manifests-data.js ────────────────────────────────
os.makedirs('manifests/variants', exist_ok=True)
idx = json.load(open('manifests/index.json'))
data = []
for f in idx:
    base = json.load(open(f'manifests/{f}'))
    base_provider = base.get('provider', 'claude')
    if base_provider == 'agy':
        base_provider = 'antigravity'
    slug = f.replace('.hire.json', '')
    variants = {}
    for p in PROVIDERS:
        v = dict(base)
        v['provider'] = p
        if p != base_provider:
            v.pop('model', None)
            v.pop('commandFlags', None)
        vfile = f'variants/{slug}.{p}.hire.json'
        with open(f'manifests/{vfile}', 'w') as out:
            json.dump(v, out, indent=2, ensure_ascii=False); out.write('\n')
        variants[p] = {'file': vfile, 'manifest': v}
    data.append({'file': f, 'manifest': base, 'baseProvider': base_provider, 'variants': variants})

with open('manifests-data.js', 'w') as out:
    out.write('/* AUTO-GENERATED by scripts/build-data.py — do not edit by hand.\n')
    out.write('   Also serves as the file:// fallback (fetch is blocked there). */\n')
    out.write('window.HIRES_DATA = ' + json.dumps(data, indent=2, ensure_ascii=False) + ';\n')

# ── models.json → models.js ─────────────────────────────────────────────────
models = json.load(open('models.json'))
models.pop('_comment', None)
with open('models.js', 'w') as out:
    out.write('/* AUTO-GENERATED from models.json by scripts/build-data.py — do not edit.\n')
    out.write('   Update models.json (or run build-data.py --sync-models), then rebuild. */\n')
    out.write('window.HIRE_MODELS = ' + json.dumps(models, indent=2, ensure_ascii=False) + ';\n')

print(f'{len(data)} roles × {len(PROVIDERS)} providers → manifests/variants/, manifests-data.js, models.js')