dev_arc_aws/src/pages/Terminal.tsx

346 lines
13 KiB
TypeScript
Raw Normal View History

Add Phase 1a: core SSH terminal (Termix migration) Implements the minimal-viable terminal described in TERMIX_MIGRATION.md Phase 1a: a real interactive SSH session in the browser over a WebSocket, using xterm.js on the frontend and ssh2 on the backend. Reuses ArchNest's existing SSH integrations (host/port/username/ password/privateKey/passphrase) instead of introducing a second, duplicate host-management system the way Termix has one. Backend: new /api/terminal WebSocket route (registered via @fastify/websocket) handling connect/input/resize/disconnect messages, authenticated via a JWT passed as a query param (browsers can't set custom headers on the WS handshake). Extracted the integration secret loader out of routes/integrations.ts into db/secrets.ts so the new terminal route can reuse it without duplicating the decrypt logic. Frontend: new Terminal.tsx page listing configured SSH hosts and rendering an xterm.js terminal wired to the WebSocket; wired into App.tsx at /terminal. vite.config.ts's dev proxy now forwards WebSocket upgrades (ws: true) so this works under `npm run dev`. Verified end-to-end against a real (test) ssh2-based SSH server: connect, shell banner, keystroke echo, and prompt redraw all worked correctly over the actual WebSocket protocol. Deliberately deferred to Phase 1b/1c per the migration doc: jump-host chaining, tab/split-pane UI, terminal theme/font settings, OPKSSH cert auth, tmux session monitor, session recording. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BbJV5nm8KPVH1oNJYKpnoF
2026-06-19 10:52:04 +00:00
import { useEffect, useRef, useState } from 'react'
import { Settings2, Plus, X, Columns2, Grid2x2, SquareSlash, Sparkles } from 'lucide-react'
import { api, type Integration, type PromptPreset, type PromptStatus } from '../lib/api'
Keep SSH terminal sessions connected across page navigation (#30) The Terminal page held all session state (xterm instances and their WebSockets) in component-local React state. Because it renders as a `<Route element={<Terminal />}>`, navigating away unmounted it and ran the xterm cleanup (`term.dispose()` + `ws.close()`), tearing down every SSH session. Returning to the page reconnected from scratch, losing scrollback and any running work. Lift terminal sessions into a `TerminalSessionProvider` mounted above the router (in `main.tsx`, inside `AuthProvider`). The provider owns each pane's xterm instance, fit addon, WebSocket, and a persistent wrapper DOM node. Wrappers live in a hidden container at the app root; the Terminal page re-parents them into its grid on mount and moves them back to the hidden root on unmount instead of disposing — so the xterm + WebSocket keep running in the background across route changes. Disconnect semantics: closing a tab/pane (or shrinking the 1/2/4 grid) destroys those sessions; logout tears down all sessions. A full browser reload still drops connections (the WebSocket dies with the page) — this persists across in-app navigation only. Shared terminal constants/types/prefs are split into a non-component module (`src/lib/terminalPrefs.ts`) so the context file stays a clean component module. Also document the terminal window grid-view tiering in ROADMAP.md (self-hosted = 4-window cap, current; paid = as many as fit on screen, planned for the AWS deployment), and realign HANDOFF/README/design-docs to reflect that auth Phase 3 (multi-user) shipped and Phase 4 (SSO) is deferred to a paid AWS add-on. Verified with a clean `tsc -b && vite build` (frontend) and `tsc --noEmit -p .` (backend). Co-authored-by: Samuel James <ssamjame@amazon.com> Co-authored-by: Kiro <noreply@kiro.dev>
2026-06-20 15:02:50 -04:00
import { useTerminalSessions } from '../lib/TerminalSessionContext'
import { TERM_THEMES } from '../lib/terminalPrefs'
Add Phase 1a: core SSH terminal (Termix migration) Implements the minimal-viable terminal described in TERMIX_MIGRATION.md Phase 1a: a real interactive SSH session in the browser over a WebSocket, using xterm.js on the frontend and ssh2 on the backend. Reuses ArchNest's existing SSH integrations (host/port/username/ password/privateKey/passphrase) instead of introducing a second, duplicate host-management system the way Termix has one. Backend: new /api/terminal WebSocket route (registered via @fastify/websocket) handling connect/input/resize/disconnect messages, authenticated via a JWT passed as a query param (browsers can't set custom headers on the WS handshake). Extracted the integration secret loader out of routes/integrations.ts into db/secrets.ts so the new terminal route can reuse it without duplicating the decrypt logic. Frontend: new Terminal.tsx page listing configured SSH hosts and rendering an xterm.js terminal wired to the WebSocket; wired into App.tsx at /terminal. vite.config.ts's dev proxy now forwards WebSocket upgrades (ws: true) so this works under `npm run dev`. Verified end-to-end against a real (test) ssh2-based SSH server: connect, shell banner, keystroke echo, and prompt redraw all worked correctly over the actual WebSocket protocol. Deliberately deferred to Phase 1b/1c per the migration doc: jump-host chaining, tab/split-pane UI, terminal theme/font settings, OPKSSH cert auth, tmux session monitor, session recording. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BbJV5nm8KPVH1oNJYKpnoF
2026-06-19 10:52:04 +00:00
const GOLD = '#C8A434'
const TEXT_SECONDARY = '#7A7D85'
const FONT_SIZES = [11, 12, 13, 14, 15, 16]
// "Symbols Nerd Font Mono" is appended as a glyph-only fallback to every option, so
// distro icons / git branch / etc. from prompts like Starship render instead of
// showing as boxes — it has no letterforms of its own, so it never overrides the
// chosen base font for normal text.
const NERD_FALLBACK = '"Symbols Nerd Font Mono"'
const FONT_FAMILIES = [
{ name: 'Monospace', value: `ui-monospace, SFMono-Regular, Menlo, monospace, ${NERD_FALLBACK}` },
{ name: 'Fira Code', value: `"Fira Code", ui-monospace, monospace, ${NERD_FALLBACK}` },
{ name: 'JetBrains Mono', value: `"JetBrains Mono", ui-monospace, monospace, ${NERD_FALLBACK}` },
]
Add Phase 1a: core SSH terminal (Termix migration) Implements the minimal-viable terminal described in TERMIX_MIGRATION.md Phase 1a: a real interactive SSH session in the browser over a WebSocket, using xterm.js on the frontend and ssh2 on the backend. Reuses ArchNest's existing SSH integrations (host/port/username/ password/privateKey/passphrase) instead of introducing a second, duplicate host-management system the way Termix has one. Backend: new /api/terminal WebSocket route (registered via @fastify/websocket) handling connect/input/resize/disconnect messages, authenticated via a JWT passed as a query param (browsers can't set custom headers on the WS handshake). Extracted the integration secret loader out of routes/integrations.ts into db/secrets.ts so the new terminal route can reuse it without duplicating the decrypt logic. Frontend: new Terminal.tsx page listing configured SSH hosts and rendering an xterm.js terminal wired to the WebSocket; wired into App.tsx at /terminal. vite.config.ts's dev proxy now forwards WebSocket upgrades (ws: true) so this works under `npm run dev`. Verified end-to-end against a real (test) ssh2-based SSH server: connect, shell banner, keystroke echo, and prompt redraw all worked correctly over the actual WebSocket protocol. Deliberately deferred to Phase 1b/1c per the migration doc: jump-host chaining, tab/split-pane UI, terminal theme/font settings, OPKSSH cert auth, tmux session monitor, session recording. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BbJV5nm8KPVH1oNJYKpnoF
2026-06-19 10:52:04 +00:00
export default function Terminal() {
const [hosts, setHosts] = useState<Integration[]>([])
const [showPrefs, setShowPrefs] = useState(false)
Add Phase 1a: core SSH terminal (Termix migration) Implements the minimal-viable terminal described in TERMIX_MIGRATION.md Phase 1a: a real interactive SSH session in the browser over a WebSocket, using xterm.js on the frontend and ssh2 on the backend. Reuses ArchNest's existing SSH integrations (host/port/username/ password/privateKey/passphrase) instead of introducing a second, duplicate host-management system the way Termix has one. Backend: new /api/terminal WebSocket route (registered via @fastify/websocket) handling connect/input/resize/disconnect messages, authenticated via a JWT passed as a query param (browsers can't set custom headers on the WS handshake). Extracted the integration secret loader out of routes/integrations.ts into db/secrets.ts so the new terminal route can reuse it without duplicating the decrypt logic. Frontend: new Terminal.tsx page listing configured SSH hosts and rendering an xterm.js terminal wired to the WebSocket; wired into App.tsx at /terminal. vite.config.ts's dev proxy now forwards WebSocket upgrades (ws: true) so this works under `npm run dev`. Verified end-to-end against a real (test) ssh2-based SSH server: connect, shell banner, keystroke echo, and prompt redraw all worked correctly over the actual WebSocket protocol. Deliberately deferred to Phase 1b/1c per the migration doc: jump-host chaining, tab/split-pane UI, terminal theme/font settings, OPKSSH cert auth, tmux session monitor, session recording. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BbJV5nm8KPVH1oNJYKpnoF
2026-06-19 10:52:04 +00:00
Keep SSH terminal sessions connected across page navigation (#30) The Terminal page held all session state (xterm instances and their WebSockets) in component-local React state. Because it renders as a `<Route element={<Terminal />}>`, navigating away unmounted it and ran the xterm cleanup (`term.dispose()` + `ws.close()`), tearing down every SSH session. Returning to the page reconnected from scratch, losing scrollback and any running work. Lift terminal sessions into a `TerminalSessionProvider` mounted above the router (in `main.tsx`, inside `AuthProvider`). The provider owns each pane's xterm instance, fit addon, WebSocket, and a persistent wrapper DOM node. Wrappers live in a hidden container at the app root; the Terminal page re-parents them into its grid on mount and moves them back to the hidden root on unmount instead of disposing — so the xterm + WebSocket keep running in the background across route changes. Disconnect semantics: closing a tab/pane (or shrinking the 1/2/4 grid) destroys those sessions; logout tears down all sessions. A full browser reload still drops connections (the WebSocket dies with the page) — this persists across in-app navigation only. Shared terminal constants/types/prefs are split into a non-component module (`src/lib/terminalPrefs.ts`) so the context file stays a clean component module. Also document the terminal window grid-view tiering in ROADMAP.md (self-hosted = 4-window cap, current; paid = as many as fit on screen, planned for the AWS deployment), and realign HANDOFF/README/design-docs to reflect that auth Phase 3 (multi-user) shipped and Phase 4 (SSO) is deferred to a paid AWS add-on. Verified with a clean `tsc -b && vite build` (frontend) and `tsc --noEmit -p .` (backend). Co-authored-by: Samuel James <ssamjame@amazon.com> Co-authored-by: Kiro <noreply@kiro.dev>
2026-06-20 15:02:50 -04:00
const {
tabs,
activeTabId,
activePaneId,
prefs,
setActiveTabId,
setActivePaneId,
setPrefs,
addTab,
closeTab,
setPaneCount,
setPaneHost,
} = useTerminalSessions()
Add Phase 1a: core SSH terminal (Termix migration) Implements the minimal-viable terminal described in TERMIX_MIGRATION.md Phase 1a: a real interactive SSH session in the browser over a WebSocket, using xterm.js on the frontend and ssh2 on the backend. Reuses ArchNest's existing SSH integrations (host/port/username/ password/privateKey/passphrase) instead of introducing a second, duplicate host-management system the way Termix has one. Backend: new /api/terminal WebSocket route (registered via @fastify/websocket) handling connect/input/resize/disconnect messages, authenticated via a JWT passed as a query param (browsers can't set custom headers on the WS handshake). Extracted the integration secret loader out of routes/integrations.ts into db/secrets.ts so the new terminal route can reuse it without duplicating the decrypt logic. Frontend: new Terminal.tsx page listing configured SSH hosts and rendering an xterm.js terminal wired to the WebSocket; wired into App.tsx at /terminal. vite.config.ts's dev proxy now forwards WebSocket upgrades (ws: true) so this works under `npm run dev`. Verified end-to-end against a real (test) ssh2-based SSH server: connect, shell banner, keystroke echo, and prompt redraw all worked correctly over the actual WebSocket protocol. Deliberately deferred to Phase 1b/1c per the migration doc: jump-host chaining, tab/split-pane UI, terminal theme/font settings, OPKSSH cert auth, tmux session monitor, session recording. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BbJV5nm8KPVH1oNJYKpnoF
2026-06-19 10:52:04 +00:00
useEffect(() => {
api.listIntegrations().then(({ integrations }) => {
setHosts(integrations.filter((i) => i.type === 'ssh'))
})
}, [])
const activeTab = tabs.find((t) => t.id === activeTabId) ?? tabs[0]
const paneGridClass =
activeTab.panes.length === 1
? 'grid-cols-1 grid-rows-1'
: activeTab.panes.length === 2
? 'grid-cols-2 grid-rows-1'
: 'grid-cols-2 grid-rows-2'
Keep SSH terminal sessions connected across page navigation (#30) The Terminal page held all session state (xterm instances and their WebSockets) in component-local React state. Because it renders as a `<Route element={<Terminal />}>`, navigating away unmounted it and ran the xterm cleanup (`term.dispose()` + `ws.close()`), tearing down every SSH session. Returning to the page reconnected from scratch, losing scrollback and any running work. Lift terminal sessions into a `TerminalSessionProvider` mounted above the router (in `main.tsx`, inside `AuthProvider`). The provider owns each pane's xterm instance, fit addon, WebSocket, and a persistent wrapper DOM node. Wrappers live in a hidden container at the app root; the Terminal page re-parents them into its grid on mount and moves them back to the hidden root on unmount instead of disposing — so the xterm + WebSocket keep running in the background across route changes. Disconnect semantics: closing a tab/pane (or shrinking the 1/2/4 grid) destroys those sessions; logout tears down all sessions. A full browser reload still drops connections (the WebSocket dies with the page) — this persists across in-app navigation only. Shared terminal constants/types/prefs are split into a non-component module (`src/lib/terminalPrefs.ts`) so the context file stays a clean component module. Also document the terminal window grid-view tiering in ROADMAP.md (self-hosted = 4-window cap, current; paid = as many as fit on screen, planned for the AWS deployment), and realign HANDOFF/README/design-docs to reflect that auth Phase 3 (multi-user) shipped and Phase 4 (SSO) is deferred to a paid AWS add-on. Verified with a clean `tsc -b && vite build` (frontend) and `tsc --noEmit -p .` (backend). Co-authored-by: Samuel James <ssamjame@amazon.com> Co-authored-by: Kiro <noreply@kiro.dev>
2026-06-20 15:02:50 -04:00
const activePaneHostId = activeTab.panes.find((p) => p.id === activePaneId)?.hostId ?? null
return (
<div className="flex h-full gap-4">
<div className="w-56 shrink-0 overflow-y-auto rounded-lg border border-white/10 bg-white/5 p-3">
<p className="mb-2 text-xs font-medium uppercase tracking-wide" style={{ color: TEXT_SECONDARY }}>
SSH Hosts
</p>
{hosts.length === 0 && (
<p className="text-xs" style={{ color: TEXT_SECONDARY }}>
No SSH integrations configured. Add one in Settings Integrations.
</p>
)}
<div className="flex flex-col gap-1">
{hosts.map((h) => (
<button
key={h.id}
onClick={() => activePaneId !== null && setPaneHost(activePaneId, h.id)}
className="rounded-md px-2 py-1.5 text-left text-sm transition-colors"
style={{
Keep SSH terminal sessions connected across page navigation (#30) The Terminal page held all session state (xterm instances and their WebSockets) in component-local React state. Because it renders as a `<Route element={<Terminal />}>`, navigating away unmounted it and ran the xterm cleanup (`term.dispose()` + `ws.close()`), tearing down every SSH session. Returning to the page reconnected from scratch, losing scrollback and any running work. Lift terminal sessions into a `TerminalSessionProvider` mounted above the router (in `main.tsx`, inside `AuthProvider`). The provider owns each pane's xterm instance, fit addon, WebSocket, and a persistent wrapper DOM node. Wrappers live in a hidden container at the app root; the Terminal page re-parents them into its grid on mount and moves them back to the hidden root on unmount instead of disposing — so the xterm + WebSocket keep running in the background across route changes. Disconnect semantics: closing a tab/pane (or shrinking the 1/2/4 grid) destroys those sessions; logout tears down all sessions. A full browser reload still drops connections (the WebSocket dies with the page) — this persists across in-app navigation only. Shared terminal constants/types/prefs are split into a non-component module (`src/lib/terminalPrefs.ts`) so the context file stays a clean component module. Also document the terminal window grid-view tiering in ROADMAP.md (self-hosted = 4-window cap, current; paid = as many as fit on screen, planned for the AWS deployment), and realign HANDOFF/README/design-docs to reflect that auth Phase 3 (multi-user) shipped and Phase 4 (SSO) is deferred to a paid AWS add-on. Verified with a clean `tsc -b && vite build` (frontend) and `tsc --noEmit -p .` (backend). Co-authored-by: Samuel James <ssamjame@amazon.com> Co-authored-by: Kiro <noreply@kiro.dev>
2026-06-20 15:02:50 -04:00
background: activePaneHostId === h.id ? 'rgba(200,164,52,0.15)' : 'transparent',
color: activePaneHostId === h.id ? GOLD : '#E8E6E0',
}}
>
{h.name}
</button>
))}
</div>
<p className="mt-3 text-[11px]" style={{ color: TEXT_SECONDARY }}>
Keep SSH terminal sessions connected across page navigation (#30) The Terminal page held all session state (xterm instances and their WebSockets) in component-local React state. Because it renders as a `<Route element={<Terminal />}>`, navigating away unmounted it and ran the xterm cleanup (`term.dispose()` + `ws.close()`), tearing down every SSH session. Returning to the page reconnected from scratch, losing scrollback and any running work. Lift terminal sessions into a `TerminalSessionProvider` mounted above the router (in `main.tsx`, inside `AuthProvider`). The provider owns each pane's xterm instance, fit addon, WebSocket, and a persistent wrapper DOM node. Wrappers live in a hidden container at the app root; the Terminal page re-parents them into its grid on mount and moves them back to the hidden root on unmount instead of disposing — so the xterm + WebSocket keep running in the background across route changes. Disconnect semantics: closing a tab/pane (or shrinking the 1/2/4 grid) destroys those sessions; logout tears down all sessions. A full browser reload still drops connections (the WebSocket dies with the page) — this persists across in-app navigation only. Shared terminal constants/types/prefs are split into a non-component module (`src/lib/terminalPrefs.ts`) so the context file stays a clean component module. Also document the terminal window grid-view tiering in ROADMAP.md (self-hosted = 4-window cap, current; paid = as many as fit on screen, planned for the AWS deployment), and realign HANDOFF/README/design-docs to reflect that auth Phase 3 (multi-user) shipped and Phase 4 (SSO) is deferred to a paid AWS add-on. Verified with a clean `tsc -b && vite build` (frontend) and `tsc --noEmit -p .` (backend). Co-authored-by: Samuel James <ssamjame@amazon.com> Co-authored-by: Kiro <noreply@kiro.dev>
2026-06-20 15:02:50 -04:00
Click a pane, then a host to connect it. Sessions stay connected when
you switch pages close a tab or pane to disconnect.
</p>
</div>
<div className="flex min-w-0 flex-1 flex-col gap-2">
<div className="flex items-center gap-2">
<div className="flex flex-1 items-center gap-1 overflow-x-auto">
{tabs.map((tab) => (
<div
key={tab.id}
onClick={() => setActiveTabId(tab.id)}
className="flex shrink-0 cursor-pointer items-center gap-2 rounded-md px-3 py-1.5 text-xs"
style={{
background: tab.id === activeTabId ? 'rgba(200,164,52,0.15)' : 'rgba(255,255,255,0.04)',
color: tab.id === activeTabId ? GOLD : '#E8E6E0',
}}
>
{tab.name}
<X
size={12}
onClick={(e) => {
e.stopPropagation()
closeTab(tab.id)
}}
/>
</div>
))}
<button onClick={addTab} className="shrink-0 rounded-md p-1.5" style={{ color: TEXT_SECONDARY }} title="New tab">
<Plus size={14} />
</button>
</div>
<div className="flex items-center gap-1">
<button onClick={() => setPaneCount(1)} className="rounded-md p-1.5" style={{ color: activeTab.panes.length === 1 ? GOLD : TEXT_SECONDARY }} title="Single pane">
<SquareSlash size={14} />
</button>
<button onClick={() => setPaneCount(2)} className="rounded-md p-1.5" style={{ color: activeTab.panes.length === 2 ? GOLD : TEXT_SECONDARY }} title="Split 2">
<Columns2 size={14} />
</button>
<button onClick={() => setPaneCount(4)} className="rounded-md p-1.5" style={{ color: activeTab.panes.length === 4 ? GOLD : TEXT_SECONDARY }} title="Split 4">
<Grid2x2 size={14} />
</button>
<button onClick={() => setShowPrefs((v) => !v)} className="rounded-md p-1.5" style={{ color: showPrefs ? GOLD : TEXT_SECONDARY }} title="Terminal preferences">
<Settings2 size={14} />
</button>
</div>
</div>
{showPrefs && (
<div className="flex items-center gap-4 rounded-lg border border-white/10 bg-white/5 px-3 py-2 text-xs" style={{ color: '#E8E6E0' }}>
<label className="flex items-center gap-2">
Theme
<select
value={prefs.themeName}
onChange={(e) => setPrefs((p) => ({ ...p, themeName: e.target.value }))}
className="rounded-md border border-white/10 bg-transparent px-2 py-1"
>
{TERM_THEMES.map((t) => (
<option key={t.name} value={t.name}>
{t.name}
</option>
))}
</select>
</label>
<label className="flex items-center gap-2">
Font Size
<select
value={prefs.fontSize}
onChange={(e) => setPrefs((p) => ({ ...p, fontSize: Number(e.target.value) }))}
className="rounded-md border border-white/10 bg-transparent px-2 py-1"
>
{FONT_SIZES.map((s) => (
<option key={s} value={s}>
{s}px
</option>
))}
</select>
</label>
<label className="flex items-center gap-2">
Font
<select
value={prefs.fontFamily}
onChange={(e) => setPrefs((p) => ({ ...p, fontFamily: e.target.value }))}
className="rounded-md border border-white/10 bg-transparent px-2 py-1"
>
{FONT_FAMILIES.map((f) => (
<option key={f.name} value={f.value}>
{f.name}
</option>
))}
</select>
</label>
<div className="ml-auto border-l border-white/10 pl-4">
<ShellPromptControl hostId={activePaneHostId} />
</div>
</div>
)}
<div className={`grid min-h-0 flex-1 gap-2 ${paneGridClass}`}>
{activeTab.panes.map((pane) => (
<TerminalPane
key={pane.id}
Keep SSH terminal sessions connected across page navigation (#30) The Terminal page held all session state (xterm instances and their WebSockets) in component-local React state. Because it renders as a `<Route element={<Terminal />}>`, navigating away unmounted it and ran the xterm cleanup (`term.dispose()` + `ws.close()`), tearing down every SSH session. Returning to the page reconnected from scratch, losing scrollback and any running work. Lift terminal sessions into a `TerminalSessionProvider` mounted above the router (in `main.tsx`, inside `AuthProvider`). The provider owns each pane's xterm instance, fit addon, WebSocket, and a persistent wrapper DOM node. Wrappers live in a hidden container at the app root; the Terminal page re-parents them into its grid on mount and moves them back to the hidden root on unmount instead of disposing — so the xterm + WebSocket keep running in the background across route changes. Disconnect semantics: closing a tab/pane (or shrinking the 1/2/4 grid) destroys those sessions; logout tears down all sessions. A full browser reload still drops connections (the WebSocket dies with the page) — this persists across in-app navigation only. Shared terminal constants/types/prefs are split into a non-component module (`src/lib/terminalPrefs.ts`) so the context file stays a clean component module. Also document the terminal window grid-view tiering in ROADMAP.md (self-hosted = 4-window cap, current; paid = as many as fit on screen, planned for the AWS deployment), and realign HANDOFF/README/design-docs to reflect that auth Phase 3 (multi-user) shipped and Phase 4 (SSO) is deferred to a paid AWS add-on. Verified with a clean `tsc -b && vite build` (frontend) and `tsc --noEmit -p .` (backend). Co-authored-by: Samuel James <ssamjame@amazon.com> Co-authored-by: Kiro <noreply@kiro.dev>
2026-06-20 15:02:50 -04:00
paneId={pane.id}
hostId={pane.hostId}
hosts={hosts}
active={pane.id === activePaneId}
onFocus={() => setActivePaneId(pane.id)}
/>
))}
</div>
</div>
</div>
)
}
function TerminalPane({
Keep SSH terminal sessions connected across page navigation (#30) The Terminal page held all session state (xterm instances and their WebSockets) in component-local React state. Because it renders as a `<Route element={<Terminal />}>`, navigating away unmounted it and ran the xterm cleanup (`term.dispose()` + `ws.close()`), tearing down every SSH session. Returning to the page reconnected from scratch, losing scrollback and any running work. Lift terminal sessions into a `TerminalSessionProvider` mounted above the router (in `main.tsx`, inside `AuthProvider`). The provider owns each pane's xterm instance, fit addon, WebSocket, and a persistent wrapper DOM node. Wrappers live in a hidden container at the app root; the Terminal page re-parents them into its grid on mount and moves them back to the hidden root on unmount instead of disposing — so the xterm + WebSocket keep running in the background across route changes. Disconnect semantics: closing a tab/pane (or shrinking the 1/2/4 grid) destroys those sessions; logout tears down all sessions. A full browser reload still drops connections (the WebSocket dies with the page) — this persists across in-app navigation only. Shared terminal constants/types/prefs are split into a non-component module (`src/lib/terminalPrefs.ts`) so the context file stays a clean component module. Also document the terminal window grid-view tiering in ROADMAP.md (self-hosted = 4-window cap, current; paid = as many as fit on screen, planned for the AWS deployment), and realign HANDOFF/README/design-docs to reflect that auth Phase 3 (multi-user) shipped and Phase 4 (SSO) is deferred to a paid AWS add-on. Verified with a clean `tsc -b && vite build` (frontend) and `tsc --noEmit -p .` (backend). Co-authored-by: Samuel James <ssamjame@amazon.com> Co-authored-by: Kiro <noreply@kiro.dev>
2026-06-20 15:02:50 -04:00
paneId,
hostId,
hosts,
active,
onFocus,
}: {
Keep SSH terminal sessions connected across page navigation (#30) The Terminal page held all session state (xterm instances and their WebSockets) in component-local React state. Because it renders as a `<Route element={<Terminal />}>`, navigating away unmounted it and ran the xterm cleanup (`term.dispose()` + `ws.close()`), tearing down every SSH session. Returning to the page reconnected from scratch, losing scrollback and any running work. Lift terminal sessions into a `TerminalSessionProvider` mounted above the router (in `main.tsx`, inside `AuthProvider`). The provider owns each pane's xterm instance, fit addon, WebSocket, and a persistent wrapper DOM node. Wrappers live in a hidden container at the app root; the Terminal page re-parents them into its grid on mount and moves them back to the hidden root on unmount instead of disposing — so the xterm + WebSocket keep running in the background across route changes. Disconnect semantics: closing a tab/pane (or shrinking the 1/2/4 grid) destroys those sessions; logout tears down all sessions. A full browser reload still drops connections (the WebSocket dies with the page) — this persists across in-app navigation only. Shared terminal constants/types/prefs are split into a non-component module (`src/lib/terminalPrefs.ts`) so the context file stays a clean component module. Also document the terminal window grid-view tiering in ROADMAP.md (self-hosted = 4-window cap, current; paid = as many as fit on screen, planned for the AWS deployment), and realign HANDOFF/README/design-docs to reflect that auth Phase 3 (multi-user) shipped and Phase 4 (SSO) is deferred to a paid AWS add-on. Verified with a clean `tsc -b && vite build` (frontend) and `tsc --noEmit -p .` (backend). Co-authored-by: Samuel James <ssamjame@amazon.com> Co-authored-by: Kiro <noreply@kiro.dev>
2026-06-20 15:02:50 -04:00
paneId: number
hostId: number | null
hosts: Integration[]
active: boolean
onFocus: () => void
}) {
Keep SSH terminal sessions connected across page navigation (#30) The Terminal page held all session state (xterm instances and their WebSockets) in component-local React state. Because it renders as a `<Route element={<Terminal />}>`, navigating away unmounted it and ran the xterm cleanup (`term.dispose()` + `ws.close()`), tearing down every SSH session. Returning to the page reconnected from scratch, losing scrollback and any running work. Lift terminal sessions into a `TerminalSessionProvider` mounted above the router (in `main.tsx`, inside `AuthProvider`). The provider owns each pane's xterm instance, fit addon, WebSocket, and a persistent wrapper DOM node. Wrappers live in a hidden container at the app root; the Terminal page re-parents them into its grid on mount and moves them back to the hidden root on unmount instead of disposing — so the xterm + WebSocket keep running in the background across route changes. Disconnect semantics: closing a tab/pane (or shrinking the 1/2/4 grid) destroys those sessions; logout tears down all sessions. A full browser reload still drops connections (the WebSocket dies with the page) — this persists across in-app navigation only. Shared terminal constants/types/prefs are split into a non-component module (`src/lib/terminalPrefs.ts`) so the context file stays a clean component module. Also document the terminal window grid-view tiering in ROADMAP.md (self-hosted = 4-window cap, current; paid = as many as fit on screen, planned for the AWS deployment), and realign HANDOFF/README/design-docs to reflect that auth Phase 3 (multi-user) shipped and Phase 4 (SSO) is deferred to a paid AWS add-on. Verified with a clean `tsc -b && vite build` (frontend) and `tsc --noEmit -p .` (backend). Co-authored-by: Samuel James <ssamjame@amazon.com> Co-authored-by: Kiro <noreply@kiro.dev>
2026-06-20 15:02:50 -04:00
const { attachPane, getPaneInfo, reconnectTmux, version } = useTerminalSessions()
const cellRef = useRef<HTMLDivElement>(null)
Keep SSH terminal sessions connected across page navigation (#30) The Terminal page held all session state (xterm instances and their WebSockets) in component-local React state. Because it renders as a `<Route element={<Terminal />}>`, navigating away unmounted it and ran the xterm cleanup (`term.dispose()` + `ws.close()`), tearing down every SSH session. Returning to the page reconnected from scratch, losing scrollback and any running work. Lift terminal sessions into a `TerminalSessionProvider` mounted above the router (in `main.tsx`, inside `AuthProvider`). The provider owns each pane's xterm instance, fit addon, WebSocket, and a persistent wrapper DOM node. Wrappers live in a hidden container at the app root; the Terminal page re-parents them into its grid on mount and moves them back to the hidden root on unmount instead of disposing — so the xterm + WebSocket keep running in the background across route changes. Disconnect semantics: closing a tab/pane (or shrinking the 1/2/4 grid) destroys those sessions; logout tears down all sessions. A full browser reload still drops connections (the WebSocket dies with the page) — this persists across in-app navigation only. Shared terminal constants/types/prefs are split into a non-component module (`src/lib/terminalPrefs.ts`) so the context file stays a clean component module. Also document the terminal window grid-view tiering in ROADMAP.md (self-hosted = 4-window cap, current; paid = as many as fit on screen, planned for the AWS deployment), and realign HANDOFF/README/design-docs to reflect that auth Phase 3 (multi-user) shipped and Phase 4 (SSO) is deferred to a paid AWS add-on. Verified with a clean `tsc -b && vite build` (frontend) and `tsc --noEmit -p .` (backend). Co-authored-by: Samuel James <ssamjame@amazon.com> Co-authored-by: Kiro <noreply@kiro.dev>
2026-06-20 15:02:50 -04:00
// Mount the persistent xterm DOM node owned by the provider into this cell;
// on unmount (route change or layout change) the wrapper is moved back to the
// hidden root rather than disposed, so the session keeps running.
useEffect(() => {
Keep SSH terminal sessions connected across page navigation (#30) The Terminal page held all session state (xterm instances and their WebSockets) in component-local React state. Because it renders as a `<Route element={<Terminal />}>`, navigating away unmounted it and ran the xterm cleanup (`term.dispose()` + `ws.close()`), tearing down every SSH session. Returning to the page reconnected from scratch, losing scrollback and any running work. Lift terminal sessions into a `TerminalSessionProvider` mounted above the router (in `main.tsx`, inside `AuthProvider`). The provider owns each pane's xterm instance, fit addon, WebSocket, and a persistent wrapper DOM node. Wrappers live in a hidden container at the app root; the Terminal page re-parents them into its grid on mount and moves them back to the hidden root on unmount instead of disposing — so the xterm + WebSocket keep running in the background across route changes. Disconnect semantics: closing a tab/pane (or shrinking the 1/2/4 grid) destroys those sessions; logout tears down all sessions. A full browser reload still drops connections (the WebSocket dies with the page) — this persists across in-app navigation only. Shared terminal constants/types/prefs are split into a non-component module (`src/lib/terminalPrefs.ts`) so the context file stays a clean component module. Also document the terminal window grid-view tiering in ROADMAP.md (self-hosted = 4-window cap, current; paid = as many as fit on screen, planned for the AWS deployment), and realign HANDOFF/README/design-docs to reflect that auth Phase 3 (multi-user) shipped and Phase 4 (SSO) is deferred to a paid AWS add-on. Verified with a clean `tsc -b && vite build` (frontend) and `tsc --noEmit -p .` (backend). Co-authored-by: Samuel James <ssamjame@amazon.com> Co-authored-by: Kiro <noreply@kiro.dev>
2026-06-20 15:02:50 -04:00
if (!cellRef.current) return
const detach = attachPane(paneId, cellRef.current)
return detach
// eslint-disable-next-line react-hooks/exhaustive-deps
Keep SSH terminal sessions connected across page navigation (#30) The Terminal page held all session state (xterm instances and their WebSockets) in component-local React state. Because it renders as a `<Route element={<Terminal />}>`, navigating away unmounted it and ran the xterm cleanup (`term.dispose()` + `ws.close()`), tearing down every SSH session. Returning to the page reconnected from scratch, losing scrollback and any running work. Lift terminal sessions into a `TerminalSessionProvider` mounted above the router (in `main.tsx`, inside `AuthProvider`). The provider owns each pane's xterm instance, fit addon, WebSocket, and a persistent wrapper DOM node. Wrappers live in a hidden container at the app root; the Terminal page re-parents them into its grid on mount and moves them back to the hidden root on unmount instead of disposing — so the xterm + WebSocket keep running in the background across route changes. Disconnect semantics: closing a tab/pane (or shrinking the 1/2/4 grid) destroys those sessions; logout tears down all sessions. A full browser reload still drops connections (the WebSocket dies with the page) — this persists across in-app navigation only. Shared terminal constants/types/prefs are split into a non-component module (`src/lib/terminalPrefs.ts`) so the context file stays a clean component module. Also document the terminal window grid-view tiering in ROADMAP.md (self-hosted = 4-window cap, current; paid = as many as fit on screen, planned for the AWS deployment), and realign HANDOFF/README/design-docs to reflect that auth Phase 3 (multi-user) shipped and Phase 4 (SSO) is deferred to a paid AWS add-on. Verified with a clean `tsc -b && vite build` (frontend) and `tsc --noEmit -p .` (backend). Co-authored-by: Samuel James <ssamjame@amazon.com> Co-authored-by: Kiro <noreply@kiro.dev>
2026-06-20 15:02:50 -04:00
}, [paneId])
Add Phase 1a: core SSH terminal (Termix migration) Implements the minimal-viable terminal described in TERMIX_MIGRATION.md Phase 1a: a real interactive SSH session in the browser over a WebSocket, using xterm.js on the frontend and ssh2 on the backend. Reuses ArchNest's existing SSH integrations (host/port/username/ password/privateKey/passphrase) instead of introducing a second, duplicate host-management system the way Termix has one. Backend: new /api/terminal WebSocket route (registered via @fastify/websocket) handling connect/input/resize/disconnect messages, authenticated via a JWT passed as a query param (browsers can't set custom headers on the WS handshake). Extracted the integration secret loader out of routes/integrations.ts into db/secrets.ts so the new terminal route can reuse it without duplicating the decrypt logic. Frontend: new Terminal.tsx page listing configured SSH hosts and rendering an xterm.js terminal wired to the WebSocket; wired into App.tsx at /terminal. vite.config.ts's dev proxy now forwards WebSocket upgrades (ws: true) so this works under `npm run dev`. Verified end-to-end against a real (test) ssh2-based SSH server: connect, shell banner, keystroke echo, and prompt redraw all worked correctly over the actual WebSocket protocol. Deliberately deferred to Phase 1b/1c per the migration doc: jump-host chaining, tab/split-pane UI, terminal theme/font settings, OPKSSH cert auth, tmux session monitor, session recording. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BbJV5nm8KPVH1oNJYKpnoF
2026-06-19 10:52:04 +00:00
Keep SSH terminal sessions connected across page navigation (#30) The Terminal page held all session state (xterm instances and their WebSockets) in component-local React state. Because it renders as a `<Route element={<Terminal />}>`, navigating away unmounted it and ran the xterm cleanup (`term.dispose()` + `ws.close()`), tearing down every SSH session. Returning to the page reconnected from scratch, losing scrollback and any running work. Lift terminal sessions into a `TerminalSessionProvider` mounted above the router (in `main.tsx`, inside `AuthProvider`). The provider owns each pane's xterm instance, fit addon, WebSocket, and a persistent wrapper DOM node. Wrappers live in a hidden container at the app root; the Terminal page re-parents them into its grid on mount and moves them back to the hidden root on unmount instead of disposing — so the xterm + WebSocket keep running in the background across route changes. Disconnect semantics: closing a tab/pane (or shrinking the 1/2/4 grid) destroys those sessions; logout tears down all sessions. A full browser reload still drops connections (the WebSocket dies with the page) — this persists across in-app navigation only. Shared terminal constants/types/prefs are split into a non-component module (`src/lib/terminalPrefs.ts`) so the context file stays a clean component module. Also document the terminal window grid-view tiering in ROADMAP.md (self-hosted = 4-window cap, current; paid = as many as fit on screen, planned for the AWS deployment), and realign HANDOFF/README/design-docs to reflect that auth Phase 3 (multi-user) shipped and Phase 4 (SSO) is deferred to a paid AWS add-on. Verified with a clean `tsc -b && vite build` (frontend) and `tsc --noEmit -p .` (backend). Co-authored-by: Samuel James <ssamjame@amazon.com> Co-authored-by: Kiro <noreply@kiro.dev>
2026-06-20 15:02:50 -04:00
// `version` is read so the header re-renders when live pane state changes.
void version
const info = getPaneInfo(paneId)
const host = hosts.find((h) => h.id === hostId)
Add Phase 1a: core SSH terminal (Termix migration) Implements the minimal-viable terminal described in TERMIX_MIGRATION.md Phase 1a: a real interactive SSH session in the browser over a WebSocket, using xterm.js on the frontend and ssh2 on the backend. Reuses ArchNest's existing SSH integrations (host/port/username/ password/privateKey/passphrase) instead of introducing a second, duplicate host-management system the way Termix has one. Backend: new /api/terminal WebSocket route (registered via @fastify/websocket) handling connect/input/resize/disconnect messages, authenticated via a JWT passed as a query param (browsers can't set custom headers on the WS handshake). Extracted the integration secret loader out of routes/integrations.ts into db/secrets.ts so the new terminal route can reuse it without duplicating the decrypt logic. Frontend: new Terminal.tsx page listing configured SSH hosts and rendering an xterm.js terminal wired to the WebSocket; wired into App.tsx at /terminal. vite.config.ts's dev proxy now forwards WebSocket upgrades (ws: true) so this works under `npm run dev`. Verified end-to-end against a real (test) ssh2-based SSH server: connect, shell banner, keystroke echo, and prompt redraw all worked correctly over the actual WebSocket protocol. Deliberately deferred to Phase 1b/1c per the migration doc: jump-host chaining, tab/split-pane UI, terminal theme/font settings, OPKSSH cert auth, tmux session monitor, session recording. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BbJV5nm8KPVH1oNJYKpnoF
2026-06-19 10:52:04 +00:00
return (
<div
onClick={onFocus}
className="flex min-w-0 min-h-0 flex-col rounded-lg p-2"
style={{
backgroundColor: '#15161A',
border: active ? `1px solid ${GOLD}` : '1px solid rgba(255,255,255,0.1)',
}}
>
<div className="mb-2 flex items-center gap-2 px-1 text-xs" style={{ color: TEXT_SECONDARY }}>
Keep SSH terminal sessions connected across page navigation (#30) The Terminal page held all session state (xterm instances and their WebSockets) in component-local React state. Because it renders as a `<Route element={<Terminal />}>`, navigating away unmounted it and ran the xterm cleanup (`term.dispose()` + `ws.close()`), tearing down every SSH session. Returning to the page reconnected from scratch, losing scrollback and any running work. Lift terminal sessions into a `TerminalSessionProvider` mounted above the router (in `main.tsx`, inside `AuthProvider`). The provider owns each pane's xterm instance, fit addon, WebSocket, and a persistent wrapper DOM node. Wrappers live in a hidden container at the app root; the Terminal page re-parents them into its grid on mount and moves them back to the hidden root on unmount instead of disposing — so the xterm + WebSocket keep running in the background across route changes. Disconnect semantics: closing a tab/pane (or shrinking the 1/2/4 grid) destroys those sessions; logout tears down all sessions. A full browser reload still drops connections (the WebSocket dies with the page) — this persists across in-app navigation only. Shared terminal constants/types/prefs are split into a non-component module (`src/lib/terminalPrefs.ts`) so the context file stays a clean component module. Also document the terminal window grid-view tiering in ROADMAP.md (self-hosted = 4-window cap, current; paid = as many as fit on screen, planned for the AWS deployment), and realign HANDOFF/README/design-docs to reflect that auth Phase 3 (multi-user) shipped and Phase 4 (SSO) is deferred to a paid AWS add-on. Verified with a clean `tsc -b && vite build` (frontend) and `tsc --noEmit -p .` (backend). Co-authored-by: Samuel James <ssamjame@amazon.com> Co-authored-by: Kiro <noreply@kiro.dev>
2026-06-20 15:02:50 -04:00
<span className="inline-block h-2 w-2 rounded-full" style={{ background: info.connected ? '#2ECC71' : '#7A7D85' }} />
{host ? (info.connected ? `Connected — ${host.name}` : `Disconnected — ${host.name}`) : 'Select a host to connect'}
{host && (
<select
Keep SSH terminal sessions connected across page navigation (#30) The Terminal page held all session state (xterm instances and their WebSockets) in component-local React state. Because it renders as a `<Route element={<Terminal />}>`, navigating away unmounted it and ran the xterm cleanup (`term.dispose()` + `ws.close()`), tearing down every SSH session. Returning to the page reconnected from scratch, losing scrollback and any running work. Lift terminal sessions into a `TerminalSessionProvider` mounted above the router (in `main.tsx`, inside `AuthProvider`). The provider owns each pane's xterm instance, fit addon, WebSocket, and a persistent wrapper DOM node. Wrappers live in a hidden container at the app root; the Terminal page re-parents them into its grid on mount and moves them back to the hidden root on unmount instead of disposing — so the xterm + WebSocket keep running in the background across route changes. Disconnect semantics: closing a tab/pane (or shrinking the 1/2/4 grid) destroys those sessions; logout tears down all sessions. A full browser reload still drops connections (the WebSocket dies with the page) — this persists across in-app navigation only. Shared terminal constants/types/prefs are split into a non-component module (`src/lib/terminalPrefs.ts`) so the context file stays a clean component module. Also document the terminal window grid-view tiering in ROADMAP.md (self-hosted = 4-window cap, current; paid = as many as fit on screen, planned for the AWS deployment), and realign HANDOFF/README/design-docs to reflect that auth Phase 3 (multi-user) shipped and Phase 4 (SSO) is deferred to a paid AWS add-on. Verified with a clean `tsc -b && vite build` (frontend) and `tsc --noEmit -p .` (backend). Co-authored-by: Samuel James <ssamjame@amazon.com> Co-authored-by: Kiro <noreply@kiro.dev>
2026-06-20 15:02:50 -04:00
value={info.selectedTmux}
onClick={(e) => e.stopPropagation()}
Keep SSH terminal sessions connected across page navigation (#30) The Terminal page held all session state (xterm instances and their WebSockets) in component-local React state. Because it renders as a `<Route element={<Terminal />}>`, navigating away unmounted it and ran the xterm cleanup (`term.dispose()` + `ws.close()`), tearing down every SSH session. Returning to the page reconnected from scratch, losing scrollback and any running work. Lift terminal sessions into a `TerminalSessionProvider` mounted above the router (in `main.tsx`, inside `AuthProvider`). The provider owns each pane's xterm instance, fit addon, WebSocket, and a persistent wrapper DOM node. Wrappers live in a hidden container at the app root; the Terminal page re-parents them into its grid on mount and moves them back to the hidden root on unmount instead of disposing — so the xterm + WebSocket keep running in the background across route changes. Disconnect semantics: closing a tab/pane (or shrinking the 1/2/4 grid) destroys those sessions; logout tears down all sessions. A full browser reload still drops connections (the WebSocket dies with the page) — this persists across in-app navigation only. Shared terminal constants/types/prefs are split into a non-component module (`src/lib/terminalPrefs.ts`) so the context file stays a clean component module. Also document the terminal window grid-view tiering in ROADMAP.md (self-hosted = 4-window cap, current; paid = as many as fit on screen, planned for the AWS deployment), and realign HANDOFF/README/design-docs to reflect that auth Phase 3 (multi-user) shipped and Phase 4 (SSO) is deferred to a paid AWS add-on. Verified with a clean `tsc -b && vite build` (frontend) and `tsc --noEmit -p .` (backend). Co-authored-by: Samuel James <ssamjame@amazon.com> Co-authored-by: Kiro <noreply@kiro.dev>
2026-06-20 15:02:50 -04:00
onChange={(e) => reconnectTmux(paneId, e.target.value)}
className="ml-auto rounded-md border border-white/10 bg-transparent px-1.5 py-0.5"
style={{ color: TEXT_SECONDARY, fontSize: '11px' }}
title="Attach to a tmux session on this host"
>
<option value="">Plain shell</option>
<option value="__new__">New tmux session</option>
Keep SSH terminal sessions connected across page navigation (#30) The Terminal page held all session state (xterm instances and their WebSockets) in component-local React state. Because it renders as a `<Route element={<Terminal />}>`, navigating away unmounted it and ran the xterm cleanup (`term.dispose()` + `ws.close()`), tearing down every SSH session. Returning to the page reconnected from scratch, losing scrollback and any running work. Lift terminal sessions into a `TerminalSessionProvider` mounted above the router (in `main.tsx`, inside `AuthProvider`). The provider owns each pane's xterm instance, fit addon, WebSocket, and a persistent wrapper DOM node. Wrappers live in a hidden container at the app root; the Terminal page re-parents them into its grid on mount and moves them back to the hidden root on unmount instead of disposing — so the xterm + WebSocket keep running in the background across route changes. Disconnect semantics: closing a tab/pane (or shrinking the 1/2/4 grid) destroys those sessions; logout tears down all sessions. A full browser reload still drops connections (the WebSocket dies with the page) — this persists across in-app navigation only. Shared terminal constants/types/prefs are split into a non-component module (`src/lib/terminalPrefs.ts`) so the context file stays a clean component module. Also document the terminal window grid-view tiering in ROADMAP.md (self-hosted = 4-window cap, current; paid = as many as fit on screen, planned for the AWS deployment), and realign HANDOFF/README/design-docs to reflect that auth Phase 3 (multi-user) shipped and Phase 4 (SSO) is deferred to a paid AWS add-on. Verified with a clean `tsc -b && vite build` (frontend) and `tsc --noEmit -p .` (backend). Co-authored-by: Samuel James <ssamjame@amazon.com> Co-authored-by: Kiro <noreply@kiro.dev>
2026-06-20 15:02:50 -04:00
{info.tmuxSessions.map((s) => (
<option key={s} value={s}>
tmux: {s}
</option>
))}
</select>
)}
Add Phase 1a: core SSH terminal (Termix migration) Implements the minimal-viable terminal described in TERMIX_MIGRATION.md Phase 1a: a real interactive SSH session in the browser over a WebSocket, using xterm.js on the frontend and ssh2 on the backend. Reuses ArchNest's existing SSH integrations (host/port/username/ password/privateKey/passphrase) instead of introducing a second, duplicate host-management system the way Termix has one. Backend: new /api/terminal WebSocket route (registered via @fastify/websocket) handling connect/input/resize/disconnect messages, authenticated via a JWT passed as a query param (browsers can't set custom headers on the WS handshake). Extracted the integration secret loader out of routes/integrations.ts into db/secrets.ts so the new terminal route can reuse it without duplicating the decrypt logic. Frontend: new Terminal.tsx page listing configured SSH hosts and rendering an xterm.js terminal wired to the WebSocket; wired into App.tsx at /terminal. vite.config.ts's dev proxy now forwards WebSocket upgrades (ws: true) so this works under `npm run dev`. Verified end-to-end against a real (test) ssh2-based SSH server: connect, shell banner, keystroke echo, and prompt redraw all worked correctly over the actual WebSocket protocol. Deliberately deferred to Phase 1b/1c per the migration doc: jump-host chaining, tab/split-pane UI, terminal theme/font settings, OPKSSH cert auth, tmux session monitor, session recording. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BbJV5nm8KPVH1oNJYKpnoF
2026-06-19 10:52:04 +00:00
</div>
Keep SSH terminal sessions connected across page navigation (#30) The Terminal page held all session state (xterm instances and their WebSockets) in component-local React state. Because it renders as a `<Route element={<Terminal />}>`, navigating away unmounted it and ran the xterm cleanup (`term.dispose()` + `ws.close()`), tearing down every SSH session. Returning to the page reconnected from scratch, losing scrollback and any running work. Lift terminal sessions into a `TerminalSessionProvider` mounted above the router (in `main.tsx`, inside `AuthProvider`). The provider owns each pane's xterm instance, fit addon, WebSocket, and a persistent wrapper DOM node. Wrappers live in a hidden container at the app root; the Terminal page re-parents them into its grid on mount and moves them back to the hidden root on unmount instead of disposing — so the xterm + WebSocket keep running in the background across route changes. Disconnect semantics: closing a tab/pane (or shrinking the 1/2/4 grid) destroys those sessions; logout tears down all sessions. A full browser reload still drops connections (the WebSocket dies with the page) — this persists across in-app navigation only. Shared terminal constants/types/prefs are split into a non-component module (`src/lib/terminalPrefs.ts`) so the context file stays a clean component module. Also document the terminal window grid-view tiering in ROADMAP.md (self-hosted = 4-window cap, current; paid = as many as fit on screen, planned for the AWS deployment), and realign HANDOFF/README/design-docs to reflect that auth Phase 3 (multi-user) shipped and Phase 4 (SSO) is deferred to a paid AWS add-on. Verified with a clean `tsc -b && vite build` (frontend) and `tsc --noEmit -p .` (backend). Co-authored-by: Samuel James <ssamjame@amazon.com> Co-authored-by: Kiro <noreply@kiro.dev>
2026-06-20 15:02:50 -04:00
<div ref={cellRef} className="min-h-0 flex-1" />
Add Phase 1a: core SSH terminal (Termix migration) Implements the minimal-viable terminal described in TERMIX_MIGRATION.md Phase 1a: a real interactive SSH session in the browser over a WebSocket, using xterm.js on the frontend and ssh2 on the backend. Reuses ArchNest's existing SSH integrations (host/port/username/ password/privateKey/passphrase) instead of introducing a second, duplicate host-management system the way Termix has one. Backend: new /api/terminal WebSocket route (registered via @fastify/websocket) handling connect/input/resize/disconnect messages, authenticated via a JWT passed as a query param (browsers can't set custom headers on the WS handshake). Extracted the integration secret loader out of routes/integrations.ts into db/secrets.ts so the new terminal route can reuse it without duplicating the decrypt logic. Frontend: new Terminal.tsx page listing configured SSH hosts and rendering an xterm.js terminal wired to the WebSocket; wired into App.tsx at /terminal. vite.config.ts's dev proxy now forwards WebSocket upgrades (ws: true) so this works under `npm run dev`. Verified end-to-end against a real (test) ssh2-based SSH server: connect, shell banner, keystroke echo, and prompt redraw all worked correctly over the actual WebSocket protocol. Deliberately deferred to Phase 1b/1c per the migration doc: jump-host chaining, tab/split-pane UI, terminal theme/font settings, OPKSSH cert auth, tmux session monitor, session recording. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BbJV5nm8KPVH1oNJYKpnoF
2026-06-19 10:52:04 +00:00
</div>
)
}
/**
* Lets a user pick one of a few Starship prompt looks and install it (Starship
* + a Nerd Font, if not already present) on the active pane's SSH host with
* one click, instead of running a script by hand.
*/
function ShellPromptControl({ hostId }: { hostId: number | null }) {
const [presets, setPresets] = useState<PromptPreset[]>([])
const [status, setStatus] = useState<PromptStatus | null>(null)
const [selected, setSelected] = useState('')
const [installing, setInstalling] = useState(false)
const [message, setMessage] = useState<string | null>(null)
const [error, setError] = useState<string | null>(null)
useEffect(() => {
setStatus(null)
setMessage(null)
setError(null)
if (hostId === null) return
api
.getShellPromptStatus(hostId)
.then(({ presets, status }) => {
setPresets(presets)
setStatus(status)
setSelected(status.configuredPreset ?? presets[0]?.id ?? '')
})
.catch((err) => setError(err instanceof Error ? err.message : 'Failed to check host'))
}, [hostId])
if (hostId === null) {
return <span style={{ color: TEXT_SECONDARY }}>Connect a host to set up its shell prompt</span>
}
async function handleInstall() {
if (!selected) return
setInstalling(true)
setError(null)
setMessage(null)
try {
await api.installShellPrompt(hostId!, selected)
setMessage('Installed — open a new terminal session to this host to see it.')
const { status } = await api.getShellPromptStatus(hostId!)
setStatus(status)
} catch (err) {
setError(err instanceof Error ? err.message : 'Install failed')
} finally {
setInstalling(false)
}
}
return (
<div className="flex items-center gap-2">
<Sparkles size={13} style={{ color: GOLD }} />
<label className="flex items-center gap-2">
Shell Prompt
<select
value={selected}
onChange={(e) => setSelected(e.target.value)}
className="rounded-md border border-white/10 bg-transparent px-2 py-1"
>
{presets.map((p) => (
<option key={p.id} value={p.id} title={p.description}>
{p.name}
</option>
))}
</select>
</label>
<button
onClick={handleInstall}
disabled={installing || !selected}
className="rounded-md px-2.5 py-1 text-xs font-medium"
style={{ backgroundColor: GOLD, color: '#0A0A0C', opacity: installing ? 0.6 : 1 }}
>
{installing ? 'Installing…' : status?.configuredPreset === selected ? 'Reinstall' : 'Install'}
</button>
{message && <span style={{ color: '#2ECC71' }}>{message}</span>}
{error && <span style={{ color: '#E74C3C' }}>{error}</span>}
</div>
)
}