Skip to content

fix(chat): 채팅 보기가 공유 터미널 크기를 바꾸지 않도록 수정 - #363

Merged
devswha merged 4 commits into
devswha:mainfrom
WOULDU-pres:fix/chat-keeps-terminal-size
Oct 3, 2026
Merged

devswha merged 4 commits into
devswha:mainfrom
WOULDU-pres:fix/chat-keeps-terminal-size

Conversation

@WOULDU-pres

Copy link
Copy Markdown
Contributor

Change

안녕하세요. #361에서 제기된, 채팅 보기가 공유 터미널 크기를 바꾸는 문제를 확인하여 수정을 제안드립니다. Closes #361

폰에서 pane을 채팅 보기로 열면 그 pane의 터미널이 폰 화면 크기로 바뀌고, 같은 pane을 데스크톱에서 보면 프로그램이 좁은 폭으로 다시 그려집니다. 채팅 보기는 대화를 자체 레이아웃으로 그리므로 터미널 크기를 바꿀 이유가 없습니다.

원인을 확인해 보니 PaneTerminal은 채팅 보기에서도 화면 뒤에 붙어 있고, 처음 연결할 때(attach), 화면 크기가 바뀔 때(키보드가 열릴 때 포함), 탭으로 돌아올 때, 글꼴을 바꿀 때 브라우저 기준 cols/rows를 서버로 보내고 있었습니다. 서버는 interact 연결의 attach와 resize를 받으면 그 크기로 공유 pty를 맞춥니다.

이번 변경은 다음과 같습니다.

  • attach에 선택 필드 keep_size를 추가했습니다. 이 값이 있으면 서버는 observe 연결과 같은 방식으로 pty를 pane 자체 크기로 만들고, 이미 있는 pty의 크기도 바꾸지 않습니다. 대신 현재 크기를 pane-geometry로 알려 줍니다.
  • 채팅 보기에서는 keep_size: true로 연결하고, resize를 보내지 않습니다. 재연결할 때도 같은 상태로 다시 연결합니다.
  • 채팅 보기의 숨겨진 터미널은 받은 pane-geometry에 맞춥니다. 채팅 보기에 표시되는 비밀번호 입력 칸은 이 숨겨진 화면에서 프롬프트를 읽기 때문에, pty와 같은 크기로 그려야 합니다. 이 부분이 빠졌을 때 기존 secret-input 브라우저 테스트가 재연결 후 프롬프트를 찾지 못해 실패하는 것을 확인했고, 함께 반영했습니다.
  • 터미널 보기로 돌아오면 기존 동작대로 그 기기 크기에 맞춰 resize를 보냅니다.
  • observe 모드, 고정 grid(Windows mirror), 터미널 보기의 동작은 바꾸지 않았습니다.

새 필드는 선택 사항이라, 아직 갱신되지 않은 원격 PC 번들(remote-v11)은 이 값을 무시하고 기존처럼 동작합니다. 원격 PC에도 적용하려면 다음 번들 갱신이 필요합니다.

server/api.contract.test.ts에 keep_size 연결이 새 pty와 기존 pty의 크기를 바꾸지 않고 현재 크기를 알려 주는지, 일반 연결은 여전히 크기를 바꾸는지 검증하는 계약 테스트를 추가했습니다. src/lib/ws.test.ts에는 재연결 시 keep_size 유지와 해제를, scripts/chat-size-regression.ts에는 실제 브라우저 검증을 추가했습니다. 변경 이력도 Unreleased 항목에 기재했습니다.

Validation

별도로 만든 테스트 세션에서 데스크톱(1280×800, 터미널 보기)과 폰(390×844, 채팅 보기) 브라우저로 같은 pane을 열고, pane 안의 셸이 보고하는 크기(stty size)와 폰이 보낸 프레임을 확인했습니다. 원본(bb7ef50)과 수정본을 같은 스크립트로 각각 실행했습니다.

단계 수정 전: bb7ef50 수정 후
폰 채팅 보기가 보낸 프레임 attach(keep_size 없음) + resize attach(keep_size: true)만
폰 채팅 보기 연 뒤 셸 크기 폰 크기로 변경 요청됨 36 145(데스크톱 그대로)
폰에서 터미널 보기로 전환 앞 단계에서 실패해 측정하지 않음 36 57(폰 크기)

