Guidance for AI coding agents working in this repository. CLAUDE.md and GEMINI.md are
symlinks to this file, so every tool reads the same text — edit AGENTS.md, never a symlink.
Sideloaded Tizen web applications for a Samsung Smart Monitor M8 (Tizen 6.5, Chromium 85),
plus the Python tooling that drives the device and a Cloudflare Worker that lets an app be
configured from a phone. There is no package manager, no bundler, and no framework: every
app is a single self-contained directory of hand-written ES5-era HTML/JS packaged into a
.wgt.
Public repository. Device addresses, tokens, and the pairing hostname are deliberately kept
out of it — the README uses RFC 5737 documentation addresses (192.0.2.10) and real values
live in gitignored .env / LOCAL.md / token.txt / */local-config.js.
Tooling reads config in this order: environment variables > .env in the project root >
defaults in tools/config.py. tools/config.py has its own dependency-free .env parser.
python3 -m venv .venv && .venv/bin/pip install samsungtvws
cp .env.example .env # set SAMTOR_HOST to the monitor's LAN address
git lfs install # icons are LFS pointers without thisShell variables used throughout: MONITOR_IP, SDB_PORT (26101), CERT_PROFILE,
SDB=~/tizen-studio/tools/sdb, TIZEN=~/tizen-studio/tools/ide/bin/tizen.
SAMTOR_TOKEN holds a path, never the token string — samsungtvws rewrites that file
when the monitor rotates the token, so it is runtime state rather than configuration.
Six independent suites; there is no aggregate runner.
.venv/bin/python -m unittest tests.test_tvctl -v # tooling (run from the project root)
node tests/test_pairing_page.mjs # renders and parses the Worker's page
node tests/test_pairing_limits.mjs # rate limit policy, and code/config drift
node tests/test_mirror_schema.mjs # the mirror's schema, reducer and ceilings
node tests/test_mirror_client.mjs # DOM-to-schema rules, with no DOM
node tests/test_mirror_page.mjs # renders and parses the mirror page
bash tests/test_public_doom.sh # pinned checksums + nothing GPL is trackedtests/ has no __init__.py, so unittest discover -s tests fails — use the module path
above, or run the file directly. A single test: append .PairingOutputTest.test_name.
cd Bench
"$TIZEN" build-web -- .
"$TIZEN" package -t wgt -s "$CERT_PROFILE" -- .buildResult
"$TIZEN" install -n Bench.wgt -s "${MONITOR_IP}:${SDB_PORT}" -- .buildResult
"$TIZEN" uninstall -p BenchApp00.Bench -s "${MONITOR_IP}:${SDB_PORT}"installtakes-s(device), not-t—-twants a Device Manager target name and answersThere is no target.uninstalltakes the full app ID (DoomApp000.Doom), not the 10-char package prefix.- The
.wgtfilename comes from<name>inconfig.xml, not the directory name. - Package IDs must be exactly 10 alphanumeric characters.
- Iterate in desktop Chrome where possible;
tizen.*calls are wrapped intry/catchso most UI logic runs off-device.
"$SDB" connect "${MONITOR_IP}:${SDB_PORT}"
.venv/bin/python tools/tvctl.py info|pair|key KEY_HOME|open BenchApp00.Bench
.venv/bin/python tools/watch_devmode.py # poll Developer Mode / sdb port
.venv/bin/python tools/wait_sdb.py # wait for sdb after a reboot
"$SDB" shell 0 vd_applist # list apps — tvctl.py apps HANGS on 2022+ firmwareThe debug port only opens for a closed app; close it with tvctl.py key KEY_RETURN
first or 0 debug hangs.
"$SDB" shell 0 debug BenchApp00.Bench # prints "port: NNNNN"
"$SDB" forward tcp:NNNNN tcp:NNNNN
.venv/bin/python probes/<script>.py NNNNN
"$SDB" shell 0 execute BenchApp00.Bench # launch without a debuggercd pairing && npx wrangler dev # http://localhost:8787
node ../tests/test_pairing_page.mjs
PAIR_HOSTNAME=pair.example.com node scripts/with-route.mjs && npx wrangler deploy --config wrangler.deploy.jsonDeploys automatically from .github/workflows/deploy-pairing.yml on pushes to main that
touch pairing/. PAIR_HOSTNAME is a repository secret, not a variable, because this
repo is public and GitHub redacts secrets from wrangler's deploy output.
Doom/doomgeneric.{js,wasm,data} are generated, gitignored, and must exist before packaging.
Doom/build.sh downloads checksum-pinned upstream archives (doomgeneric at a fixed revision,
DOOM 1.9 shareware, dgguspat) into .build/ and builds with emsdk 6.0.9. Needs unar,
unzip, curl, make, emcc. Changing any pin means updating the matching assertions in
tests/test_public_doom.sh and the links in README.md / THIRD_PARTY_NOTICES.md.
Apps (Bench/, DinoJump/, Doom/) — one directory each, packaged whole. All logic is
in a single index.html (Bench is ~790 lines) built as a set of screens with exactly one
visible at a time. Everything is ES5-style function syntax and IIFEs, targeting Chromium 85.
No shared code between apps: the pairing client is copied in by
pairing/client/install.sh, because a .wgt is built from one self-contained directory.
Re-run that script after touching pairing/client/*.
pairing/ — a Cloudflare Worker acting as an RFC 8628-style rendezvous point, since a
Tizen web app cannot listen on a socket. src/index.js routes, generates codes, and
validates the shape of the config schema; src/session.js is a Durable Object (one per
code, SQLite backend, WebSocket Hibernation for near-zero duration cost); src/page.js is
the phone-side page served inline. The hostname appears nowhere in the source — the
verification URI and QR are derived from the request's Host. An app declares what it needs
(config: { app, fields: [...] }), the phone renders the form, values return over the open
socket and can be resent. See pairing/README.md for the full HTTP/socket API and schema.
The same Worker carries a second, live mode: src/mirror*.js plus client/remote-mirror.js
mirror a form the application already has on screen onto a phone, both directions, at a
100 ms cadence. It has its own routes (/m, /api/mirror/*), its own Durable Object and its
own client; it shares only the code alphabet and the three rate limit bindings. index.js
meters those routes and delegates — do not read env.RL_* inside mirror-router.js,
because tests/test_pairing_limits.mjs scrapes index.js alone and a binding it cannot see
is a limit nobody enforces. What the phone renders is derived from the DOM by
describeForm(), so a mirrored form is described exactly once, in the markup.
tools/ — config.py (env resolution), tvctl.py (WebSocket remote over wss://:8002),
plus two Developer Mode / sdb waiters.
probes/ — throwaway CDP scripts that attach to /json/list and drive
Runtime.evaluate; each takes the forwarded debug port as argv[1]. Kept as evidence, not
maintained. probes/preflight/ is frozen: it produced the measurements in
pairing/README.md and is not meant to run as-is. results/ holds JSON captures from
on-device runs (results/apps.json is gitignored — it is personal device data).
These were measured, not assumed, and explain otherwise-odd decisions:
<access>inconfig.xmlis required forfetch/XHR to external origins; WebSocket is not subject to it. Omitting it produces a bare "Failed to fetch" while sockets keep working — the most confusing failure mode on this platform. CORS does not apply once an origin is whitelisted (responses come backtype: "basic"and readable).- Web apps render at 1920×1080 even on a 4K panel. Keep a canvas backing store at source frame size and scale with CSS — raising Doom's to 1440×1080 cost 60 → ~32 fps.
- Canvas 2D is barely accelerated (~176 sprites @ 60 fps, ~55 Mpx/s) vs WebGL (~28k triangles @ 60 fps). WASM is ~16× JS. WASM SIMD and bulk memory are unavailable; shared memory/threads are available.
- Remote keys need ~0.6 s between presses; Tizen swallows back-to-back sends.
registerKey()silently does nothing without thetv.inputdeviceprivilege. Partner buttons (Netflix/Disney+/Amazon) cannot be bound — the launcher intercepts them.- The remote microphone's raw audio is not reachable:
getUserMediafails withNotReadableErrorunder every privilege combination. Onlytizen.voicecontrolworks. - The app runs from a
file:origin yetisSecureContextis true, so WebCrypto is available (full ECDH P-256 + HKDF + AES-GCM handshake in 160–190 ms). wgt-privateandlocalStorageboth survive an in-place reinstall.- Developer Mode's sdb port often stays closed until after a reboot, and Smart Hub caches icons — reinstall the same package to refresh artwork.
- Comments in this codebase explain why, usually recording a failure that was paid for
once (see the
canvasCSS rule inBench/index.htmlthat once hid the pairing QR). Match that register rather than narrating what the code does. - Four browser facts the mirror client encodes, each of which only shows up on the device:
el.maxLengthanswers524288when the attribute is absent; HTML'spatternis implicitly anchored while this schema's is not;setSelectionRangethrows ontype=emailandtype=number; andkeyCodecannot be set through theKeyboardEventconstructor, so it is defined on the instance or every relayed key does nothing. - Never push without an explicit, per-push instruction, and never force-push without
one. Approval for one push does not carry over to the next commit, amend, or rebase.
Cursor enforces the force-push half of this through
.cursor/hooks.json; other tools are expected to honour it on their own. - Never commit:
token.txt,.env,LOCAL.md,results/apps.json,*/local-config.js,pairing/wrangler.deploy.json, certificates, or generated Doom artifacts. - Documentation addresses in committed files stay RFC 5737 (
192.0.2.10); real device values belong inLOCAL.md.