Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 6 additions & 2 deletions src/lib/components/WhatsNewModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
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 {
version: string;
date: string;
changes: Array<{ type: string; text: string }>;
imageTag?: string;
comingSoon?: boolean;
}

interface Props {
Expand All @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/lib/data/changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
{ "type": "fix", "text": "stop password managers from offering to save stack secret env-var fields (#1517)" },
{ "type": "fix", "text": "repository stats no longer fail on the backups screen (#1561)" },
{ "type": "fix", "text": "dashboard image disk usage no longer counts shared layers multiple times (PR#1461, @omggga)" },
{ "type": "feature", "text": "add a docker attach terminal mode (#1078, PR#1377, @ivanjx)" }
{ "type": "feature", "text": "add a docker attach terminal mode (#1078, PR#1377, @ivanjx)" },
{ "type": "fix", "text": "stack action buttons show for stopped and freshly created stacks, regression (#1565)" },
{ "type": "fix", "text": "the update dialog no longer shows an unreleased version as the target (#1566)" }
],
"imageTag": "fnsys/dockhand:v1.0.48"
},
Expand Down
15 changes: 15 additions & 0 deletions src/lib/server/docker-stream-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
33 changes: 33 additions & 0 deletions src/lib/server/git-deletions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,39 @@ export function buildNextManifest(newCommit: string, newFiles: Record<string, st
return { commit: newCommit, files: { ...newFiles } };
}

/** Compare two commit refs by their 7-char short form (the DB stores 7-char,
* git returns 40-char); null/empty never matches. */
function sameCommit(a: string | null | undefined, b: string | null | undefined): boolean {
if (!a || !b) return false;
return a.substring(0, 7) === b.substring(0, 7);
}

/**
* Whether a sync can skip re-hashing the whole compose tree. Skipping is safe
* ONLY when the git diff proved no compose-dir change AND the diff was taken
* against the SAME commit the manifest was built at. The second condition is
* load-bearing: a bare Sync advances the diff baseline (lastCommit) without
* persisting the manifest (only a deploy does), so `changedInComposeDir===false`
* alone does NOT imply the on-disk tree still matches the manifest. When the
* baselines match and a prior manifest exists, nothing was added/modified/
* deleted, so the manifest carries forward verbatim and the unconditional
* full re-hash (which blocks the event loop on a large tree) is skipped. Any
* mismatch, undefined change state (new clone / diff failed), or empty manifest
* falls back to a full re-hash - the safe default that self-corrects drift.
*/
export function canSkipTreeRehash(
changedInComposeDir: boolean | undefined,
manifestSize: number,
manifestCommit: string | null | undefined,
diffBaselineCommit: string | null | undefined
): boolean {
return (
changedInComposeDir === false &&
manifestSize > 0 &&
sameCommit(manifestCommit, diffBaselineCommit)
);
}