수정 후 캡처 (데스크톱 터미널 보기: size-1은 데스크톱만 연 상태, size-2는 폰에서 채팅 보기를 연 뒤)

수정 후: 폰 채팅 보기를 열어도 데스크톱 크기 유지

캡처는 이번 검증용으로 생성한 테스트 세션에서 촬영했습니다. 운영 중인 터미널이나 사용자 대화는 포함하지 않았으며, 이미지와 수정 전·후 실행 기록, 전체 브라우저 테스트 로그는 포크의 별도 자료 브랜치에 보관했습니다.

검증 환경: Linux(WSL), Herdr 0.9.3, Bun 1.4.2, lockfile에 맞는 Playwright Chromium 153.

  • bun run typecheck: 통과
  • bun run build: 통과
  • bun run test:unit: 1,060건 통과, 3건 건너뜀, 실패 없음
  • server/api.contract.test.ts: 76건 통과, 실패 없음(새 계약 테스트는 원본 서버에서 실패, 수정본에서 통과 확인)
  • bun scripts/ui-regression.ts: 전체 통과(새 chat-size-regression.ts, 기존 secret-input 포함)
PASS a phone's chat lens leaves the shared grid at the desktop's 36 145
PASS the phone's terminal lens fits the grid to 36 57
PASS masked secret input: both lenses, no drafts/queue/echo, disconnect, background and cancel

전체 브라우저 테스트를 반복 실행하는 중 한 번 usage-regression.ts의 사용량 표시 단계가 시간 초과로 실패했습니다. 같은 테스트를 원본과 수정본에서 각각 두 번씩 단독 실행했을 때는 모두 통과했고, 다시 실행한 전체 테스트도 통과해 이번 변경과는 무관한 간헐적 실패로 판단했습니다.

확인해 주시면 감사하겠습니다. 필드 이름(keep_size)이나 채팅 보기의 크기 처리 방식에 선호하시는 방향이 있으면 그에 맞춰 조정하겠습니다.

@coderabbitai

coderabbitai Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

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

🧰 Additional context used
📚 Code guidelines (1)
CONTRIBUTING.md — configured

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: devswha/herdr-web-ui/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 86df3a11-cd7b-4795-902a-3f0a704de67d
📥 Commits

Reviewing files that changed from the base of the PR and between e0508bd and affcf98.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • scripts/chat-size-regression.ts
  • scripts/ui-regression.ts
  • server/api.contract.test.ts
  • server/index.ts
  • src/components/PaneTerminal.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Opening a pane in the chat lens preserves its existing terminal size, so using chat on a phone no longer resizes the pane shown on desktop.
    • Switching back to the terminal lens still fits the pane to that device’s screen.
    • macOS Cmd+Backspace now sends Ctrl+U in the live terminal while preserving the order of pending input method text.

Walkthrough

Chat-lens attachments now preserve the shared pane’s terminal size. Terminal mode can still fit the terminal to the viewing device. Socket, server, and browser regression checks cover these behaviors.

Changes

Chat Lens Terminal Size

Layer / File(s) Summary
Preserve-size attach state
shared/protocol.ts, src/lib/ws.ts, src/lib/ws.test.ts
The attach message supports keep_size. The socket stores and replays this state, clears it on resize, and provides keepSize for an existing attachment.
Server attach geometry
server/index.ts, server/api.contract.test.ts
The server preserves the pane geometry for attachments with keep_size. Integration tests check preserved geometry, normal terminal resizing, and resize ordering during attachment creation.
Chat and terminal lens behavior
src/components/PaneTerminal.tsx, scripts/chat-size-regression.ts, scripts/ui-regression.ts, CHANGELOG.md
The chat lens skips PTY resizing and adopts the latest shared geometry. The browser regression checks chat and terminal modes. The changelog records the sizing behavior and the Cmd+Backspace fix.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: devswha

Merge Risk: ⚪ Minimal · up to affcf

Chat view no longer resizes the shared terminal, and terminal view still fits the terminal to the device. Remote PCs keep the old behavior until their bridge bundle is updated. No merge-blocking risk is evident.

Security Architecture Review

