Skip to content

armgit / chums

Public Imported from GitHub
0

Talk to Claude Code and Codex agents from an Apple Watch and an iPhone. Each agent is a character on the watch.

1.9 KB
Raw Blame
#!/bin/zsh
# Writes app/ChumsWatch/HubConfig.swift from ~/.chums/config.json: the hub's public address, the watch's token and a
# build stamp. bin/chums-install runs it. The generated file is git-ignored (it holds the token).
ROOT="${0:A:h:h}"
[[ -f ~/.chums/config.json ]] || { echo "no ~/.chums/config.json yet: start the hub once (bin/chums-hub), it writes one" >&2; exit 1 }
python3 - "$ROOT" <<'EOF'
import json, os, subprocess, sys
root = sys.argv[1]
cfg = json.load(open(os.path.expanduser("~/.chums/config.json")))
# The watch reaches the Mac only through its public https address (bin/chums-tunnel, cfg "publicURL"): watchOS doesn't
# support apps reaching a home-network address, and probing one on other networks would hand the token to whoever has
# that address. 127.0.0.1 is for the Simulator (the app drops it on a real watch).
hosts = [h for h in (cfg.get('publicURL'), f"http://127.0.0.1:{cfg['port']}") if h]
if not cfg.get('publicURL'): print("no publicURL yet: run bin/chums-tunnel first, or the watch can only reach the Simulator's hub")
import datetime
build = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
out = os.path.join(root, "app/ChumsWatch/HubConfig.swift")
# it holds the watch's token: readable by this user only
with os.fdopen(os.open(out, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600), "w") as f:
    os.fchmod(f.fileno(), 0o600)
    f.write("// Generated by tools/gen-config.sh. Do not commit.\n")
    f.write("enum HubConfig {\n")
    f.write(f"    static let hosts = {json.dumps(hosts)}\n")
    f.write(f"    static let token = {json.dumps(cfg['watchToken'])}   // the watch's own token: the watch API only\n")
    f.write(f"    static let build = {json.dumps(build)}\n")
    # the watch's frame rate and memory in the hub's log every 30 s: for working on the app, off unless asked for
    f.write(f"    static let diagnostics = {'true' if cfg.get('diagnostics') else 'false'}\n")
    f.write("}\n")
print("wrote", out, hosts)
EOF