herdr-web-ui
AGENTS.md459 starsChanged 2 months agoMITView on GitHub
Browser UI for the herdr terminal multiplexer: a React 18 + xterm.js client (src/) and a Bun.serve backend (server/) that bridges herdr's newline-JSON unix-socket API. shared/ is the wire contract both sides import. The app is only a bridge: herdr owns every pty, scrollback and agent state.
- Commits and pushes
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository2 other files it gives its agents.
- server/AGENTS.mdAGENTS.md
- src/AGENTS.mdAGENTS.md
The file
We split this AGENTS.md into the rules it gives an agent
11 rules. About 0 are common, 1 is distinctive, and 10 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
10
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 9
Read server/AGENTS.md before editing server/ and src/AGENTS.md before editing src/.
- Very specific: line 16
NEVER load node-pty inside Bun.
- Very specific: line 18
NEVER give xterm scrollback (keep scrollback: 0), and never rebuild the terminal from pane.read.
- Very specific: line 19
NEVER edit shared/herdr-api.generated.ts.
- Very specific: line 20
NEVER pool herdr RPC connections: herdr closes the socket after each response.
- Very specific: line 32
Every push to main redeploys the site and the demo.
- Very specific: line 33
Every error body is { error: { code, message } }, built only with the helpers in server/http.ts.
- Distinctive: line 43
Wait with bounded polls and deadlines, never fixed sleeps.
- Very specific: line 61
Every createServer in a test gets a temp stateDir from mkdtempSync and port: 0.
- Very specific: line 63
NEVER run the real herdr update in a test: it replaces the herdr on PATH.
- Very specific: line 73
Write the full link (GitHub leaves a bare #208 unlinked in CHANGELOG.md) and keep @login bare (it is what lists the contributor in the …
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
herdr-web-ui
Browser UI for the herdr terminal multiplexer: a React 18 + xterm.js client (src/) and a Bun.serve backend (server/) that bridges herdr's newline-JSON unix-socket API. shared/ is the wire contract both sides import.
Scope
- This file,
server/AGENTS.mdandsrc/AGENTS.mdare committed and apply to every agent working on the project, forks included. A PR is checked against them together withCONTRIBUTING.md,.github/REVIEW.md,docs/development.mdandDESIGN.md. - They hold only what the code and those documents do not show. Commands, layout, environment variables and release steps are in
docs/development.mdandpackage.json; do not copy them here. - Read
server/AGENTS.mdbefore editingserver/andsrc/AGENTS.mdbefore editingsrc/. - "Maintainer workflow" applies only to the maintainer. Everyone else follows
CONTRIBUTING.mdfor branches, PRs and the changelog.
Bridge invariants
The app is only a bridge: herdr owns every pty, scrollback and agent state.
- NEVER load node-pty inside Bun; it panics the runtime (oven-sh/bun#18546). All PTY work goes through the Node sidecar
server/pty/pty-host.mjs, and the only process it runs isherdr terminal attach <terminal_id>. - NEVER pass
--takeovertoherdr terminal attachon the server's own initiative: an attach, a retry or a reconnect waits for the holder instead. Only a user's explicit request for that pane, from an interact connection, may take it. Always setHERDR_SOCKET_PATHto the socket the RPCs use. - NEVER give xterm scrollback (keep
scrollback: 0), and never rebuild the terminal frompane.read. The attach byte stream is the source of truth. - NEVER edit
shared/herdr-api.generated.ts. Runbun run generate:types. - NEVER pool herdr RPC connections: herdr closes the socket after each response. Use one connection per call (10 s timeout). Only
events.subscribestays open, and a second subscribe on an open connection is silently ignored, so reopen it with the full set. pane.process_infotakespane_id, nottarget. Giventarget, it silently answers for the focused pane.server/collector.tsis the only status subscription source. Do not subscribe to status anywhere else.- Nothing the user typed is ever queued or sent automatically while offline. Keystrokes go to a draft the user sends or discards; messages sent while the agent works wait for an explicit "Send now".
- Prompt answers are
send_keysnavigation, never digits, and go throughPOST /api/pane/prompt/answer: the key semantics per agent live on the server. - Web push: build requests with
generateRequestDetailsand send them withfetch; never callsendNotification. - The omo transcript is found through the process tree, never through
pane.agentor file mtime. - Windows x64 has no PTY sidecar: herdr there cannot
terminal attach, so the server mirrors the screen (server/mirror.ts). Do not assume a pty exists.
Changing a contract
- HTTP and WS shapes live in
shared/protocol.ts; change both sides through it and add a contract test (server/api.contract.test.tsfor endpoints). - Every push to
mainredeploys the site and the demo. A new endpoint or WS frame needs an answer insite/demo/transport.ts, or the demo gets a 404. - Every error body is
{ error: { code, message } }, built only with the helpers inserver/http.ts. - Mutating machine, device and update POSTs require same-origin plus the
x-herdr-machine: 1orx-herdr-update: 1header. - Route order in
createServer().fetchmatters: bridge, then machines, then/ws, then the/api/*handlers, then a 404 for the rest of/api/*, then static files.
Code conventions
- Imports carry explicit
.ts/.tsxextensions and relative paths. The@shared/*alias is configured but unused; do not start using it. - Wire fields are snake_case (
pane_id) and code is camelCase (paneId). createServer(options)is the only injection seam; an unset option falls back to the environment.- State files are written to a temp file and renamed, files 0600 and directories 0700.
- Wait with bounded polls and deadlines, never fixed sleeps.
- Multi-PC: pane and workspace calls go through
useMachineApi(), and storage keys usepaneStorageId(machineId, paneId). Never use a mutable global target in async work. - Component CSS is colocated and uses tokens only: no color literals, no
!important.DESIGN.mdmust match the token values insrc/styles.css; no test checks this, so update both together. - Endless animations use
steps()orvar(--ease-pulse)(src/motion.test.tsenforces it). - i18n: the English string is the key and must be a string literal. Every new
t("…")needs an entry insrc/lib/i18n.ko.ts,i18n.ja.tsandi18n.zh.ts;i18n.test.tsfails on a missing, unused or untranslated entry. - Shortcuts are Mod+Shift+key so the pty keeps Ctrl+key. To add one, update
SHORTCUTS,KEY_TO_IDand the switch insrc/lib/shortcuts.ts. - Icons come from lucide-react only; brand marks live in
AgentMark.tsx. When icon files change, bump the?v=query inindex.htmlandCACHE_NAMEinpublic/sw.jstogether. - UI wording: "New workspace", not "New session". "Session" means the herdr server session or an agent's history.
- There is no linter or formatter.
scripts/andsite/are not typechecked, so run what you change there.
Testing
bun:testonly, with no DOM.src/tests cover pure logic inlib/*.test.ts; component behavior is covered by the Playwright scripts. A.test.tsxfile is not discovered.- A test that needs a live herdr is named
*.contract.test.ts. Unit tests run withHERDR_TEST_MODE=unitand never touch herdr. - Single file:
HERDR_TEST_MODE=unit bun test ./server/prompt.test.ts. The./is required. bun run test:uidoes not runscripts/file-viewer-regression.ts; CI does.- Tests run on an isolated herdr session (
herdr-web-ui-test, or-1to-4underbun run test:integration), never the user's. Stop a leftover one withherdr --session herdr-web-ui-test server stop. - Each
describecreates and closes its ownherdr-web-ui-test-<purpose>workspace withfocus:false, and mutates only panes it created. - Every
createServerin a test gets a tempstateDirfrommkdtempSyncandport: 0. The default state dir is the user's real devices directory. - Transcript caches are module-global; tests call
forgetTranscriptState(). - NEVER run the real
herdr updatein a test: it replaces the herdr on PATH. scripts/generate-protocol-types.test.tsrewrites the generated file while it runs; do not edit that file during a test run.- Two servers cannot attach the same pane: the second gets
attach_conflict. For QA, use a pane the live server does not hold. - Screenshots and recordings come from the
herdr-web-ui-demoor a test session, never the user's live session. Playwright scripts servedist/, so build first.
Maintainer workflow
- PRs only, squash merged; the title is
type(scope): summaryand the merge adds(#N).mainrequires the "Fast checks" and "Integration and browser" checks and every review thread resolved. - Release steps are in
docs/development.md#releasing. NEVER push av*tag by hand: installed updaters act on tags alone. - Changelog entries end with the PR link, plus
by @loginfor an outside contributor:… ([#208](https://github.com/devswha/herdr-web-ui/pull/208) by @login).- Write the full link (GitHub leaves a bare
#208unlinked in CHANGELOG.md) and keep@loginbare (it is what lists the contributor in the GitHub release). - Link the PR, not the issue. An entry built from several PRs links each one.
- Credit every PR author except @devswha and bots, also when the maintainer pushed fixes to the PR or carried it into a new one; then link both, with
by @loginafter the PR that person wrote. - A PR has no number until it opens, so add the link in a commit after
gh pr create. At release, fill in missing links and credits fromgit log --format=%s <last tag>..mainandgh pr view N --json author.
- Write the full link (GitHub leaves a bare
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