Security architecture risk: 🔵 Low · up to affcf

The change reduces interference between chat and terminal users while preserving existing access and read-only controls. A bounded remaining risk concerns password-prompt recognition when the hidden terminal adopts a different screen size. No credential disclosure or privilege expansion was established, and compatibility with older remote servers remains only partially confirmed.

Retained concerns

  • Low · security · inferred: The new flow extends shared-geometry adoption to interactive chat clients without independently refreshing masked-input detection when dimensions change. Non-mirrored attach sends replay before pane-geometry; detection runs from the asynchronous PTY-write callback, whereas geometry adoption and entry into chat can resize the hidden terminal without rerunning detection. If replay is processed first and wrapping changes prompt classification, ordinary input can remain available instead of the masked-input flow until further output. A failing runtime case or disclosure was not established: the write callback may run after geometry arrives, and the server independently checks masked submissions.
Security review details

Security Blast Radius

  • observed — The affected mutable resource is the shared PTY grid and the screen interpretation of clients viewing that pane. Existing interact resize authority is pane-global rather than attachment-owned when no creation is pending; that behavior predates keep_size and is not evidence of newly granted authority.

Security Findings and Attack Paths

  • inferred — Terminal-controlled output reaches the hidden screen and its width-dependent password detector. The new geometry handoff creates a possible stale-classification window, but no complete credential-disclosure path was verified. The routed browser script is a temporary-workspace regression harness, not a new production entrypoint.

Trust Boundaries and Controls

  • observed — WebSocket upgrade retains configured access checks and same-origin enforcement. Watch-only connections are initialized as observe, cannot promote themselves to interact, and cannot resize. keep_size does not change these controls. An empty configured token remains an existing authentication exception.
  • observed — The masked-input path uses a password field without draft or queue retention, checks connection identity and feature support, and sends once. The server checks attachment readiness, authority, and the current authoritative prompt before accepting the secret. These controls limit the stale-client-prompt concern but do not independently refresh client detection.

Resilience and Maintainability Implications

  • observed — Device revocation marks the connection closing, removes pane claims, detaches resources, and closes the socket. The new pending-resize continuation checks closure, current role, and pane membership before mutating shared geometry.

Hardening Proposals

  • proposed — Make masked-input recognition explicitly follow authoritative geometry: send geometry before replay or recompute detection after adopted-grid changes. Validate a wrapped supported prompt with delayed geometry delivery and mismatched initial dimensions, including reconnect and terminal-to-chat switching.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning Issue #361 requires chat view to leave shared terminal dimensions unchanged. The new client and server path preserves the size, and the added tests cover attach, reconnect, and resize ordering. The PR… Update the remote-v11 bundle to honor keep_size, or add a compatible path that prevents chat-view attach from resizing the PTY on those hosts. Add coverage for that path.
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 8 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: chat view no longer changes the size of the shared terminal.
Description check ✅ Passed The description includes both required sections. It explains the problem and resulting behavior, and lists validation checks, results, and UI evidence.
Out of Scope Changes check ✅ Passed The protocol, server, client, regression tests, and changelog changes support issue #361. The hidden-terminal geometry handling also supports chat-view prompts without changing the shared PTY size. No…
Full details: Linked Issues check

Explanation

Issue #361 requires chat view to leave shared terminal dimensions unchanged. The new client and server path preserves the size, and the added tests cover attach, reconnect, and resize ordering. The PR description states that existing remote-v11 bundles ignore keep_size; chat attach on those hosts still changes the shared PTY size. This leaves the issue unresolved for panes served by those bundles.

Full details: Docstring Coverage

Explanation

Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 8 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • 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.

devswha and others added 3 commits October 3, 2026 16:24
# Conflicts:
#	scripts/ui-regression.ts
…aw the chat lens for the shared grid

Two cases the covered attach (keep_size) left open, found in review:

- A resize that reached the server while the pane's attachment was still
  being created was dropped. A chat lens that attached and then switched
  to the terminal lens before the terminal was looked up stayed on the
  pane's own grid under a terminal fitted to the device. The resize now
  waits for the creation.
- The terminal lens ignores pane-geometry (it drives the grid), so a
  device that entered the chat lens after another one had resized the pty
  kept its hidden screen at its own size. The last pane-geometry is kept
  and the hidden screen takes it on entering the chat lens.

