# Hero TV on the Touch Bar (for an agent or a person on the Mac)

Goal: play Infinite TV stations from herorunai.com on this Mac's Touch Bar. Native AppKit app, no browser.
Works on any Touch Bar MacBook Pro (2016 to 2021, Intel or Apple Silicon). macOS 12 or newer.

## Fastest path (prebuilt universal binary)

    curl -fsSL https://herorunai.com/downloads/HeroTVBar -o ~/HeroTVBar && chmod +x ~/HeroTVBar && ~/HeroTVBar

- A small window opens ("Hero TV · Touch Bar"). While that window is frontmost, the Touch Bar is a full-width
  video strip playing the live house stations, sound on. Click another app and the bar goes back to normal;
  click the window again and the show returns. That is how macOS Touch Bar works, not a bug.
- Keys with the window focused: space = pause/play, m = mute, n = next station, q = quit.
- The window has a chat box: type what should happen next and press Enter for a free steer (waits in line), or
  ⌘Enter for a paid "next beat" steer ($0.25 of $HERO from your key, your name on the clip). "Write it with AI"
  turns a rough idea into a full scene in the box first. Paste your Hero key in the key field once (Save key), or
  start the app with `HERO_RUN_KEY=hr_live_... ~/HeroTVBar`. No key? "Buy a key by card" ($5 to $200) opens Stripe in the
  browser; the app watches the payment and fills the new key in by itself. All sales final, no chargebacks.
- 🎤 Talk: say what should happen next; Apple's speech recognition (on-device when the Mac supports it) puts it
  in the box. First use asks for Microphone and Speech Recognition permission. Then Enter or ⌘Enter as usual.
- Stations made in the "Touch Bar strip" format (21:9, subjects spread left to right, action in the middle band)
  play first. Open your own in that format at https://herorunai.com/infinite-tv (Format → Touch Bar 21:9).
- Pin one station: `~/HeroTVBar 4b23dc4595` (SpongeBob vs Goku). Several: `~/HeroTVBar <id> <id> ...`
  Station ids are at https://herorunai.com/api/tv (field `id`).
- The binary is unsigned. Downloaded with curl it runs straight away. If it was downloaded through a browser,
  clear the quarantine flag first: `xattr -d com.apple.quarantine ~/HeroTVBar`, or right-click → Open once.
- If macOS says it cannot open it, build from source instead (below); Xcode command line tools are enough.

## Build from source (about 20 seconds)

    curl -fsSL https://herorunai.com/downloads/HeroTVBar.swift -o ~/HeroTVBar.swift
    curl -fsSL https://herorunai.com/downloads/HeroTVBar-Info.plist -o ~/HeroTVBar-Info.plist
    swiftc -O -framework AppKit -framework AVFoundation -framework Speech -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __info_plist -Xlinker ~/HeroTVBar-Info.plist ~/HeroTVBar.swift -o ~/HeroTVBar
    ~/HeroTVBar

If `swiftc` is missing: `xcode-select --install`, then run the three lines again.

## What it does under the hood

- Reads `https://herorunai.com/api/tv` for live stations and `https://herorunai.com/api/tv/<id>` for clips.
- Plays clips in order through AVQueuePlayer into an NSTouchBar custom item (2170x60), cropped to fill.
- When fewer than 3 clips are queued it POSTs `https://herorunai.com/api/tv/<id>/tick`, which asks the station
  for the next clip. That clip is paid by the station's owner (house stations by Hero Run), not by this Mac.
- Polls every 5 seconds; reruns the last clip until a new one lands.

## Verify it is running

    pgrep -fl HeroTVBar          # a process
    lsof -p $(pgrep -f HeroTVBar | head -1) -i | grep -c ESTABLISHED   # streaming connections

Look at the Touch Bar: you should see the picture with the station title on the left and the current beat's
caption on the right. If the bar shows the normal controls, click the Hero TV window to bring it to the front.
