Skip to content

The agent that grows with you

fix(dashboard): weave resume follow-scroll into sanitizer write path + contributor mapping

Teknium7f7ca8925568
diff --git a/contributors/emails/[email protected] b/contributors/emails/[email protected]
new file mode 100644
index 00000000000..694287245e7
--- /dev/null
+++ b/contributors/emails/[email protected]
@@ -0,0 +1 @@
+VBS2004
diff --git a/web/src/pages/ChatPage.tsx b/web/src/pages/ChatPage.tsx
index c20bfb5d1de..ea6d9f36e5e 100644
--- a/web/src/pages/ChatPage.tsx
+++ b/web/src/pages/ChatPage.tsx
@@ -172,7 +172,6 @@ export default function ChatPage({ isActive = true }: { isActive?: boolean }) {
const fitRef = useRef<FitAddon | null>(null);
const wsRef = useRef<WebSocket | null>(null);
const stickToBottomRef = useRef(true);
-
// Exposed to the main metrics-sync effect so it can refit the terminal
// the moment `isActive` flips back to true (display:none → display:flex
// collapses the host's box, so ResizeObserver never fires on return).
@@ -196,8 +195,8 @@ export default function ChatPage({ isActive = true }: { isActive?: boolean }) {
// so a missing token there is expected, not an error.
const [banner, setBanner] = useState<string | null>(() =>
typeof window !== "undefined" &&
- !window.__HERMES_SESSION_TOKEN__ &&
- !window.__HERMES_AUTH_REQUIRED__
+ !window.__HERMES_SESSION_TOKEN__ &&
+ !window.__HERMES_AUTH_REQUIRED__
? "Session token unavailable. Open this page through `hermes dashboard`, not directly."
: null,
);
@@ -1049,48 +1048,49 @@ export default function ChatPage({ isActive = true }: { isActive?: boolean }) {
}
}, PTY_CONNECTING_TIMEOUT_MS);
- ws.onopen = () => {
- clearReconnectTimer();
- clearConnectingTimer();
- connectInFlightRef.current = false;
- reconnectAttemptRef.current = 0;
- setBanner(null);
- setLastCloseCode(null);
- setPtyState("open");
- blockedInputNoticeRef.current = false;
- // Connected — cancel any pending reconnect from a prior transient drop.
- if (reconnectTimerRef.current) {
- clearTimeout(reconnectTimerRef.current);
- reconnectTimerRef.current = null;
- }
- // Send the initial RESIZE immediately so Ink has *a* size to lay
- // out against on its first paint. The double-rAF block above will
- // follow up with the authoritative measurement — at worst Ink
- // reflows once after the PTY boots, which is imperceptible.
- ws.send(`\x1b[RESIZE:${term.cols};${term.rows}]`);
- // Resumed sessions replay scrollback over the socket. Start pinned to the
- // bottom so the latest output is in view; released once the user scrolls up.
- if (resumeParam) stickToBottomRef.current = true;
- // One-shot: a ?learn=<text> param (set by the Skills page "Learn a
- // skill" panel) is typed into the composer as a /learn command once the
- // PTY is up. /learn resolves via command.dispatch → a normal agent turn,
- // so this reuses the existing composer path — no special PTY protocol.
- const learnSeed = searchParams.get("learn");
- if (learnSeed) {
- const next = new URLSearchParams(searchParams);
- next.delete("learn");
- setSearchParams(next, { replace: true });
- const cmd = `/learn ${learnSeed}`.trim();
- // Delay so Ink's composer has mounted and grabbed focus before input.
- setTimeout(() => {
- try {
- wsRef.current?.send(cmd + "\r");
- } catch {
- /* PTY not ready / closed — user can retype */
- }
- }, 800);
- }
- };
+ ws.onopen = () => {
+ clearReconnectTimer();
+ clearConnectingTimer();
+ connectInFlightRef.current = false;
+ reconnectAttemptRef.current = 0;
+ setBanner(null);
+ setLastCloseCode(null);
+ setPtyState("open");
+ blockedInputNoticeRef.current = false;
+ // Connected — cancel any pending reconnect from a prior transient drop.
+ if (reconnectTimerRef.current) {
+ clearTimeout(reconnectTimerRef.current);
+ reconnectTimerRef.current = null;
+ }
+ // Send the initial RESIZE immediately so Ink has *a* size to lay
+ // out against on its first paint. The double-rAF block above will
+ // follow up with the authoritative measurement — at worst Ink
+ // reflows once after the PTY boots, which is imperceptible.
+ ws.send(`\x1b[RESIZE:${term.cols};${term.rows}]`);
+ // Resumed sessions replay scrollback over the socket. Start pinned to
+ // the bottom so the latest output is in view; released once the user
+ // scrolls up (#59591).
+ if (resumeParam) stickToBottomRef.current = true;
+ // One-shot: a ?learn=<text> param (set by the Skills page "Learn a
+ // skill" panel) is typed into the composer as a /learn command once the
+ // PTY is up. /learn resolves via command.dispatch → a normal agent turn,
+ // so this reuses the existing composer path — no special PTY protocol.
+ const learnSeed = searchParams.get("learn");
+ if (learnSeed) {
+ const next = new URLSearchParams(searchParams);
+ next.delete("learn");
+ setSearchParams(next, { replace: true });
+ const cmd = `/learn ${learnSeed}`.trim();
+ // Delay so Ink's composer has mounted and grabbed focus before input.
+ setTimeout(() => {
+ try {
+ wsRef.current?.send(cmd + "\r");
+ } catch {
+ /* PTY not ready / closed — user can retype */
+ }
+ }, 800);
+ }
+ };
// Session resume: Ink's two-pass virtual scroll floods the PTY with
// erase codes and blank-line bursts while replaying a long session.
@@ -1166,23 +1166,84 @@ export default function ChatPage({ isActive = true }: { isActive?: boolean }) {
? `Auth failed (${ev.reason}). Reload to refresh the session.`
: "Auth failed. Reload the page to refresh the session token.",
);
+ return;
+ }
+ if (ev.code === 4403) {
+ // Host/Origin mismatch (DNS-rebinding guard).
+ setPtyState("closed");
+ setBanner(
+ ev.reason
+ ? `Refused: ${ev.reason}.`
+ : "Refused: request host/origin doesn't match the dashboard.",
+ );
+ return;
+ }
+ if (ev.code === 4404) {
+ setPtyState("closed");
+ setBanner(
+ ev.reason
+ ? `Chat websocket unavailable: ${ev.reason}.`
+ : "Chat websocket unavailable on this server.",
+ );
+ return;
+ }
+ if (ev.code === 4408) {
+ setPtyState("closed");
+ setBanner(
+ ev.reason
+ ? `Refused: ${ev.reason}.`
+ : "Refused: your client isn't permitted (server bound to localhost only).",
+ );
+ return;
+ }
+ if (ev.code === 1011) {
+ // Server already wrote an ANSI error frame.
+ setPtyState("closed");
+ return;
+ }
+ // Keep-alive close-code contract (web_server.pty_ws + pty_session):
+ // 4410 = the agent PROCESS exited (real end) → restart affordance.
+ // 4409 = superseded by a newer tab attaching the same token → stay quiet.
+ if (ev.code === 4410) {
+ term.write(`\r\n\x1b[90m[session ended]\x1b[0m\r\n`);
setPtyState("ended");
- };
+ return;
+ }
+ if (ev.code === 4409) {
+ setPtyState("closed");
+ return;
+ }
+ if (!ev.wasClean || ev.code === 1001 || ev.code === 1006) {
+ // Transient transport drop (refresh, sleep/wake, signal loss).
+ // Reconnect with backoff; the same ?attach= token reattaches to
+ // the still-living PTY, so the conversation continues in place.
+ scheduleReconnect(ev.code);
+ return;
+ }
+ // Normal/clean exit: the agent process ended (e.g. the user typed
+ // `/exit`, or started a new session). NS-504: surface an explicit
+ // restart affordance instead of leaving a dead terminal that only a
+ // full page refresh could recover.
+ term.write(
+ `\r\n\x1b[90m[session ended (code ${ev.code})]\x1b[0m\r\n`,
+ );
+ setPtyState("ended");
+ };
- // Keystrokes → PTY.
- //
- // IMPORTANT:
- // The embedded web chat has occasionally surfaced stray letters/digits
- // in the input line after a turn completes. The most likely culprit is
- // browser-side terminal control traffic being forwarded back into the
- // PTY as if it were user text. SGR mouse tracking is the highest-risk
- // path here: xterm.js emits raw CSI reports (`\x1b[<...`) that look like
- // ordinary bytes to the backend.
- //
- // For the browser embed we prefer input stability over terminal-style
- // mouse reporting, so we drop SGR mouse reports entirely instead of
- // forwarding them into Hermes. Keyboard input, paste, and resize still
- // behave normally.
+ // Keystrokes → PTY.
+ //
+ // IMPORTANT:
+ // The embedded web chat has occasionally surfaced stray letters/digits
+ // in the input line after a turn completes. The most likely culprit is
+ // browser-side terminal control traffic being forwarded back into the
+ // PTY as if it were user text. SGR mouse tracking is the highest-risk
+ // path here: xterm.js emits raw CSI reports (`\x1b[<...`) that look like
+ // ordinary bytes to the backend.
+ //
+ // For the browser embed we prefer input stability over terminal-style
+ // mouse reporting, so we drop SGR mouse reports entirely instead of
+ // forwarding them into Hermes. Keyboard input, paste, and resize still
+ // behave normally.
// eslint-disable-next-line no-control-regex -- intentional ESC byte in xterm SGR mouse report parser
const SGR_MOUSE_RE = /^\x1b\[<(\d+);(\d+);(\d+)([Mm])$/;
onDataDisposable = term.onData((data) => {
@@ -1225,7 +1286,8 @@ export default function ChatPage({ isActive = true }: { isActive?: boolean }) {
});
// Release the stick-to-bottom pin the moment the user scrolls up, so
- // we only auto-follow during the resume replay — not their manual review.
+ // we only auto-follow during the resume replay — not their manual
+ // review of the backlog (#59591).
onScrollDisposable = term.onScroll(() => {
stickToBottomRef.current = isViewportPinnedToBottom(term.buffer.active);
});
@@ -1410,8 +1472,9 @@ export default function ChatPage({ isActive = true }: { isActive?: boolean }) {
// descendants below those layers (see Toast.tsx).
const reconnectBanner =
ptyState === "reconnecting"
- ? `Chat connection interrupted${lastCloseCode ? ` (code ${lastCloseCode})` : ""
- }. Reconnecting...`
+ ? `Chat connection interrupted${
+ lastCloseCode ? ` (code ${lastCloseCode})` : ""
+ }. Reconnecting...`
: null;
const visibleBanner = banner ?? reconnectBanner;
const showReconnectOverlay =