Skip to content

fix(mocactl): redraw history on resize; cap live region to the window - #651

Merged
pdettori merged 1 commit into
rossoctl:mainfrom
esnible:fix/mocactl-resize-596
Oct 28, 2026
Merged

pdettori merged 1 commit into
rossoctl:mainfrom
esnible:fix/mocactl-resize-596

Conversation

@esnible

@esnible esnible commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Fixes #596.

What changes

Redraw on resize (packages/mocactl/src/app.tsx). History printed through <Static> is wrapped at the width it was printed at, and nothing reprinted it when the width changed. The terminal then re-wrapped it on its own, which left stray and duplicated box borders. Now a width change waits RESIZE_SETTLE_MS (100 ms) for the resize to finish and then calls the existing redraw() once. A drag that fires many resize events gets one redraw, and the first render is skipped. A height change alone doesn't reprint history, because history is wrapped by width only.

Cap the live region to the window (packages/mocactl/src/views/Chat.tsx). A streaming reply could make the live region taller than the window. Ink then clears and repaints the screen on every frame, so the input box jumped and flickered. The live region is now capped at rows - 1 lines, using Ink 8's maxHeight and overflowY="hidden". An overlong reply is cut off at the top so its newest lines stay in view. The overlay, input box and status line never shrink. The full reply still reaches history through <Static> once it settles.

Out of scope: pinning the input box to the bottom when the transcript is short. That needs a full-screen layout that replaces the print-once history design (spec §6.1), as the issue says.

Tests

  • test/chat.test.tsx: a 50-line streaming reply with rows=10 renders in at most 9 live lines, ends with the input box's bottom border and then the status line, and shows the newest reply line.
  • test/app.test.tsx: mountInteractive gains a resize() helper. Three resizes, each half the settle delay apart, clear nothing while they're arriving, then clear the screen exactly once after the delay and reprint the history. The test fails if the debounce's clearTimeout is removed.
  • With the fixes temporarily reverted, both new tests fail.
  • mocactl pnpm typecheck and make lint pass, and Prettier finds nothing to change.
  • The full mocactl suite has 6 failing tests, and 6 also fail on main without this change. They're waitFor timeouts, and the failing tests differ from run to run, so they look like timing flakes under load. The UI test files touched here (app, chat, overlays) pass when run on their own: 84/84.

Checked by hand in a real terminal: resizing the window and streaming a long reply both behave correctly.

🤖 Assisted-By Claude Code

@esnible
esnible requested a review from pdettori as a code owner October 28, 2026 14:46
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Oct 28, 2026
Settled history is printed once through <Static>, wrapped at the width it
was printed at; when the terminal width changed nothing re-printed it, so
the terminal's own re-wrap left stray and duplicated box borders. A width
change now waits for the resize to settle (RESIZE_SETTLE_MS) and calls the
existing redraw() once.

A streaming reply could grow the live region past the window height, which
makes Ink clear and repaint the screen on every frame, so the input box
jumped and flickered. The live region is now capped a row short of the
window: an overlong reply is clipped from the top so its newest lines stay
in view, and the overlay, input box and status line never shrink. The full
reply still reaches history through <Static> once it settles.

Pinning the input box to the bottom with a short transcript is left out:
it needs a full-screen layout that replaces the print-once history design
(spec §6.1).

Fixes rossoctl#596

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Ed Snible <[email protected]>
@esnible
esnible force-pushed the fix/mocactl-resize-596 branch from 20f1f81 to 5e17c13 Compare October 28, 2026 14:54
@esnible esnible changed the title fix(mocactl): redraw history on resize; cap the live region to the window fix(mocactl): redraw history on resize; cap live region to the window Oct 28, 2026

@huang195 huang195 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The resize redraw is a clean debounce on the existing redraw(). It doesn't fire on the first render, and the cleanup cancels the timer on each new resize and on unmount. The rows - 1 cap matches Ink 8's rule for switching to full repaints (outputHeight >= rows). With overflowY="hidden" and flex-end, the newest lines stay in view, and the non-shrinking wrappers stop Yoga from squashing blocks. Both tests target the right behavior. LGTM.

One thing to be aware of, not blocking: CLEAR_SCREEN includes \e[3J, so every width change now clears the scrollback, including shell history from before mocactl started. Theme changes and the editor already did this. Resizing is a passive action, though, so users will hit it more often.

Author: esnible (MEMBER — maintainer)
Areas reviewed: TypeScript/React (Ink UI), tests
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, signed off
CI status: passing

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both fixes look right. The resize debounce is correct: bursts restart the timer, a return to the printed width cancels it, and the first render is skipped. The tests fail with the fix reverted, which is good. One suggestion inline: the outer maxHeight clips the overlay, input box and status line once they outgrow the window by themselves. That happens with Help in a session at 80×24. The L62-63 comment says Ink falls back to full repaints there instead.

Author: esnible (MEMBER, maintainer) · Areas: mocactl TUI (Ink), tests · Agent/IDE config: none · Commits: 1, signed-off · CI: green (k8s-kind-e2e pending at review time)

{overlay ? (
<Box marginTop={1} flexDirection="column">
{overlay}
<Box flexDirection="column" maxHeight={Math.max(1, rows - 1)}>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: The outer maxHeight also applies when the flexShrink={0} children overflow on their own, and Ink then clips them rather than falling back to full repaints, so the comment at L62-63 is inaccurate. With Ink 8.0.0 (the lockfile version) the frame is the box's computed height, and rows past it are dropped.

That's reachable at the default 80×24 in a session: Help is the title, 16 commands, a blank line and INPUT_KEYS, which wraps to 2 lines at 80 columns. That's 20 lines, plus marginTop 1, the input box 3 and the status line 1, which makes 25 rows against a cap of 23. I rendered that tree in isolation, and the last two lines were ╭───╮ / │ type a message │: the bottom border and the status line are gone. A multi-line draft in the input box, or a short window (rows ≤ ~6), hits the same thing.

One option is to put the cap only on the live box, sized from what's left: measure the fixed tail with measureElement and set maxHeight={Math.max(0, rows - 1 - tailHeight)} on the clipped box. You could also drop the outer cap while an overlay is open. Either way, a test with an overlay taller than rows (asserting the status line is still the last line) would pin it.

@pdettori
pdettori merged commit 2f9eed2 into rossoctl:main Oct 28, 2026
15 checks passed
@esnible
esnible deleted the fix/mocactl-resize-596 branch October 28, 2026 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mocactl: input box not anchored to bottom; window resize corrupts the TUI

4 participants