Notes on a Three-Button Remote
I recently built something a bit silly: a remote control for Douyin.
The requirement was simple. I wanted to lie on the sofa and watch Douyin on the TV. A phone works, but the TV has a bigger screen and better sound. A laptop works too, but holding one on the sofa feels wrong. My TV is connected to an Apple TV, and there’s an always-on Mac mini in the study, so at first I was just thinking about how to connect these things.
The obvious first attempt was iPhone AirPlay. I have an iPhone 13, and AirPlaying Douyin to the Apple TV works fine — until the phone gets hot, the stream starts to stutter, and the battery drains. At one point I seriously considered a wireless charging stand plus a cooling pad, turning the phone into a dedicated player.
Then the problem shifted from “how do I watch Douyin on the TV” to “how do I remotely control a phone that can’t move.”
Apple’s accessibility work goes far deeper than I expected. I tried Switch Control, then Voice Control. Voice Control even pointed at a theoretically viable path: the Mac plays the phrase “swipe up,” the iPhone hears it, and Voice Control operates Douyin. At that point it had gotten absurd — I started out wanting to skip one video, and now one computer was talking to a phone so the phone would swipe the screen.
I also considered XiaoAi, Xiaomi’s voice assistant. Voice is a natural fit here; saying “next” beats hunting for a remote. The path could work — XiaoAi hits a public endpoint, which lands on the Mac mini. But maintaining a Worker, tokens, and auth for three actions felt like too much, so I set it aside.
What actually simplified everything was noticing, much later than I should have, that Douyin has an official macOS app. The iPhone could drop out of the playback path entirely, and the Mac mini became the player, mirroring to the Apple TV.
flowchart LR
Mac["Mac mini<br/>Douyin.app"]
ATV["Apple TV"]
TV["Television"]
Mac -->|"AirPlay"| ATV
ATV --> TV
Now only one problem was left: from the sofa, how do I control the Mac mini in the study?
An Apple TV remote can’t control the Mac that’s mirroring to it. A wireless mouse works, but lying down and hunting for a cursor just to browse short videos is barely better. What I actually needed was three actions:
Previous
Play / Pause
Next
For just those three actions, the whole thing could be designed in ten minutes: three big buttons in a mobile web page, an HTTP server on the Mac mini, and a keyboard event per request. That’s probably the most sensible way to build a Douyin remote.
But I happened to be deep in Free4Chat at the time, so the three buttons ended up on a deliberately over-engineered path.
Bring an Agent into the Room
Free4Chat started years ago as an anonymous WebRTC chat room; I wrote about its history in Four Evolutions of a WebRTC Chat Room. It later grew agents. These days, when I use Free4Chat, I usually don’t open the chat page to ask an agent a question — I open a Room and bring in an agent running on one of my machines. Same here.
The Mac mini runs free4chat-agent, a local Agent Runtime that joins the Room and receives work. I created a Task and picked Codex as the Harness — the agent environment that does the actual work. The requirement was one sentence: Douyin is already installed on this Mac; build me a way to control previous, next, and play/pause from a phone. After that, I mostly let it work on its own.
Capabilities, not integrations
The agent was in the Room and had the Task, but it still couldn’t touch Douyin.
Codex first figured out how to control the macOS Douyin app. There was no black magic and no reverse engineering: the macOS app already supports keyboard input, so underneath it all it was Accessibility and keyboard events.
The interesting part is that Accessibility was never built for agents. Apple spent decades on it so that people who can’t use a mouse, keyboard, or touchscreen could still operate software. Then agents showed up and became a second, entirely unexpected kind of user — an agent has no hands either. For a desktop app with no API, an agent also needs to know what’s on screen, what can be operated, and how to trigger it, and the accessibility tree plus keyboard events are a ready-made, machine-readable entry point. So this remote never needed anything as heavy as computer vision; a few keyboard events were enough. Apple’s decades of goodwill toward accessibility ended up paying an unexpected dividend in the agent era.
Still, I didn’t want the Runtime to see pressArrowDown(), pressSpace(), pressArrowUp(), and I definitely didn’t want a DouyinIntegration baked into the Free4Chat server. What the agent built instead was a thin local Adapter — a single Objective-C .m file, designed, implemented, and tested by Codex in the Room, packaged as a local app on the Mac. It exposes only a few semantic actions:
douyin_remote
|-- previous
|-- play_pause
`-- next
The Runtime only needs to know that a Capability exists, and that it can list, describe, invoke, and observe it. Whether that capability is backed by Accessibility, AppleScript, CUPS, a serial port, a vendor SDK, or someday an ESP32 is none of the Runtime’s business. The Adapter owns the vendor, device, and OS protocol details.
flowchart TB
Runtime["Agent Runtime<br/>Capability calls"]
Adapter["External Adapter<br/>douyin_remote"]
OS["macOS<br/>Accessibility / Keyboard"]
App["Douyin.app"]
Runtime -->|"describe / invoke / observe"| Adapter
Adapter --> OS
OS --> App
I later summarized this boundary in one line: the Runtime knows capabilities, not integrations.
The distinction looks small, but it decides whether Free4Chat slowly turns into another Home Assistant or Zapier. If every device meant new server-side integration code — a printer module, a Douyin module, a Bilibili module, a smart-light module — the Runtime would eventually have to know every vendor protocol, and the server would end up holding everyone’s credentials. I don’t want that. Capabilities belong to the participant; custom integrations belong to the participant; Free4Chat only needs to know which capabilities a participant is willing to expose in the current Room.
I had already tried the same model with an Epson printer. That Adapter talks to local CUPS and shows up as a semantic capability like printer_status. A printer and Douyin look unrelated, but at the Runtime level they’re the same thing:
printer_status
douyin_remote
One reads device state, the other controls a local app. Whether the thing behind it is hardware or software doesn’t matter to the Room.
More than a message
At this point the agent could already control Douyin: I’d say “next” in the Room, it would call douyin_remote.next, and the video would actually change. But that’s not a remote control — if every video meant typing next to Codex, I might as well go back to XiaoAi.
So I asked it to build a phone interface. Codex generated a simple remote against the local control interface we’d just set up. Fullscreen, it’s three buttons: Previous, Play / Pause, Next.
The first version was ugly, but it can be iterated within the same Task: tell Codex to keep adjusting, and the interface updates live on the phone without a refresh.
I opened it on my iPhone, pressed Next, and the video on the TV switched almost immediately. It felt like an ordinary remote — no pause while Codex “thought.” Later I opened it on a second device, and both could share the remote’s state while controlling the Mac mini.
By the way, chat products make it easy to assume an agent’s result is a message, but a Task’s output comes in more shapes than that: a design document is an artifact, a running program you need to watch is a Live View, and something you keep operating is an App. The remote is the last kind — and behind those three buttons is not a mock API but a real Mac mini in the study.
At this point the requirement was done: three buttons on the phone, one action on the TV. But what actually happens after you press Next is the part I wanted to understand.
What happens after you press Next
Here is the full path:
flowchart TB
subgraph Phone["iPhone / Browser"]
App["Generated Task App<br/>Previous / Play / Next"]
Host["Task App Host"]
App --> Host
end
subgraph Room["Free4Chat Room"]
Presence["Presence / Identity"]
Task["Task State"]
Permission["Authorization"]
Projection["Capability discovery metadata"]
AppState["App Metadata / Shared State"]
end
subgraph Mac["Mac mini / Agent Participant"]
Runtime["Agent Runtime"]
Router["Capability Router"]
Adapter["douyin_remote Adapter"]
Accessibility["macOS Accessibility / Keyboard"]
Douyin["Douyin.app"]
Runtime --> Router
Router --> Adapter
Adapter --> Accessibility
Accessibility --> Douyin
end
Host -. "Host context / Room authorization" .-> Room
Host == "Reliable WebRTC DataChannel" ==> Runtime
Room -. "Addressed Task event / authorization context" .-> Runtime
Douyin -->|"AirPlay"| ATV["Apple TV"]
ATV --> TV["Television"]
The easiest thing to misread in this diagram is the Room in the middle. Seeing a cloud Room, the natural assumption is that every button press also goes through it:
iPhone → Cloudflare Worker → RoomSession (the Room's Durable Object) → Mac mini
But in this design, the button call does not route through the Room. The Room is the collaboration state center — each Room has a RoomSession (a Durable Object) that coordinates membership, Tasks, and permissions. But a button press is meant to reach the local control interface on the Mac mini, and there’s no reason for the Room to relay it one call at a time. There are actually two different paths here.
Not routed through the Room
Free4Chat is a realtime collaboration system, so the browser and the Room constantly exchange collaboration state: who joined or left, where a Task stands, whether the agent is still working. The browser syncs this over WebSocket, and RoomSession coordinates it. Who can participate and who can act belongs to this control path.
But pressing Next is different. It needs to trigger a local action on the Mac mini. If every click went Browser → Worker → RoomSession → Agent → Runtime → Adapter, the Room would slowly become a universal remote-call proxy: all participant-local data would detour through the cloud, latency and Worker cost would rise, and the server would start owning integration traffic that belongs to the participant.
So the two paths are separated:
flowchart TB
subgraph CP["Control Plane"]
WS["Room WebSocket"]
DO["RoomSession<br/>Durable Object"]
Presence["Presence / Identity"]
Tasks["Task Lifecycle"]
Perm["Permissions"]
Apps["App Metadata / Shared State"]
Cap["Capability discovery metadata"]
WS --> DO
DO --> Presence
DO --> Tasks
DO --> Perm
DO --> Apps
DO --> Cap
end
subgraph DP["Participant Data Plane"]
Browser["Human Browser"]
Host["Task App + bounded Host API"]
DC["Reliable WebRTC DataChannel"]
Runtime["Agent Runtime"]
Adapter["Local Adapter"]
Browser --> Host
Host --> DC
DC --> Runtime
Runtime --> Adapter
end
CP -. "identity / addressing / authorization" .-> DP
The control plane keeps Room membership, Task state, and permissions. The data plane carries the button call to the Mac mini. The authorization relationship is confirmed by the control plane; the call itself travels over the participant data plane, and RoomSession no longer does per-call application-level relaying.
“Direct” here does not mean the browser and the Mac mini establish a raw P2P connection. It means the call no longer makes an application-level RPC hop through RoomSession. Human and Agent still talk over Free4Chat’s WebRTC / SFU participant transport — the button command rides a reliable DataChannel, and the Go Runtime on the Mac mini joins that realtime link through Pion as a headless participant.
For a single next, this distinction is invisible. It matters once local capabilities become live controls, continuous state sync, hardware sensors, or a Room full of participants. Free4Chat first used WebRTC to move realtime media between participants; this local-control experiment made me think of using a reliable DataChannel to carry button commands to an Agent Runtime. That’s how the chat room and the Agent Runtime slowly grew into one thing.
Generate once, use many times
One more design choice I care about: pressing Next should not call Codex again. A path like “Human Click → LLM → interpret Next → choose tool → invoke capability” would make a terrible remote — model latency, cost, and nondeterminism, just to switch a video.
So the work splits into two phases:
flowchart TB
subgraph Build["Build Time - selected Harness via ACP"]
Req["Human Requirement"]
RuntimeBuild["Agent Runtime"]
Harness["Selected Harness<br/>Codex"]
Inspect["Inspect Environment"]
BuildAdapter["Build Adapter"]
Register["Register Capability"]
Generate["Generate Task App"]
Req --> RuntimeBuild
RuntimeBuild --> Harness
Harness --> Inspect
Harness --> BuildAdapter
BuildAdapter --> Register
Harness --> Generate
end
subgraph Run["Run Time - deterministic hot path"]
Human["Human Click"]
App["Task App"]
Host["Task App Host"]
DC["DataChannel"]
Runtime["Agent Runtime"]
Adapter["douyin_remote"]
Action["Accessibility / Keyboard"]
Human --> App
App --> Host
Host --> DC
DC --> Runtime
Runtime --> Adapter
Adapter --> Action
end
Register --> Runtime
Generate --> App
During build time, the Codex Harness studies the environment, writes the Adapter, and generates the UI over ACP (Agent Client Protocol) — ACP is about how a host controls an agent: sessions, streaming, permissions, cancellation. MCP (Model Context Protocol) sits on the other side, about how an agent discovers and uses tools. Once the work is done, the agent leaves the Runtime hot path; every button press from then on is just a normal deterministic RPC. Swap in another supported Harness and the Room/Runtime boundary stays the same.
This matches a pattern I increasingly like in agent systems: let the model own the fuzzy, high-level, one-shot generation and decisions, and let ordinary software own the frequent, deterministic, verifiable execution. Here the split is especially visible — what the model leaves behind is three buttons.
I wrote more about this boundary in Where Jev Fits. The three actions' rules are simple enough to hardcode, so at runtime even a Decision Model isn’t needed.
The state behind one button
There’s one more thing that’s easy to miss. From the user’s side, the remote’s state is tiny — it’s either ready or unavailable. But making Next work requires a lot of state with different lifecycles, spread across different processes:
| Layer | State |
|---|---|
| Collaboration (Room) | Room membership, Human session, Agent participant session, Task lifecycle, Task execution state, Permission state |
| Interface (browser) | Task App lifecycle, Task App Host state, shared App state, Room WebSocket |
| Transport (RTC) | WebRTC PeerConnection, publisher / subscriber session, DataChannel |
| Runtime (Mac) | Agent harness session, Capability projection, Capability authorization, Runtime transport, Adapter process |
| System (OS / device) | macOS Accessibility permission, Douyin app state, AirPlay session |
String those together and you get the real dependency chain behind one click:
flowchart TB
A["Human / Task ready"]
B["Participant transport ready"]
C["Capability authorized"]
D["Runtime route ready"]
E["Local Adapter / OS permission ready"]
F["TV picture changes"]
A --> B
B --> C
C --> D
D --> E
E --> F
If any one of them fails, all the human sees is a button that doesn’t work. The real difficulty isn’t the number of states — some of these boundaries are simply real: Human and Agent are different participants, the browser and Runtime are different processes, the Room and the local machine aren’t on the same network, and a Task and an Agent Session have different lifecycles. Splitting files more cleanly won’t make them disappear. What you end up having to answer is: which component owns each state, which one is authorized to advance it, and who is responsible for recovery when it fails.
The Room as a temporary trust boundary
Of all that state, the first thing worth pinning down is ownership. Building the remote had a nice side effect: it doesn’t belong to my iPhone. I can control it from my own phone, or from another device; another Human in the same Room can open the same Task App and, if authorized, control the Mac mini.
That doesn’t copy douyin_remote onto their phone, and it doesn’t turn my Mac mini into a permanently public HTTP API. Ownership stays split:
Capability → Mac mini Participant
Adapter → Mac mini / Agent
Task App → Task
Authorization → Room
Human → temporary use of the Capability
The capability stays on the Mac mini, and the Adapter runs only there. The Room just knows which capabilities this Agent participant has projected and whether these Humans may use them during this collaboration. The relationship is still temporary: the call path disappears when the participant or Runtime leaves, the Adapter becomes unavailable, or the Room expires.
So I’ve come to think of the Room as a trust boundary. It isn’t the owner of integrations, and it shouldn’t be a warehouse for local credentials. For Douyin that hardly matters; for an internal service, a printer, home automation, local files, or anything that should never become a public cloud integration, it matters a lot.
At this point, calling Free4Chat an “AI chat room” isn’t quite right anymore. A Room can hold Humans, Agents, Tasks, Apps, and local capabilities at once, each with its own lifecycle and its own permission boundary. What the Room does is increasingly just this: temporarily establishing a revocable collaboration relationship among them.
Generating is easy; trusting is hard
With the boundaries laid out, one question remains: how much authority should a generated interface get?
Generating the HTML is easy — any coding agent can write a remote UI in seconds. The harder question is why I should run it at all. If a generated JavaScript could reach the Room’s internals, the agent’s credentials, the local Runtime, or arbitrary system capabilities, then a more powerful Generated App would just be a bigger security problem.
So a Task App is not “the agent generates some JS and the browser runs it as-is.” There’s an App Host in between:
flowchart TB
Generated["Agent Generated Task App"]
Sandbox["Sandboxed iframe"]
Host["Task App Host<br/>bounded MessagePort API"]
State["Room shared-state API"]
Lane["Reliable WebRTC DataChannel"]
Runtime["Agent Runtime<br/>capability route"]
Adapter["Local Adapter"]
Room["RoomSession<br/>Task / authorization state"]
Generated --> Sandbox
Sandbox --> Host
Host -->|"bounded shared-state calls"| State
State --> Room
Host -->|"explicit Human click"| Lane
Lane --> Runtime
Runtime --> Adapter
Room -. "binds Task / Agent / Human authorization" .-> Runtime
The App runs inside a bounded host contract. It doesn’t need to know how the Adapter process starts, and it doesn’t get macOS accessibility privileges. What it sees is a narrow host API: shared Room state, and invocation of capabilities that have already been projected and authorized. Actions like douyin_remote.next that produce real-world side effects are also tied to trusted human interaction — the agent generated the button, but that doesn’t mean its page can silently loop side effects in the background.
For next this looks excessive. Swap in open_door, start_printer, move_robot, delete_file, and the same boundary stops being theoretical. For generated UI, the <button> is the easy part; putting it inside a controllable execution boundary is the hard part.
From Douyin to Bilibili to printers
Once Douyin worked, Bilibili was the obvious next example. Then a printer, then someday an ESP32 reachable only on the local network — all the same pattern. Only the Capability changes: douyin_remote is three buttons, bilibili_remote adds fullscreen and favorite, printer_status is state and accepting-jobs.
What gets reused isn’t “how to press Douyin’s next button” but the whole path:
Local Integration → Semantic Capability → Participant Runtime → Temporary Room → Agent-generated Human Interface
Douyin itself doesn’t matter. Capabilities come from participants; the Room just temporarily connects the Humans, Agents, and capabilities when collaboration is needed.
When software is made on demand
Squeeze everything back down and what’s left on the phone is still three buttons.
Previous, Play / Pause, Next.
I press Next. The TV moves to the next video — under a second, and no LLM anywhere in the loop.
For just this remote, an HTTP server would obviously be simpler. The reason I took the long way is that, by the end, the remote wasn’t the interesting part anymore.
This App didn’t exist a few minutes ago.
Nobody scoped it. No product manager wrote requirements. No engineer scheduled it. There was no release, no App Store review, and no crowd of users who tried it before me.
I just said: I want three buttons.
The agent looked at what was on the Mac, found a way to control Douyin, wrote an Adapter, turned it into a few semantic capabilities, and generated an interface from those capabilities.
Then I started using it.
At that point I realized the change might not just be about agents writing code.
The software we’re used to has a long production line:
requirements → design → development → testing → release → installation → use.
Agents are steadily compressing the middle of that line.
Need appears, software appears.
When I wrote When Software Stops Needing So Many Software Engineers, I framed this as engineering scarcity declining. A while ago, whether an idea was worth doing first meant asking how much engineering time it would take; increasingly, “can it even be built” isn’t the real question anymore.
This remote pushed that one step further.
Take it one more step: a lot of software may never be “released” at all. It appears temporarily inside a task, solves one very specific problem, and disappears when it’s done.
If software really can be generated the moment a need appears, then the question is no longer just “who still needs to write all this software” — it’s: what gives software that was born seconds ago the right to touch the real world?
A three-button remote is, of course, a silly example.
But if what’s generated isn’t a remote — if it’s a tool that reads internal company files, a panel that controls home devices, an interface that drives robots and printers, or a temporary app that can modify real data — the picture changes completely.
Just because software can be generated quickly doesn’t mean it should be allowed to do whatever it wants.
That’s why all the things that looked over-engineered earlier stayed in the design: sandboxing, human interaction, capability ownership, Room authorization, participant-local adapters, and a deterministic runtime hot path.
None of them made the Next button smarter.
They were solving a different problem:
What gives software that was just born the right to touch the real world, right now?
A lot of our trust used to come from upstream. We knew who built the software, where we downloaded it, whether it was reviewed, how many people had used it.
But if more and more software is generated by an agent at the moment of use, that upstream trust model gets less and less usable.
Code will keep getting cheaper.
Interfaces will keep getting cheaper.
Even integrations can be generated on the spot.
The one thing that hasn’t gotten cheaper is the boundary that separates software from the real world.
So the question three buttons leave behind isn’t really “how much more software can agents generate.”
It’s this:
If future software isn’t a product we choose, install, and trust over time — if it’s generated by an agent the moment a need appears — will our trust shift away from “who made it” and toward “what it can see, what it can call, what it can affect, and when it must expire”?
Code: free4chat · Try it: https://free4.chat