What the device says

Two small tools I built for myself, both for things I can touch. A tablet I write on, and a trackpad I share between two Macs. The code was the easy part. Both broke because the device reported something that wasn't true.

Coding agents wrote much of the code for both tools, under my direction. What they couldn’t do was find out how the hardware behaves. That took experiments on the real devices, and most of this post is about what those showed.

Feedback in ink

Agents write me long plans. I read better on paper, and typing feedback back into a chat was slow. So I built a Claude Code skill that sends a document to an e-ink tablet, and reads my pen marks back as data the agent can act on.

Sending renders the Markdown through Typst onto a page the size of the tablet’s screen, 180 × 240 mm. Nothing gets scaled, so nothing has to be unscaled on the way back. The right 45 mm is a margin for handwriting. Questions that need an answer become boxes: decide boxes with options A to J, ruled boxes for questions, circles 1 to 5 for ratings. The last box always asks what Claude should do with the whole thing.

Every box and heading carries a label Typst can find again. One query writes all of them, with page and position, to a file next to the PDF. The document carries its own map, so nothing has to parse the PDF later to find out where a box is.

Uploads go to one inbox folder on the tablet. Pairing with the tablet’s cloud is mine to do. The agent never types the code.

Colour does the reading

Handwriting recognition is the obvious way to read the marks, and the least reliable. Most feedback doesn’t need it. If the pen’s colour carries the meaning, a tick or an underline says enough.

3 RetriesIf the upload fails, retry three times,then stop and leave it in the inbox.Compare the manifest with the last pull,so only changed documents download.The inbox folder is the only target.D2 Decide: format for long plansA MarkdownB TypstC HTMLwhythree?
annotations.json
{
  "box": "D2",
  "kind": "decide",
  "colour": "green",
  "meaning": "yes",
  "option": "B"
}
summary.md
D2 → B
A tick in a decide box becomes its option letter. Nothing to read.

Red means no, green yes, blue a question, yellow keep this, black a note. When I pull a document, touching strokes of the same colour become one mark. Each mark is placed in the box it falls in and under the nearest heading, and the text beneath it is read from the PDF. A tick in a decide box becomes its option letter.

The agent gets back lines like “D1 → A” and a red underline on “retry three times” in section 3. It can act on those without asking me what I meant.

The skill is 596 lines of Python and 172 of Typst.

The canvas lied

The first pulls put marks in the wrong place. Not by a little: 35 to 90 points off, which on a page is the next line or the next box.

The tablet’s own files say the page is 1404 units wide. My strokes reached about 1610. The transform believed the first number.

So I stopped believing it. A calibration page has four crosshair targets near the corners. I draw an X on each one, pull, and fit a transform from where the strokes landed to where the targets are, one least-squares fit per axis.

Calibrationdraw an X on each target

The files say 1404 units wide. The strokes reach about 1610.

Top left37 pt
Top right85 pt
Bottom left56 pt
Bottom right88 pt

Limit: 2 pt

Every X was drawn right on its target. With the width from the metadata, they come back 35 to 90 points away.

One detail mattered. Each X is matched to its target by the corner of the page it’s in, not by distance. Before calibration, the distances are the thing that’s wrong.

It took five calibration pulls in eight minutes. The marks now land within 0.25 to 0.68 points of the targets, against a limit of 2.

The offsets in the figure are drawn within the range I measured. The residuals are the real ones.

A trackpad with one owner

I work on two Macs with one keyboard and one trackpad. The keyboard switches between them with a key. The trackpad doesn’t. It stays with the first Mac, and moving it meant opening Bluetooth settings on the other one, forgetting the device and pairing again.

I wanted the trackpad to follow the keyboard. First I had to learn how it behaves, and the only way to learn was to try things.

OwnerIt holds a bond to one Mac at a time.
HiddenWhile it’s disconnected, no other Mac can find it.
FreedIt becomes findable when its current Mac unpairs it while it’s still connected. The same call Forget makes.
QueryA new connection only sticks if a service query runs first, so the input driver attaches. The usual command-line Bluetooth tools skip it, which is why there’s a small Swift binary.

So only the Mac that has the trackpad can let it go. A handoff has to be a short conversation between the two Macs.

Five seconds

A watcher on each Mac checks the list of input devices once a second. When the keyboard shows up, it waits a second and asks the other Mac over ssh to let the trackpad go. That Mac unpairs it while it’s still connected. Then this Mac drops its old bond, pairs, connects, runs the service query and waits up to 4 seconds for the input driver. Every step has a timeout.

KeyboardMac AMac BTrackpad0 s1 s2 s3 s4 s5 s6 shas the trackpadswitches to Mac Bsees itrelease, over sshunpairfindablepair, connectservice queryinput on Mac B5.0 s

I press the keyboard's key for Mac B. The keyboard switches. The trackpad stays bonded to Mac A.

The total is the measured median. The steps in between are drawn to fit it, not timed one by one.

If a step fails, it tries again every 3 seconds for up to 3 minutes. After three failures it tells me to flip the trackpad’s power switch. For ssh it tries the route that worked last time first, then the local network name, then the VPN address. When I log out, the trackpad goes to the other Mac, or gets unpaired so it can still be found.

My log goes back to September 2. The keyboard arrived 290 times, and 194 of those the trackpad was already there. I could measure 91 handoffs. The median is 5.0 seconds, three in four finished within 7, and the slowest took 85. Eight requests between the Macs timed out, and once it gave up.

Every choice was the plain one: polling instead of system notifications, and bash, with Swift only where a private call needed it. Twice the plain thing failed without a word. Copying files to the other Mac with rsync did nothing, so it uses tar over ssh. And launchd refused to start the new version until the old process had exited, so the installer waits for it.

The permission belongs to the process

The Bluetooth helper worked when launchd started it and hung when I ran it over ssh. Same binary, same commands. macOS only lets a process that launchd started hold the Bluetooth permission, so anything I ran from a terminal waited forever. Rebuilding the helper was worse. The new binary had a new hash, and the permission stayed with the old one, without a word.

So the helper is built once and kept alive. One launchd worker holds the permission and reads requests from a folder. Everything else writes a file and waits for the answer.

ssh sessionno Bluetoothmailbox/launchd workerholds Bluetooth0swatchdogreq.tmpres.tmprc=0

The ssh session can't touch Bluetooth. It writes its request to req.tmp.

Both sides write to a temporary name and then rename, so nobody ever reads half a file. macOS has no timeout command, so the 40 second watchdog is written by hand. When it fires, the answer is rc=124, the code a timed-out command gets on Linux.

The menu bar app only calls the command-line tool. It holds no permission, so I can rebuild it as often as I like.