Introduce backend app for WebSocket terminal sessions and sandbox orchestration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
OverlordandClaude Bot committed 2026-10-13 00:22:49 +02:00
1 parent 7b1df2607e
commit 91049379f7
22 files changed
+808 -11

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
export * from './spawner.ts';
export * from './lines.ts';
export * from './client.ts';
export * from './terminal.ts';
+3 -2
View File
@@ -1,9 +1,10 @@
import { MAX_TERMINAL_SIZE } from './terminal.ts';
export const SANDBOX_LABEL = 'org.security-command.sandbox';
export const SESSION_LABEL = 'org.security-command.session';
export const MAX_REQUEST_BYTES = 4096;
export const MAX_REQUEST_BYTES = 4096;
export const MAX_SESSION_SECONDS = 6 * 60 * 60;
export const MAX_TERMINAL_SIZE = 500;
export type SpawnerRequest =
| { op: 'spawn'; sessionId: string; expiresAt: number }
+51
View File
@@ -0,0 +1,51 @@
/**
* Messages of the browser WebSocket. Terminal bytes always travel as binary
* frames in both directions; text frames carry these JSON control messages.
* This module must stay free of Node imports, because the frontend uses it.
*/
export const TERMINAL_PATH = '/ws';
export const MAX_CONTROL_BYTES = 1024;
export const MAX_TERMINAL_SIZE = 500;
export type TerminalSize = { cols: number; rows: number };
export type ClientMessage =
| ({ type: 'hello' } & TerminalSize)
| ({ type: 'resize' } & TerminalSize);
export type ExitReason = 'closed' | 'expired' | 'error';
export type ServerMessage =
| { type: 'ready' }
| { type: 'exit'; reason: ExitReason };
export class InvalidMessageError extends Error {}
function invalid(message: string): never
{
throw new InvalidMessageError(message);
}
function size(value: unknown): number
{
if (typeof value !== 'number' || !Number.isInteger(value)) invalid('invalid terminal size');
return Math.min(Math.max(value, 1), MAX_TERMINAL_SIZE);
}
export function parseClientMessage(text: string): ClientMessage
{
if (text.length > MAX_CONTROL_BYTES) invalid('message too long');
let input: unknown;
try { input = JSON.parse(text); }
catch { invalid('malformed json'); }
if (typeof input !== 'object' || input === null || Array.isArray(input)) invalid('message must be an object');
const message = input as Record<string, unknown>;
const type = Object.hasOwn(message, 'type') ? message.type : undefined;
if (type !== 'hello' && type !== 'resize') invalid('unknown message type');
return { type, cols: size(message.cols), rows: size(message.rows) };
}