From 6d0e375943ec7807f236aee4d48b9af1d05bc84e Mon Sep 17 00:00:00 2001 From: Jarek Krochmalski Date: Mon, 14 Sep 2026 05:25:04 +0200 Subject: [PATCH 1/5] add a docker attach terminal mode --- server.js | 14 ++++++++++-- src/lib/server/docker-stream-core.ts | 15 +++++++++++++ tests/docker-stream-core.test.ts | 32 +++++++++++++++++++++++++++- vite.config.ts | 9 +++++--- 4 files changed, 64 insertions(+), 6 deletions(-) diff --git a/server.js b/server.js index b9bdb00a3..97678f406 100644 --- a/server.js +++ b/server.js @@ -267,6 +267,13 @@ function buildDockerStreamRequest(path, target, body = '') { ); } +// Mirrors translateAttachInput in docker-stream-core.ts: for non-TTY attach map a lone +// \r (xterm Enter) to \n (no pty to do it); exec / TTY attach pass through. Keep in sync. +function translateAttachInput(data, nonTtyAttach) { + if (!nonTtyAttach) return data; + return data.replace(/\r(?!\n)/g, '\n'); +} + function createDockerStreamState(multiplexed = false) { return { headersStripped: false, @@ -538,7 +545,8 @@ async function handleTerminalConnection(ws, url, connId) { try { const msg = JSON.parse(data.toString()); if (msg.type === 'input' && msg.data) { - dockerStream.write(msg.data); + // Non-TTY attach has no pty to convert Enter (\r) to a newline. + dockerStream.write(translateAttachInput(msg.data, multiplexed)); } else if (msg.type === 'resize' && msg.cols && msg.rows) { if (mode === 'attach') { if (typeof globalThis.__terminalResizeContainer === 'function') { @@ -644,10 +652,12 @@ function handleEdgeExec(ws, connId, containerId, shell, user, environmentId, mod try { const msg = JSON.parse(data.toString()); if (msg.type === 'input' && msg.data) { + // Non-TTY attach has no pty to convert Enter (\r) to a newline. + const inputData = translateAttachInput(msg.data, attach && multiplexed); const inputMsg = JSON.stringify({ type: 'exec_input', execId, - data: Buffer.from(msg.data).toString('base64') + data: Buffer.from(inputData).toString('base64') }); globalThis.__hawserSendMessage(environmentId, inputMsg); } else if (msg.type === 'resize' && msg.cols && msg.rows) { diff --git a/src/lib/server/docker-stream-core.ts b/src/lib/server/docker-stream-core.ts index f14d329d5..fb505c12a 100644 --- a/src/lib/server/docker-stream-core.ts +++ b/src/lib/server/docker-stream-core.ts @@ -136,3 +136,18 @@ export function processDockerStreamChunk(data: Buffer | Uint8Array | string, sta return output; } + +/** + * Translate terminal input before writing it to the container's stdin. xterm sends a + * carriage return (\r) when Enter is pressed; with a TTY the pty converts that to a + * newline, but attach to a container started without a tty has no pty, so a shell + * `read` never sees an end-of-line and the session looks unresponsive. When + * `nonTtyAttach` is set, map a lone \r to \n (leaving an existing \r\n alone) so Enter + * ends a line. For exec and TTY attach (nonTtyAttach false) the input passes through + * verbatim. The gate lives here so it is unit-tested alongside the transform, rather + * than only in the inline call-site ternaries. + */ +export function translateAttachInput(data: string, nonTtyAttach: boolean): string { + if (!nonTtyAttach) return data; + return data.replace(/\r(?!\n)/g, '\n'); +} diff --git a/tests/docker-stream-core.test.ts b/tests/docker-stream-core.test.ts index f67cfb01b..c7a749fea 100644 --- a/tests/docker-stream-core.test.ts +++ b/tests/docker-stream-core.test.ts @@ -3,7 +3,8 @@ import { describe, expect, test } from 'bun:test'; import { createDockerStreamState, decodeChunkedDockerBody, - processDockerStreamChunk + processDockerStreamChunk, + translateAttachInput } from '../src/lib/server/docker-stream-core'; const HTTP_HEAD = 'HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n\r\n'; @@ -157,3 +158,32 @@ describe('processDockerStreamChunk - edge attach seeding (headersStripped, no HT expect(processDockerStreamChunk(f.subarray(4), st).join('')).toBe('split'); }); }); + +describe('translateAttachInput - CR to LF gated on non-TTY attach', () => { + // nonTtyAttach=true: attach to a container with no pty (the CR->LF case). + test('maps a lone carriage return (xterm Enter) to a newline', () => { + expect(translateAttachInput('ls\r', true)).toBe('ls\n'); + }); + + test('leaves an existing CRLF alone (no doubled newline)', () => { + expect(translateAttachInput('a\r\nb', true)).toBe('a\r\nb'); + }); + + test('translates multiple lone CRs', () => { + expect(translateAttachInput('one\rtwo\rthree\r', true)).toBe('one\ntwo\nthree\n'); + }); + + test('passes plain text and bare LF through unchanged', () => { + expect(translateAttachInput('hello\n', true)).toBe('hello\n'); + expect(translateAttachInput('no-eol', true)).toBe('no-eol'); + }); + + // nonTtyAttach=false: exec or TTY attach - input MUST pass through verbatim, + // including a lone \r (the pty/exec handles line-ending itself). This guards the + // gate: a flipped call site would corrupt exec keystrokes and this would fail. + test('passes a lone CR through UNCHANGED for exec / TTY attach', () => { + expect(translateAttachInput('ls\r', false)).toBe('ls\r'); + expect(translateAttachInput('\r', false)).toBe('\r'); + expect(translateAttachInput('a\rb\rc', false)).toBe('a\rb\rc'); + }); +}); diff --git a/vite.config.ts b/vite.config.ts index 53ba8b575..247cdac22 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -184,7 +184,7 @@ function buildDockerStreamHttpRequest(path: string, target: DockerTarget, body = // ============ Stream Processing ============ -import { createDockerStreamState, processDockerStreamChunk, type DockerStreamState } from './src/lib/server/docker-stream-core'; +import { createDockerStreamState, processDockerStreamChunk, translateAttachInput, type DockerStreamState } from './src/lib/server/docker-stream-core'; // ============ Hawser Edge Exec Messages ============ @@ -764,7 +764,9 @@ function webSocketPlugin(): Plugin { try { const msg = JSON.parse(message.toString()); if (msg.type === 'input') { - conn.ws.send(JSON.stringify(createExecInputMessage(edgeExecId, msg.data))); + // Non-TTY attach has no pty to convert Enter (\r) to a newline. + const inputData = translateAttachInput(msg.data, !!session.streamState?.multiplexed); + conn.ws.send(JSON.stringify(createExecInputMessage(edgeExecId, inputData))); } else if (msg.type === 'resize') { conn.ws.send(JSON.stringify(createExecResizeMessage(edgeExecId, msg.cols, msg.rows))); } @@ -785,7 +787,8 @@ function webSocketPlugin(): Plugin { try { const msg = JSON.parse(message.toString()); if (msg.type === 'input' && d.stream) { - d.stream.write(msg.data); + // Non-TTY attach has no pty to convert Enter (\r) to a newline. + d.stream.write(translateAttachInput(msg.data, d.mode === 'attach' && d.state.multiplexed)); } else if (msg.type === 'resize') { if (d.mode === 'attach') { resizeContainerForWs(d.containerId, msg.cols, msg.rows, d.target); From 067318887f5cb1975cce20708e3e621873ed219c Mon Sep 17 00:00:00 2001 From: Jarek Krochmalski Date: Mon, 14 Sep 2026 05:25:04 +0200 Subject: [PATCH 2/5] the update dialog no longer shows an unreleased version as the target --- src/lib/components/WhatsNewModal.svelte | 8 +++-- src/lib/utils/changelog-filter.ts | 13 ++++++++ src/routes/settings/about/AboutTab.svelte | 6 +++- .../settings/about/SelfUpdateDialog.svelte | 6 +++- tests/changelog-filter.test.ts | 31 +++++++++++++++++++ 5 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 src/lib/utils/changelog-filter.ts create mode 100644 tests/changelog-filter.test.ts diff --git a/src/lib/components/WhatsNewModal.svelte b/src/lib/components/WhatsNewModal.svelte index f9e044ace..7bc108859 100644 --- a/src/lib/components/WhatsNewModal.svelte +++ b/src/lib/components/WhatsNewModal.svelte @@ -3,6 +3,7 @@ import { Button } from '$lib/components/ui/button'; import { Sparkles, Bug, Zap, CheckCircle, ScrollText } from 'lucide-svelte'; import { compareVersions } from '$lib/utils/version'; + import { releasedEntries } from '$lib/utils/changelog-filter'; import ChangelogText from '$lib/components/ChangelogText.svelte'; interface ChangelogEntry { @@ -10,6 +11,7 @@ date: string; changes: Array<{ type: string; text: string }>; imageTag?: string; + comingSoon?: boolean; } interface Props { @@ -22,9 +24,11 @@ let { open = $bindable(), version, changelog, lastSeenVersion, onDismiss }: Props = $props(); - // Filter to show versions newer than lastSeenVersion, limited to 3 most recent + // Versions newer than lastSeenVersion, 3 most recent. Coming-soon (unreleased) + // entries are excluded: the user is on a released build, so an unreleased version + // must never appear as something they "missed". const missedReleases = $derived( - changelog + releasedEntries(changelog) .filter((r) => { if (!lastSeenVersion) return true; // Show all if first time return compareVersions(r.version, lastSeenVersion.replace(/^v/, '')) > 0; diff --git a/src/lib/utils/changelog-filter.ts b/src/lib/utils/changelog-filter.ts new file mode 100644 index 000000000..c173fcb13 --- /dev/null +++ b/src/lib/utils/changelog-filter.ts @@ -0,0 +1,13 @@ +// A coming-soon changelog entry (comingSoon: true) is an unreleased placeholder +// used for the webpage's "what's next" section. It must never appear in the app's +// released-version surfaces (About list, What's New, self-update release notes), +// which otherwise render it as the latest shipped version. + +export interface ChangelogEntryLike { + comingSoon?: boolean; +} + +/** Drop unreleased (comingSoon) entries, keeping only shipped releases. */ +export function releasedEntries(entries: T[]): T[] { + return entries.filter((e) => !e.comingSoon); +} diff --git a/src/routes/settings/about/AboutTab.svelte b/src/routes/settings/about/AboutTab.svelte index 32ff1a377..f52dbf812 100644 --- a/src/routes/settings/about/AboutTab.svelte +++ b/src/routes/settings/about/AboutTab.svelte @@ -1,6 +1,7 @@