The changelog entries of devswha#347 and devswha#363 were written before 0.3.44 was cut
and merged under that released version: both move to Unreleased, with
their PR links.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@devswha

devswha commented Oct 3, 2026

Copy link
Copy Markdown
Owner

Thank you for the fix and the tests. Before merging I ran an adversarial review of the diff (Codex, gpt-6-astra, low effort, read-only) and, as maintainer, pushed two follow-up fixes to this branch in affcf98. main is merged in rather than rebased.

Fixed in affcf98

  • A resize sent while the pty is still being created was dropped. A chat lens attaches with keep_size, and the user switches to the terminal lens before the terminal was looked up. The resize found no attachment yet and did nothing, and the covered attach then skipped its own resize. The pty stayed at the pane's own grid under a terminal fitted to the device. The resize handler now waits for the pending creation. New contract test: attach (keep_size) and resize in the same tick end with the resize's grid, also in the shell's stty size. It times out without the fix.
  • Entering the chat lens did not take the shared grid. The terminal lens ignores pane-geometry because it drives the grid. A desktop that entered the chat lens after a phone had resized the pty kept its hidden screen at the desktop's size. The last pane-geometry is now kept, and the hidden screen takes it on entering the chat lens. scripts/chat-size-regression.ts has a third step for this, which fails without the fix.

Not changed

  • Remote PCs. The current bridge bundle (remote-v11) ignores keep_size, as the PR already says. This is not a regression: a remote PC behaves as before until its bundle is updated. The changelog entry says so.
  • A covered or observe-only attachment that is started again (after another bridge let go, or after a herdr live handoff) reuses the size it had. The review proposed reading the pane's size again first. I measured on herdr 0.9.3 that the layout rect does not follow the attached size (it stayed 120x40 while the attach was 100x30, then 140x40, and after it left), so reading it again would not show another bridge's size and could itself resize the terminal. Left as it is.

Changelog. The entry was written before 0.3.44 was cut, so the merge left it under that released version. It is now under [Unreleased] with the PR link. The entry of #347 had the same problem on main and is moved here too.

Checked locally on this branch: generate:types --check, typecheck, build, test:unit (1076 pass), the attach-related contract tests (115 pass) and the full ui-regression.ts (pass, including the three chat-size steps).

@devswha
devswha merged commit f20acfc into devswha:main Oct 3, 2026
12 checks passed
devswha added a commit that referenced this pull request Oct 3, 2026
…the terminal's size alone (#390)

## What was wrong

#363 made the chat lens leave the shared terminal's size alone, but only
when the page opens on the pane. Picking a chat-lens pane from the
sidebar while a terminal-lens pane is open still resized it.

- A desktop shows an agent pane in its terminal lens at 38×145.
- A second, smaller window has a shell pane open in the terminal lens
and picks that agent pane, whose lens there is chat.
- The `attach` goes out without `keep_size`, and the desktop's pane is
fitted to the smaller window.

**Cause:** `src/App.tsx` set the selected pane's lens in a `useEffect`
after the selection. `PaneTerminal` attaches in the layout effect of the
render that selects the pane, so it still saw the previous pane's lens.

## Change

The lens is settled in the render that selects the pane (state adjusted
during render, keyed by what the effect depended on). What decides the
lens is unchanged: the pane's remembered choice, else Settings, else the
device.

## Checks

- New browser regression `checkPaneSwitchKeepsTerminalSize` in
`scripts/chat-size-regression.ts`, run by `scripts/ui-regression.ts`. On
`main` it fails: the picked pane's `attach` has no `keep_size`. With the
fix it passes and the pane's own `stty size` stays 38 145.
- `bun run typecheck`: pass.
- `bun run test:unit`: 1083 pass, 3 skip, 0 fail.
- `scripts/ui-regression.ts` and `scripts/file-viewer-regression.ts`:
all pass on an isolated herdr session.

## Not covered

The smaller findings from the same review of #363 are left as they are:
a `resize` that arrives while a `keep_size` attachment is still being
created is dropped, and the replay/geometry order for a client that
adopts the grid.
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.

Chat view should not resize the underlying terminal

2 participants