feat(terminal): refactor runtime and add mobile workspace (#2280)

Replace the legacy terminal flow with a shared authenticated WebSocket
runtime used across web, desktop, relay, and mobile surfaces.

- introduce the v3 terminal protocol with scoped attachments, snapshots,
  ordered output, bounded replay history, reconnects, and explicit lifecycle
- harden PTY creation, restart, resize, close, force-kill, idle cleanup,
  shell selection, login mode, environment sanitization, and appearance sync
- add runtime-aware terminal APIs with relay authentication and Electron parity
- add a fullscreen mobile terminal workspace with touch scrolling,
  long-press selection, safe-area controls, quick keys, and Ctrl/Alt input
- add terminal selection attachments, preview detection, project actions,
  shell settings, and localized UI
- harden Ghostty rendering, resize recovery, Unicode handling, block
  characters, line height, and stale-row behavior
- remove the obsolete terminal SSE path and update reverse-proxy guidance
- expand terminal runtime, transport, input, selection, and store coverage
- avoid duplicate web builds when preparing mobile assets in root CI builds
This commit is contained in:
Bohdan Triapitsyn
2026-07-17 13:17:21 +03:00
committed by GitHub
parent f5b4a267c0
commit d4a8c4d2e1
103 changed files with 4085 additions and 4496 deletions
@@ -0,0 +1,28 @@
import { describe, expect, test } from 'bun:test';
import {
getPreviewTargetErrorCode,
getPreviewTargetRecoveryAction,
PREVIEW_TARGET_ERROR_HEADER,
} from './proxy-response';
describe('preview proxy response classification', () => {
test('recognizes proxy-owned target failures', () => {
for (const code of ['missing', 'expired', 'invalid-token'] as const) {
const headers = new Headers({ [PREVIEW_TARGET_ERROR_HEADER]: code });
expect(getPreviewTargetErrorCode(headers)).toBe(code);
}
});
test('does not classify ordinary upstream responses as target failures', () => {
expect(getPreviewTargetErrorCode(new Headers())).toBeNull();
expect(getPreviewTargetErrorCode(new Headers({ [PREVIEW_TARGET_ERROR_HEADER]: 'unknown' }))).toBeNull();
expect(getPreviewTargetRecoveryAction(new Headers(), false)).toBe('none');
});
test('bounds automatic target recovery to one registration retry', () => {
const headers = new Headers({ [PREVIEW_TARGET_ERROR_HEADER]: 'expired' });
expect(getPreviewTargetRecoveryAction(headers, false)).toBe('retry-registration');
expect(getPreviewTargetRecoveryAction(headers, true)).toBe('stop-retrying');
});
});
@@ -0,0 +1,18 @@
export const PREVIEW_TARGET_ERROR_HEADER = 'x-openchamber-preview-target-error';
type PreviewTargetErrorCode = 'missing' | 'expired' | 'invalid-token';
export const getPreviewTargetErrorCode = (headers: Pick<Headers, 'get'>): PreviewTargetErrorCode | null => {
const value = headers.get(PREVIEW_TARGET_ERROR_HEADER);
return value === 'missing' || value === 'expired' || value === 'invalid-token'
? value
: null;
};
export const getPreviewTargetRecoveryAction = (
headers: Pick<Headers, 'get'>,
recoveryAttempted: boolean,
): 'none' | 'retry-registration' | 'stop-retrying' => {
if (!getPreviewTargetErrorCode(headers)) return 'none';
return recoveryAttempted ? 'stop-retrying' : 'retry-registration';
};
@@ -198,8 +198,9 @@ const TRANSPARENT_IMAGE_PLACEHOLDER = 'data:image/png;base64,iVBORw0KGgoAAAANSUh
// switches, but intentionally does NOT survive a full page reload: the server
// holds the target map in memory and the auth cookie is HttpOnly + scoped to
// the proxy id, so a stale persisted entry would 404 after a server restart.
// Entries are evicted on registration error (refetched) or when the upstream
// returns 403 (cookie expired) / 404 (target unknown) at iframe load time.
// Entries are evicted on registration error or when the preview proxy marks a
// target as missing, expired, or unauthorized. Upstream 4xx responses are not
// cache failures.
export type CachedProxyTarget = { proxyBasePath: string; previewToken?: string; expiresAt: number };
export const previewProxyTargetCache = new Map<string, CachedProxyTarget>();
const previewProxyTargetRequests = new Map<string, Promise<CachedProxyTarget | null>>();