// =============================================================================
// Sync summary (per-file status table)
// =============================================================================
Expand Down
43 changes: 37 additions & 6 deletions src/lib/server/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
hashDirFiles,
computeDeletions,
buildNextManifest,
canSkipTreeRehash,
buildSyncChangeSummary,
formatChangeTable,
skipReasonMessage,
Expand Down Expand Up @@ -470,13 +471,34 @@ async function computeSyncDeletionPlan(options: {
composeDir: string; // absolute path inside the clone
composeFileName: string | undefined; // compose file relative to composeDir
rawManifest: string | null | undefined;
// When the caller's git diff proved NOTHING changed in the compose dir between
// the deployed commit and the new clone, hashing the whole tree is pure waste:
// no file changed, so none was deleted. Large trees (tens of thousands of files)
// otherwise block the event loop re-hashing unchanged files on every deploy.
// undefined = unknown -> hash (safe default; e.g. new clone / diff failed).
changedInComposeDir?: boolean;
// The commit the git diff was taken against. Skipping is only safe when this
// equals the manifest's own commit; otherwise the diff baseline has drifted
// from the manifest (e.g. a bare Sync advanced lastCommit without persisting
// the manifest) and a full re-hash is required to stay correct.
diffBaselineCommit?: string | null;
}): Promise<{ plan: DeletionPlan; newFiles: Record<string, string>; previousManifest: SyncManifest }> {
const { logPrefix, composeDir, composeFileName, rawManifest } = options;
const { logPrefix, composeDir, composeFileName, rawManifest, changedInComposeDir, diffBaselineCommit } = options;

const previousManifest = parseManifest(rawManifest);
const manifestSize = Object.keys(previousManifest.files).length;

// Fast path: git proved no compose-dir file changed, the diff baseline matches
// the manifest's commit, and we have a prior manifest. Nothing can have been
// added/modified/deleted, so carry the manifest forward verbatim instead of
// re-hashing the entire tree.
if (canSkipTreeRehash(changedInComposeDir, manifestSize, previousManifest.commit, diffBaselineCommit)) {
console.log(`${logPrefix} Deletion sync: no compose-dir changes, skipping full re-hash of ${manifestSize} file(s)`);
return { plan: { toDelete: [], skipped: [] }, newFiles: { ...previousManifest.files }, previousManifest };
}

const newFiles = hashDirFiles(composeDir);

const manifestSize = Object.keys(previousManifest.files).length;
console.log(`${logPrefix} Deletion sync: manifest has ${manifestSize} file(s)${manifestSize === 0 ? ' (first sync — nothing will be deleted)' : ''}`);

// First sync / legacy manifest: nothing was recorded, so nothing can be deleted
Expand Down Expand Up @@ -1236,12 +1258,17 @@ export async function syncGitStack(stackId: number): Promise<SyncResult> {
console.log(`${logPrefix} No env file path configured`);
}

// Deletion sync (#966): manifest-vs-clone deletion plan
// Deletion sync (#966): manifest-vs-clone deletion plan.
// `updated` is the dir-scoped git-diff result (false when the commit didn't
// change OR no compose-dir file changed) - lets the plan skip re-hashing an
// unchanged tree.
const deletionData = await computeSyncDeletionPlan({
logPrefix,
composeDir,
composeFileName,
rawManifest: gitStack.syncedFiles
rawManifest: gitStack.syncedFiles,
changedInComposeDir: updated,
diffBaselineCommit: previousCommit
});

// Update git stack status
Expand Down Expand Up @@ -1875,13 +1902,17 @@ export async function deployGitStackWithProgress(
}
}

// Deletion sync (#966): manifest-vs-clone deletion plan
// Deletion sync (#966): manifest-vs-clone deletion plan. `updated` is the
// dir-scoped git-diff result; when nothing changed the plan skips re-hashing
// the whole tree.
const logPrefix = `[Stack:${gitStack.stackName}]`;
const deletionData = await computeSyncDeletionPlan({
logPrefix,
composeDir,
composeFileName: progressComposeFileName,
rawManifest: gitStack.syncedFiles
rawManifest: gitStack.syncedFiles,
changedInComposeDir: updated,
diffBaselineCommit: previousCommit
});

// Update git stack status
Expand Down
13 changes: 13 additions & 0 deletions src/lib/utils/changelog-filter.ts
Original file line number Diff line number Diff line change
@@ -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<T extends ChangelogEntryLike>(entries: T[]): T[] {
return entries.filter((e) => !e.comingSoon);
}
11 changes: 11 additions & 0 deletions src/lib/utils/stack-actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Whether the stack row's management actions (edit / logs / start / restart /
// stop) should render. They show for a stack in ANY state EXCEPT a git stack that
// has not been deployed yet - that one shows only its dedicated deploy button, so
// the management actions would be redundant. A non-git stack that is stopped or
// freshly created still needs its Start button, so deploy status must not hide the
// management actions. `status` is the raw stack status; a git stack that has never
// deployed is raw "created" (shown as "not deployed" elsewhere).

export function showsManagementActions(sourceType: string | undefined, status: string): boolean {
return !(sourceType === 'git' && status === 'created');
}
6 changes: 5 additions & 1 deletion src/routes/settings/about/AboutTab.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
// Trigger rebuild for debug logging changes
import * as Card from '$lib/components/ui/card';
import { releasedEntries } from '$lib/utils/changelog-filter';
import { Badge } from '$lib/components/ui/badge';
import { Button } from '$lib/components/ui/button';
import { Input } from '$lib/components/ui/input';
Expand Down Expand Up @@ -33,6 +34,7 @@
date: string;
changes: ChangelogChange[];
imageTag: string;
comingSoon?: boolean;
}

