Skip to content

feat(machines): mirror a pane's screen into the terminal lens where herdr cannot attach - #228

Merged
devswha merged 15 commits into
mainfrom
feat/windows-terminal-mirror
Oct 1, 2026
Merged

devswha merged 15 commits into
mainfrom
feat/windows-terminal-mirror

Conversation

@devswha

@devswha devswha commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Stacked on #227. Refs #189.

Why

herdr has no terminal attach on Windows yet (herdrdev/herdr#4821), so #227 gives a Windows PC a chat lens and a notice where its terminal would be. This is a stopgap so the terminal lens shows something real until herdr can attach there.

What

  • server/mirror.ts: MirrorSession reads the pane's visible screen (pane.read, ansi) every 80 ms while it changes, relaxing to 400 ms, and sends each changed screen as one whole repaint in ordinary pty-data frames. It has PtySession's surface, so the attach lifecycle, the replay for late joiners (the latest screen only) and the output window are reused as they are.
  • The grid is the pane's own in herdr. pane-geometry gains fixed: true, sent before the first screen; every client adopts that size and none resizes. A layout change on the PC re-reads the size and repaints.
  • Typing on such a PC always goes through pane.send_text in the pane's queue.
  • HerdrIdentity.terminal_mirror on /api/health, /api/bridge and the PC list. The client treats it as a working terminal lens: no soon pill, and the lens remembers its choice per pane again. The terminal_unsupported handling stays for a bridge without the mirror.
  • createServer({ terminalAttach: false }) (from feat(machines): Windows PCs over SSH, chat lens only until herdr can attach there #227) answers as a Windows herdr would, for tests and QA.

Limits

  • No cursor: herdr's read carries no cursor position, so it is hidden.
  • Output that comes and goes between two reads is not seen.
  • The grid is the pane's size on that PC, not the browser's; a phone sees it from the left edge, as an observer does.
  • Not run against a real Windows PC. No Windows host was reachable from the workstation this was built on. It is proven on Linux with attach forced off; scripts/windows-host-qa.ts is updated for the mirror but was not run.

Tests

  • server/mirror.test.ts: frame shape, sends only changed screens, pause/resume sends the latest only, repaint, kill stops reading, ends when herdr says the pane is gone.
  • server/submit.contract.test.ts: over a real pane with attach forced off: the pane's grid arrives before the first screen, a resize is ignored, typed echo output comes back as a screen, a late joiner gets the current screen, closing the pane ends with pty-exit.
  • scripts/windows-lens-browser-qa.ts: in Chrome, the terminal lens shows typed output and colour, survives a lens switch, and a phone-sized second viewer sees the same screen.
  • bun run typecheck, generate:types --check, test:unit (647 pass), test:integration pass locally.

…d tell a reused pid from herdr's

A PC without terminal attach sent each WS input straight to pane.send_text, so a Stop
tapped right after Send could land between the message and its Enter. It now waits its
turn in the pane's queue like every other input.

herdr's Windows socket marker was called live whenever its pid was: after a reboot another
program can hold that pid, and the bridge then refused to start a daemon. What runs under
the pid decides (tasklist), with the pid alone as the fallback.

The bundle smoke no longer replaces a failed assertion with its cleanup error.
…erdr cannot attach

herdr has no terminal attach on Windows (herdrdev/herdr#4821), so such a PC had a chat
lens and a notice in place of its terminal. The bridge now reads the pane's visible
screen (pane.read, ansi) a few times a second and sends each changed screen as a whole
repaint in ordinary pty-data frames. MirrorSession stands where PtySession stands, so
the attach lifecycle, the replay for late joiners and the output window are unchanged.

The grid is the pane's own: pane-geometry carries fixed, sent before the first screen,
and every client adopts it instead of resizing. Typing goes through pane.send_text in
the pane's queue. /api/health and the PC list carry terminal_mirror.

A stopgap: no cursor, nothing between two reads, and it ends once herdr reports attach.
@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Repository: devswha/herdr-web-ui/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 301cca6c-010a-4ff6-97c8-1779e03be910

📥 Commits

Reviewing files that changed from the base of the PR and between bbf5a41 and 549b489.

📒 Files selected for processing (13)
  • CHANGELOG.md
  • docs/remote-pcs.md
  • scripts/windows-host-qa.ts
  • scripts/windows-lens-browser-qa.ts
  • server/herdr/client.ts
  • server/index.ts
  • server/mirror.test.ts
  • server/mirror.ts
  • server/submit.contract.test.ts
  • shared/machines.ts
  • shared/protocol.ts
  • src/App.tsx
  • src/components/PaneTerminal.tsx
 ______________________________________________________________________________________________________________________________________________________
< Why do you need code reviews? dB/dt = ∇ × Bv: The proliferation rate of bugs (dB/dt) equals the curl of the bug vector field (Bv). It's simple math. >
 ------------------------------------------------------------------------------------------------------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Comment @coderabbitai help to get the list of available commands.

… and drop it with its connection

Typing on a server that did not know yet whether herdr attaches waited for the ping
outside the pane's queue, so a message sent meanwhile overtook it. The turn is taken
first and the probe runs inside it.

Typing that waited its turn was still sent after its connection closed. It is dropped.
…on Windows

cmd holds the file it redirects into. A PC that already ran a bridge for one herdr
session could not start a second: the launcher's redirect into the shared bridge.log
failed with "being used by another process" and the bridge never ran (found on a real
Windows PC with a default-session bridge up and a named session added). The log and
the launcher are named after the session, and so is the daemon's log.
…setup

- PowerShell ends a single-quoted literal at a curly quote (U+2018 to U+201B) too: a
  path holding one ran what followed it. psQuote doubles them, and remote-entry.ts
  uses the same function.
- The win32 bundle carried node_modules/.bin symlinks, which an account without the
  symlink privilege cannot extract.
- The bridge launcher was written as ASCII, so a profile such as C:\Users\홍길동 lost
  its name and Bun never started. It is UTF-8 now, behind chcp 65001.
- A key file whose last line had no newline took the app key onto that line.
- The administrators key file kept a write grant to Users, Authenticated Users or
  Everyone that it already had, and sshd refuses such a file.
- A marker whose pid another herdr holds was called live. Its second field is the
  daemon's start in Unix nanoseconds, compared now with the process's creation time,
  and the name has to be herdr exactly.

All six were reproduced on a real Windows PC before the fix.
… size, and end an attach to a mirror already gone

From an adversarial review of the mirror:
- A late joiner got the stream tail of the last frame, which cuts a screen larger than
  the replay buffer in two. The mirror hands over its latest screen whole.
- A pane resized on its PC kept its old grid here: no event this server listens to
  announces a layout change. The mirror asks for the pane's size every two seconds,
  tells the clients first, then paints the screen again.
- An attach that waited for a mirror whose pane vanished during its first read joined
  a record already closed and heard nothing more. It gets pty-exit.
Base automatically changed from feat/windows-hosts to main October 1, 2026 07:30
…-mirror

# Conflicts:
#	CHANGELOG.md
#	docs/remote-pcs.md
#	scripts/windows-host-qa.ts
#	scripts/windows-lens-browser-qa.ts
#	server/herdr/client.ts
#	server/index.ts
#	server/submit.contract.test.ts
#	shared/machines.ts
#	shared/protocol.ts
#	src/App.tsx
#	src/components/PaneTerminal.tsx
@devswha
devswha merged commit 79abf6c into main Oct 1, 2026
10 of 21 checks passed
@devswha
devswha deleted the feat/windows-terminal-mirror branch October 1, 2026 07:35
devswha added a commit that referenced this pull request Oct 1, 2026
Release v0.3.38: moves the Unreleased notes under 0.3.38 and bumps
`package.json` and `herdr-plugin.toml`.

In this release: Windows PCs over SSH (#227) with an interim mirrored
terminal (#228), sidebar workspace folding (#222), Gajae Code in New
session (#220), gjc background results ending a chat turn (#225), OmO
pane marks without an agent kind (#224 by @beomq).

The mirror entry now says that a phone cannot pan the pane-sized grid
yet (#230).

Remote bundle `remote-v9` is tagged on `79abf6c`; `release.yml` runs
only after its release is published.

`bun scripts/release-notes.ts 0.3.38` prints the notes and exits 0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant