Digital Garden
The Migration of Nine Hundred Sixty-Eight Lines
The grandest migrations in civilized history were never of people, but of scripture — an algorithm written in one civilization’s tongue, moved into another’s grammar without altering a single word.
With the recipe captured, the hardest stretch remained: porting DTK’s 968 lines of pure-algorithm Python (SM3 hashing + variant RC4 + the ordering of fifty scalar fields) into Kotlin with bit-level precision. DTK is an Apache-2.0 clean-room reimplementation, so porting raises no licensing issue — but “bit-level precision” meant one byte’s deviation equals total loss.
I. The stalled agent and the hand on the pen
The engineers first assigned a subagent to the porting while they built the native skeleton (Media3 player + API layer + TV paging UI). Forty-five minutes passed with zero output from the agent — stop it, to prevent later file overwrites, then read the source and write it personally. That was the night’s hardest-core declaration: where the machine stalls, the hand takes over.
II. Two byte-level hunts
The pitfalls of porting all lived at the byte level. First, in the RC4 key schedule key[i] is a Byte in Kotlin (possibly negative) but a 0..255 int in Python — no masking and everything collapses. Second, hand-computing IV constant two’s complement is doomed to err; switched uniformly to Long.toInt() and let the compiler do it. Fixed, committed, built — the first compile passed, v1.0 (4.3MB including Media3).
III. Boonie Bears, in full screen
Install, ignite, run the chain: feed request status 200, 81KB of data — the Kotlin-ported a_bogus, Douyin recognized it on the spot. Full-screen playback succeeded; Boonie Bears was born on the box, with author and title rendered below; the remote’s down key switched to the next movie-commentary clip, OK key paused/played — no login, no captcha, the whole chain at command.
IV. The roadmap and the six gates
After glory came discipline. P1–P6, ordered by “user value ÷ implementation risk”, was written into docs/ROADMAP.md: P1 Cookie login (box shows QR → phone scans to open a LAN page → paste and submit, bypassing remote input) → P2 viewing-experience completion → P3 search → P4 author page/mixes → P5 interactive writes (deliberately after all read paths stabilize — write interfaces are the sensitive zone of account risk) → P6 live streaming as the finale. P7 is continuous: signing regression unit tests, daily interface self-check CI, risk-control backoff — the signing changes every one to three months historically; self-checks produce no features, but they are the precondition for all features staying alive. Four red lines: downloading, watermark removal, bulk collection, commercial use.
Then P1–P6 were built together, v1.1.0 (4.6MB) with twelve items verified: info layer with stats (❤84k 💬10k ⭐3,879), auto-skip on playback failure, author works 18 items guest-direct, pairing service 200, search command delivery succeeded. Two encoding traps were caught en route: brotli claims support but fails to decompress (force gzip); manually adding Accept-Encoding: gzip instead stops OkHttp from auto-decompressing, turning the body into garbage — the agent was doing it for you; don’t steal its job.
Real coordinates
- Port: 968 lines Python → Kotlin (SM3 + variant RC4 + fifty scalar fields); Apache-2.0 clean-room, no licensing issue
- Incidents: subagent stalled 45 minutes with no output → stopped the agent, wrote by hand; RC4 Byte negative-value masking; IV constants switched to Long.toInt()
- Record: first compile passed v1.0 (4.3MB); feed 200 (81KB/95KB/69KB); Boonie Bears full screen; remote switch/pause OK
- P1–P6: Cookie QR import → experience → search → author/mixes → interactive writes → live; P7 signing regression + daily self-check; red lines = download/watermark-removal/bulk/commercial
- v1.1.0: info-layer stats, auto-skip, author works 18, pairing 200, search delivered; encoding traps = force gzip, never manually add gzip header
Comments