let dependencies = $state<Dependency[]>([]);
Expand Down Expand Up @@ -84,7 +86,9 @@
try {
const res = await fetch('/api/changelog');
if (!res.ok) throw new Error('Failed to fetch changelog');
changelog = await res.json();
// Shipped releases only: an unreleased (coming-soon) entry must not show as
// the "Latest" version.
changelog = releasedEntries(await res.json());
} catch (e) {
changelogError = e instanceof Error ? e.message : 'Unknown error';
} finally {
Expand Down
6 changes: 5 additions & 1 deletion src/routes/settings/about/SelfUpdateDialog.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import * as Dialog from '$lib/components/ui/dialog';
import { releasedEntries } from '$lib/utils/changelog-filter';
import { Button } from '$lib/components/ui/button';
import { Badge } from '$lib/components/ui/badge';
import { Progress } from '$lib/components/ui/progress';
Expand All @@ -12,6 +13,7 @@
date: string;
changes: Array<{ type: string; text: string }>;
imageTag?: string;
comingSoon?: boolean;
}

interface Props {
Expand Down Expand Up @@ -159,7 +161,9 @@
);

if (response.ok) {
const changelog: ChangelogEntry[] = await response.json();
// Drop coming-soon (unreleased) entries: the update only ever goes to a
// released version, so an unreleased changelog entry must not appear here.
const changelog: ChangelogEntry[] = releasedEntries(await response.json());
if (currentVersion && changelog.length > 0) {
const newer = changelog.filter(entry => compareVersions(entry.version, currentVersion) > 0);
releaseNotes = newer.length > 0 ? newer : changelog.slice(0, 1);
Expand Down
3 changes: 2 additions & 1 deletion src/routes/stacks/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import ContainerIcon from '$lib/components/ContainerIcon.svelte';
import BatchOperationModal from '$lib/components/BatchOperationModal.svelte';
import type { ComposeStackInfo, ContainerStats, StackContainer } from '$lib/types';
import { showsManagementActions } from '$lib/utils/stack-actions';
import StackModal from './StackModal.svelte';
import DeleteStackModal from './DeleteStackModal.svelte';
import ComposeOutputModal from './ComposeOutputModal.svelte';
Expand Down Expand Up @@ -2180,7 +2181,7 @@
{/snippet}
</GitDeployProgressPopover>
{/if}
{#if stack.status !== 'not deployed' && stack.status !== 'created'}
{#if showsManagementActions(source.sourceType, stack.status)}
{#if $canAccess('stacks', 'edit')}
{#if source.sourceType === 'git' && source.gitStack}
<button
Expand Down
31 changes: 31 additions & 0 deletions tests/changelog-filter.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { describe, test, expect } from 'bun:test';
import { releasedEntries } from '../src/lib/utils/changelog-filter';

describe('releasedEntries', () => {
test('drops coming-soon (unreleased) entries', () => {
const entries = [
{ version: '1.0.48', comingSoon: true },
{ version: '1.0.47' },
{ version: '1.0.46', comingSoon: false }
];
expect(releasedEntries(entries).map((e) => e.version)).toEqual(['1.0.47', '1.0.46']);
});

test('keeps everything when nothing is coming-soon', () => {
const entries = [{ version: '1.0.47' }, { version: '1.0.46' }];
expect(releasedEntries(entries)).toHaveLength(2);
});

test('empty in, empty out', () => {
expect(releasedEntries([])).toEqual([]);
});

test('the top entry being coming-soon does not become the latest released', () => {
// The regression case: user on an older build, changelog[0] is an unreleased entry.
const entries = [
{ version: '1.0.48', comingSoon: true },
{ version: '1.0.47' }
];
expect(releasedEntries(entries)[0].version).toBe('1.0.47');
});
});
32 changes: 31 additions & 1 deletion tests/docker-stream-core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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');
});
});
Loading
Loading