Add session-backed dashboard terminal
This commit is contained in:
@@ -1,56 +1,190 @@
|
|||||||
import { NextResponse } from 'next/server'
|
import { NextResponse } from 'next/server'
|
||||||
|
import { randomUUID } from 'node:crypto'
|
||||||
import { DEFAULT_EXEC_TIMEOUT_MS, MAX_COMMAND_LENGTH, runSandboxCommand, validateSandboxId, validateTerminalCommand } from '../../../lib/openshellHost'
|
import { DEFAULT_EXEC_TIMEOUT_MS, MAX_COMMAND_LENGTH, runSandboxCommand, validateSandboxId, validateTerminalCommand } from '../../../lib/openshellHost'
|
||||||
|
|
||||||
export async function GET(request: Request) {
|
type TranscriptEntry = {
|
||||||
const { searchParams } = new URL(request.url)
|
id: string
|
||||||
const sandboxId = searchParams.get('sandboxId') || 'unknown'
|
command: string
|
||||||
|
stdout: string
|
||||||
|
stderr: string
|
||||||
|
exitCode: number
|
||||||
|
executionMode?: string
|
||||||
|
ranAt: string
|
||||||
|
}
|
||||||
|
|
||||||
return NextResponse.json({
|
type TerminalSession = {
|
||||||
ok: true,
|
sessionId: string
|
||||||
|
sandboxId: string
|
||||||
|
createdAt: string
|
||||||
|
updatedAt: string
|
||||||
|
cwd?: string
|
||||||
|
transcript: TranscriptEntry[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const sessions = new Map<string, TerminalSession>()
|
||||||
|
const MAX_TRANSCRIPT = 100
|
||||||
|
|
||||||
|
function ensureSession(sessionId: string, sandboxId: string) {
|
||||||
|
const existing = sessions.get(sessionId)
|
||||||
|
if (existing) {
|
||||||
|
if (existing.sandboxId !== sandboxId) {
|
||||||
|
throw new Error('sessionId does not match sandboxId')
|
||||||
|
}
|
||||||
|
return existing
|
||||||
|
}
|
||||||
|
|
||||||
|
const now = new Date().toISOString()
|
||||||
|
const created: TerminalSession = {
|
||||||
|
sessionId,
|
||||||
sandboxId,
|
sandboxId,
|
||||||
attached: false,
|
createdAt: now,
|
||||||
|
updatedAt: now,
|
||||||
|
cwd: undefined,
|
||||||
|
transcript: [],
|
||||||
|
}
|
||||||
|
sessions.set(sessionId, created)
|
||||||
|
return created
|
||||||
|
}
|
||||||
|
|
||||||
|
function sanitizePromptPath(cwd?: string) {
|
||||||
|
if (!cwd) return '~'
|
||||||
|
return cwd
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildWrappedCommand(command: string, cwd?: string) {
|
||||||
|
const trimmed = validateTerminalCommand(command)
|
||||||
|
const cdPrefix = cwd ? `cd ${quoteForSingleQuotedShell(cwd)} >/dev/null 2>&1 || exit 98; ` : ''
|
||||||
|
const shellBody = `${cdPrefix}${trimmed}; __cmd_exit=$?; printf '\n__OPENCLAW_PWD__=%s\n' "$PWD"; exit $__cmd_exit`
|
||||||
|
return shellBody
|
||||||
|
}
|
||||||
|
|
||||||
|
function quoteForSingleQuotedShell(value: string) {
|
||||||
|
return `'${value.replace(/'/g, `'"'"'`)}'`
|
||||||
|
}
|
||||||
|
|
||||||
|
function extractPwd(stdout: string) {
|
||||||
|
const match = stdout.match(/\n__OPENCLAW_PWD__=(.*)\n?$/)
|
||||||
|
if (!match) {
|
||||||
|
return { cleanedStdout: stdout.trim(), cwd: undefined }
|
||||||
|
}
|
||||||
|
|
||||||
|
const cwd = match[1]?.trim() || undefined
|
||||||
|
const cleanedStdout = stdout.slice(0, match.index).trimEnd()
|
||||||
|
return { cleanedStdout, cwd }
|
||||||
|
}
|
||||||
|
|
||||||
|
function serializeSession(session: TerminalSession) {
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
interactive: false,
|
interactive: false,
|
||||||
mode: 'bounded-command-runner',
|
terminalLike: true,
|
||||||
note: 'Embedded PTY transport is still not live. This route now supports bounded one-shot command execution via POST while interactive terminal attach remains pending.',
|
mode: 'session-backed-command-terminal',
|
||||||
suggestedCommand: `openshell sandbox exec ${sandboxId} -- /bin/sh`,
|
session: {
|
||||||
|
sessionId: session.sessionId,
|
||||||
|
sandboxId: session.sandboxId,
|
||||||
|
cwd: session.cwd,
|
||||||
|
createdAt: session.createdAt,
|
||||||
|
updatedAt: session.updatedAt,
|
||||||
|
prompt: `${session.sandboxId}:${sanitizePromptPath(session.cwd)}$`,
|
||||||
|
transcript: session.transcript,
|
||||||
|
},
|
||||||
limits: {
|
limits: {
|
||||||
timeoutMs: DEFAULT_EXEC_TIMEOUT_MS,
|
timeoutMs: DEFAULT_EXEC_TIMEOUT_MS,
|
||||||
maxCommandLength: MAX_COMMAND_LENGTH,
|
maxCommandLength: MAX_COMMAND_LENGTH,
|
||||||
},
|
},
|
||||||
})
|
note: 'Dashboard terminal is session-backed and command-scoped. It preserves transcript and working directory across commands, but it is not a raw PTY stream yet.',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function GET(request: Request) {
|
||||||
|
const { searchParams } = new URL(request.url)
|
||||||
|
const sandboxId = searchParams.get('sandboxId') || ''
|
||||||
|
const sessionId = searchParams.get('sessionId') || ''
|
||||||
|
|
||||||
|
if (!sandboxId) {
|
||||||
|
return NextResponse.json({
|
||||||
|
ok: false,
|
||||||
|
interactive: false,
|
||||||
|
mode: 'session-backed-command-terminal',
|
||||||
|
error: 'sandboxId is required',
|
||||||
|
}, { status: 400 })
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const validatedSandboxId = validateSandboxId(sandboxId)
|
||||||
|
|
||||||
|
if (!sessionId) {
|
||||||
|
const createdSession = ensureSession(randomUUID(), validatedSandboxId)
|
||||||
|
return NextResponse.json(serializeSession(createdSession))
|
||||||
|
}
|
||||||
|
|
||||||
|
const session = sessions.get(sessionId)
|
||||||
|
if (!session || session.sandboxId !== validatedSandboxId) {
|
||||||
|
return NextResponse.json({
|
||||||
|
ok: false,
|
||||||
|
interactive: false,
|
||||||
|
mode: 'session-backed-command-terminal',
|
||||||
|
error: 'session not found',
|
||||||
|
}, { status: 404 })
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json(serializeSession(session))
|
||||||
|
} catch (error) {
|
||||||
|
const message = error instanceof Error ? error.message : 'Failed to inspect terminal session'
|
||||||
|
const status = message.includes('sandboxId') ? 400 : 500
|
||||||
|
return NextResponse.json({
|
||||||
|
ok: false,
|
||||||
|
interactive: false,
|
||||||
|
mode: 'session-backed-command-terminal',
|
||||||
|
error: message,
|
||||||
|
}, { status })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function POST(request: Request) {
|
export async function POST(request: Request) {
|
||||||
try {
|
try {
|
||||||
const body = await request.json()
|
const body = await request.json()
|
||||||
const sandboxInput = typeof body?.sandboxId === 'string' ? body.sandboxId : ''
|
const sandboxInput = typeof body?.sandboxId === 'string' ? body.sandboxId : ''
|
||||||
|
const sessionInput = typeof body?.sessionId === 'string' ? body.sessionId : ''
|
||||||
const commandInput = typeof body?.command === 'string' ? body.command : ''
|
const commandInput = typeof body?.command === 'string' ? body.command : ''
|
||||||
|
|
||||||
const sandboxId = validateSandboxId(sandboxInput)
|
const sandboxId = validateSandboxId(sandboxInput)
|
||||||
const command = validateTerminalCommand(commandInput)
|
const command = validateTerminalCommand(commandInput)
|
||||||
const result = await runSandboxCommand(sandboxId, command)
|
const sessionId = sessionInput || randomUUID()
|
||||||
|
const session = ensureSession(sessionId, sandboxId)
|
||||||
|
|
||||||
|
const wrappedCommand = buildWrappedCommand(command, session.cwd)
|
||||||
|
const result = await runSandboxCommand(sandboxId, wrappedCommand)
|
||||||
|
const { cleanedStdout, cwd } = extractPwd(result.stdout)
|
||||||
|
|
||||||
|
session.cwd = cwd || session.cwd
|
||||||
|
session.updatedAt = new Date().toISOString()
|
||||||
|
session.transcript.push({
|
||||||
|
id: randomUUID(),
|
||||||
|
command,
|
||||||
|
stdout: cleanedStdout,
|
||||||
|
stderr: result.stderr.trim(),
|
||||||
|
exitCode: result.exitCode,
|
||||||
|
executionMode: result.mode,
|
||||||
|
ranAt: session.updatedAt,
|
||||||
|
})
|
||||||
|
if (session.transcript.length > MAX_TRANSCRIPT) {
|
||||||
|
session.transcript.splice(0, session.transcript.length - MAX_TRANSCRIPT)
|
||||||
|
}
|
||||||
|
|
||||||
const ok = result.exitCode === 0
|
const ok = result.exitCode === 0
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
|
...serializeSession(session),
|
||||||
ok,
|
ok,
|
||||||
sandboxId,
|
|
||||||
interactive: false,
|
|
||||||
mode: 'bounded-command-runner',
|
|
||||||
executionMode: result.mode,
|
|
||||||
command,
|
command,
|
||||||
exitCode: result.exitCode,
|
exitCode: result.exitCode,
|
||||||
stdout: result.stdout.trim(),
|
executionMode: result.mode,
|
||||||
|
stdout: cleanedStdout,
|
||||||
stderr: result.stderr.trim(),
|
stderr: result.stderr.trim(),
|
||||||
note: ok
|
note: ok
|
||||||
? result.mode === 'shell'
|
? 'Command completed and terminal session state was updated.'
|
||||||
? 'Bounded sandbox command execution succeeded. Interactive PTY transport is still pending.'
|
: `Command exited non-zero (${result.exitCode}); transcript preserved for inspection.`,
|
||||||
: 'Sandbox reachability fallback succeeded, but command execution still requires a shell-capable image.'
|
|
||||||
: `Bounded sandbox command exited non-zero (${result.exitCode}). Interactive PTY transport is still pending, but stderr/stdout below reflect the real sandbox response.`,
|
|
||||||
limits: {
|
|
||||||
timeoutMs: DEFAULT_EXEC_TIMEOUT_MS,
|
|
||||||
maxCommandLength: MAX_COMMAND_LENGTH,
|
|
||||||
},
|
|
||||||
}, { status: ok ? 200 : 502 })
|
}, { status: ok ? 200 : 502 })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = error instanceof Error ? error.message : 'Failed to run sandbox command'
|
const message = error instanceof Error ? error.message : 'Failed to run sandbox command'
|
||||||
@@ -58,13 +192,14 @@ export async function POST(request: Request) {
|
|||||||
|| message === 'command is required'
|
|| message === 'command is required'
|
||||||
|| message.includes('sandboxId must be a valid lowercase DNS-style identifier')
|
|| message.includes('sandboxId must be a valid lowercase DNS-style identifier')
|
||||||
|| message.includes('command exceeds')
|
|| message.includes('command exceeds')
|
||||||
|
|| message.includes('sessionId does not match sandboxId')
|
||||||
? 400
|
? 400
|
||||||
: 500
|
: 500
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
ok: false,
|
ok: false,
|
||||||
interactive: false,
|
interactive: false,
|
||||||
mode: 'bounded-command-runner',
|
mode: 'session-backed-command-terminal',
|
||||||
error: message,
|
error: message,
|
||||||
}, { status })
|
}, { status })
|
||||||
}
|
}
|
||||||
|
|||||||
+185
-111
@@ -37,6 +37,26 @@ interface ReadinessResponse {
|
|||||||
error?: string
|
error?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface TranscriptEntry {
|
||||||
|
id: string
|
||||||
|
command: string
|
||||||
|
stdout: string
|
||||||
|
stderr: string
|
||||||
|
exitCode: number
|
||||||
|
executionMode?: string
|
||||||
|
ranAt: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TerminalSessionPayload {
|
||||||
|
sessionId: string
|
||||||
|
sandboxId: string
|
||||||
|
cwd?: string
|
||||||
|
createdAt: string
|
||||||
|
updatedAt: string
|
||||||
|
prompt: string
|
||||||
|
transcript: TranscriptEntry[]
|
||||||
|
}
|
||||||
|
|
||||||
interface CommandRunResponse {
|
interface CommandRunResponse {
|
||||||
ok: boolean
|
ok: boolean
|
||||||
command?: string
|
command?: string
|
||||||
@@ -46,6 +66,7 @@ interface CommandRunResponse {
|
|||||||
stderr?: string
|
stderr?: string
|
||||||
error?: string
|
error?: string
|
||||||
note?: string
|
note?: string
|
||||||
|
session?: TerminalSessionPayload
|
||||||
}
|
}
|
||||||
|
|
||||||
type LoadState = 'idle' | 'loading' | 'ready' | 'error'
|
type LoadState = 'idle' | 'loading' | 'ready' | 'error'
|
||||||
@@ -62,9 +83,11 @@ export default function OperatorTerminalPage() {
|
|||||||
const [data, setData] = useState<ReadinessResponse | null>(null)
|
const [data, setData] = useState<ReadinessResponse | null>(null)
|
||||||
const [lastCheckedAt, setLastCheckedAt] = useState<string | null>(null)
|
const [lastCheckedAt, setLastCheckedAt] = useState<string | null>(null)
|
||||||
const [copyMessage, setCopyMessage] = useState<string>('')
|
const [copyMessage, setCopyMessage] = useState<string>('')
|
||||||
const [commandInput, setCommandInput] = useState<string>('pwd && whoami')
|
const [commandInput, setCommandInput] = useState<string>('pwd')
|
||||||
const [commandState, setCommandState] = useState<'idle' | 'running' | 'done' | 'error'>('idle')
|
const [commandState, setCommandState] = useState<'idle' | 'running' | 'done' | 'error'>('idle')
|
||||||
const [commandResult, setCommandResult] = useState<CommandRunResponse | null>(null)
|
const [commandResult, setCommandResult] = useState<CommandRunResponse | null>(null)
|
||||||
|
const [sessionState, setSessionState] = useState<'idle' | 'loading' | 'ready' | 'error'>('idle')
|
||||||
|
const [terminalSession, setTerminalSession] = useState<TerminalSessionPayload | null>(null)
|
||||||
|
|
||||||
const refreshReadiness = useCallback(async () => {
|
const refreshReadiness = useCallback(async () => {
|
||||||
if (!sandboxId) {
|
if (!sandboxId) {
|
||||||
@@ -94,10 +117,43 @@ export default function OperatorTerminalPage() {
|
|||||||
}
|
}
|
||||||
}, [sandboxId])
|
}, [sandboxId])
|
||||||
|
|
||||||
|
const ensureTerminalSession = useCallback(async () => {
|
||||||
|
if (!sandboxId) {
|
||||||
|
setTerminalSession(null)
|
||||||
|
setSessionState('idle')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
setSessionState('loading')
|
||||||
|
try {
|
||||||
|
const currentSessionId = terminalSession?.sessionId
|
||||||
|
const url = currentSessionId
|
||||||
|
? `/api/openshell/terminal?sandboxId=${encodeURIComponent(sandboxId)}&sessionId=${encodeURIComponent(currentSessionId)}`
|
||||||
|
: `/api/openshell/terminal?sandboxId=${encodeURIComponent(sandboxId)}`
|
||||||
|
const response = await fetch(url, { cache: 'no-store' })
|
||||||
|
const result = await response.json()
|
||||||
|
|
||||||
|
if (!response.ok || !result.ok || !result.session) {
|
||||||
|
throw new Error(result.error || 'Failed to initialize dashboard terminal session.')
|
||||||
|
}
|
||||||
|
|
||||||
|
setTerminalSession(result.session)
|
||||||
|
setSessionState('ready')
|
||||||
|
} catch (error) {
|
||||||
|
setSessionState('error')
|
||||||
|
setTerminalSession(null)
|
||||||
|
setCommandResult({ ok: false, error: error instanceof Error ? error.message : 'Failed to initialize terminal session.' })
|
||||||
|
}
|
||||||
|
}, [sandboxId, terminalSession?.sessionId])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
refreshReadiness()
|
refreshReadiness()
|
||||||
}, [refreshReadiness])
|
}, [refreshReadiness])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
ensureTerminalSession()
|
||||||
|
}, [ensureTerminalSession])
|
||||||
|
|
||||||
const readiness = useMemo(() => {
|
const readiness = useMemo(() => {
|
||||||
if (!sandboxId) {
|
if (!sandboxId) {
|
||||||
return {
|
return {
|
||||||
@@ -119,7 +175,7 @@ export default function OperatorTerminalPage() {
|
|||||||
return {
|
return {
|
||||||
tone: 'border-[var(--status-running)] text-[var(--status-running)]',
|
tone: 'border-[var(--status-running)] text-[var(--status-running)]',
|
||||||
label: 'TERMINAL PATH VERIFIED',
|
label: 'TERMINAL PATH VERIFIED',
|
||||||
detail: 'The dashboard confirmed the pod is ready and a bounded backend shell exec succeeded. Interactive PTY embedding is still not wired up, but this path now proves command execution reachability without requiring a second manual probe.',
|
detail: 'The backend confirmed pod readiness and shell reachability. The dashboard terminal below is session-backed and preserves transcript plus working directory across commands.',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,15 +183,15 @@ export default function OperatorTerminalPage() {
|
|||||||
return {
|
return {
|
||||||
tone: 'border-[var(--status-pending)] text-[var(--status-pending)]',
|
tone: 'border-[var(--status-pending)] text-[var(--status-pending)]',
|
||||||
label: 'DEGRADED: POD UP, SHELL UNCONFIRMED',
|
label: 'DEGRADED: POD UP, SHELL UNCONFIRMED',
|
||||||
detail: 'The pod exists, but the bounded shell probe did not succeed from the dashboard backend. Treat the page as degraded and try the local SSH attach path.',
|
detail: 'The pod exists, but the bounded shell probe did not succeed from the dashboard backend. You can still inspect the terminal panel below, but local SSH remains the stronger recovery path.',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state === 'ready' && data?.ok && data?.podExists) {
|
if (state === 'ready' && data?.ok && data?.podExists) {
|
||||||
return {
|
return {
|
||||||
tone: 'border-[var(--status-running)] text-[var(--status-running)]',
|
tone: 'border-[var(--status-running)] text-[var(--status-running)]',
|
||||||
label: 'READY FOR LOCAL SSH ATTACH',
|
label: 'READY FOR DASHBOARD TERMINAL',
|
||||||
detail: 'The dashboard confirmed pod metadata. Use the attach commands below while persistent PTY transport is still pending.',
|
detail: 'Pod metadata is present and the dashboard terminal session can be used for command-scoped work.',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,11 +229,16 @@ export default function OperatorTerminalPage() {
|
|||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
sandboxId,
|
sandboxId,
|
||||||
|
sessionId: terminalSession?.sessionId,
|
||||||
command: commandInput,
|
command: commandInput,
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
const result: CommandRunResponse = await response.json()
|
const result: CommandRunResponse = await response.json()
|
||||||
setCommandResult(result)
|
setCommandResult(result)
|
||||||
|
if (result.session) {
|
||||||
|
setTerminalSession(result.session)
|
||||||
|
setSessionState('ready')
|
||||||
|
}
|
||||||
setCommandState(response.ok && result.ok ? 'done' : 'error')
|
setCommandState(response.ok && result.ok ? 'done' : 'error')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setCommandResult({
|
setCommandResult({
|
||||||
@@ -186,22 +247,23 @@ export default function OperatorTerminalPage() {
|
|||||||
})
|
})
|
||||||
setCommandState('error')
|
setCommandState('error')
|
||||||
}
|
}
|
||||||
}, [commandInput, sandboxId])
|
}, [commandInput, sandboxId, terminalSession?.sessionId])
|
||||||
|
|
||||||
const aliasCommand = data?.attach?.aliasCommand || defaultAlias(sandboxId)
|
const aliasCommand = data?.attach?.aliasCommand || defaultAlias(sandboxId)
|
||||||
const fallbackCommand = data?.attach?.fallbackCommand || defaultFallback(sandboxId)
|
const fallbackCommand = data?.attach?.fallbackCommand || defaultFallback(sandboxId)
|
||||||
const loginShellCommand = data?.attach?.loginShellCommand || defaultLoginShell(sandboxId)
|
const loginShellCommand = data?.attach?.loginShellCommand || defaultLoginShell(sandboxId)
|
||||||
const shellHint = data?.attach?.shellHint || DEFAULT_SHELL_HINT
|
const shellHint = data?.attach?.shellHint || DEFAULT_SHELL_HINT
|
||||||
|
const transcript = terminalSession?.transcript || []
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="min-h-screen bg-[var(--background)] text-[var(--foreground)] p-8">
|
<main className="min-h-screen bg-[var(--background)] text-[var(--foreground)] p-8">
|
||||||
<div className="mx-auto max-w-5xl space-y-6">
|
<div className="mx-auto max-w-6xl space-y-6">
|
||||||
<div className="flex items-start justify-between gap-4 flex-wrap">
|
<div className="flex items-start justify-between gap-4 flex-wrap">
|
||||||
<div>
|
<div>
|
||||||
<p className="text-[10px] uppercase tracking-[0.25em] text-[var(--foreground-dim)] font-mono">Operator path</p>
|
<p className="text-[10px] uppercase tracking-[0.25em] text-[var(--foreground-dim)] font-mono">Operator path</p>
|
||||||
<h1 className="text-2xl font-semibold uppercase tracking-wider mt-2">Operator Terminal</h1>
|
<h1 className="text-2xl font-semibold uppercase tracking-wider mt-2">Operator Terminal</h1>
|
||||||
<p className="text-sm text-[var(--foreground-dim)] mt-3 max-w-2xl">
|
<p className="text-sm text-[var(--foreground-dim)] mt-3 max-w-3xl">
|
||||||
Truthful operator render for the current terminal path. This page still does not pretend to host an embedded PTY, but it now checks pod readiness and bounded shell reachability together before telling you how to attach.
|
Dashboard terminal for the selected sandbox. This is not pretending to be a raw PTY: it is a session-backed shell view that keeps working directory and transcript across commands so you can actually use the dashboard as a terminal surface.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<Link
|
<Link
|
||||||
@@ -227,13 +289,105 @@ export default function OperatorTerminalPage() {
|
|||||||
<p className="text-sm mt-4 text-[var(--foreground)]">{readiness.detail}</p>
|
<p className="text-sm mt-4 text-[var(--foreground)]">{readiness.detail}</p>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section className="grid grid-cols-1 xl:grid-cols-[1.25fr_0.9fr] gap-6">
|
<section className="panel p-6 space-y-4">
|
||||||
|
<div className="flex items-center justify-between gap-3 flex-wrap">
|
||||||
|
<div>
|
||||||
|
<h3 className="text-sm font-semibold uppercase tracking-wider">Dashboard Terminal</h3>
|
||||||
|
<p className="text-xs text-[var(--foreground-dim)] mt-2">
|
||||||
|
Session-backed shell surface. Each command runs through the backend against the sandbox, and the page keeps transcript plus cwd so the experience behaves like a terminal instead of isolated one-shot boxes.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="text-[11px] text-[var(--foreground-dim)] font-mono">
|
||||||
|
{sessionState === 'loading' ? 'Initializing session…' : sessionState === 'ready' ? terminalSession?.prompt : sessionState === 'error' ? 'Session unavailable' : 'Idle'}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="rounded-sm border border-[var(--border-subtle)] bg-black p-4 min-h-[420px]">
|
||||||
|
<div className="flex items-center justify-between gap-3 flex-wrap border-b border-white/10 pb-3 mb-3">
|
||||||
|
<div className="text-xs font-mono text-green-300">
|
||||||
|
{terminalSession?.prompt || `${sandboxId || 'sandbox'}:~$`}
|
||||||
|
</div>
|
||||||
|
<div className="text-[11px] font-mono text-zinc-400">
|
||||||
|
{terminalSession?.sessionId ? `session ${terminalSession.sessionId.slice(0, 8)}` : 'no session'}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-4 max-h-[480px] overflow-auto pr-1">
|
||||||
|
{transcript.length === 0 ? (
|
||||||
|
<div className="text-sm font-mono text-zinc-500">No terminal transcript yet. Run a command below to start the session.</div>
|
||||||
|
) : (
|
||||||
|
transcript.map((entry) => (
|
||||||
|
<div key={entry.id} className="space-y-2">
|
||||||
|
<div className="text-sm font-mono text-green-300">{terminalSession?.prompt || `${sandboxId || 'sandbox'}:~$`} {entry.command}</div>
|
||||||
|
<pre className="whitespace-pre-wrap break-words text-sm font-mono text-zinc-100">{entry.stdout || ''}</pre>
|
||||||
|
{entry.stderr && (
|
||||||
|
<pre className="whitespace-pre-wrap break-words text-sm font-mono text-amber-300">{entry.stderr}</pre>
|
||||||
|
)}
|
||||||
|
<div className="text-[11px] font-mono text-zinc-500">exit {entry.exitCode}{entry.executionMode ? ` · ${entry.executionMode}` : ''} · {new Date(entry.ranAt).toLocaleTimeString()}</div>
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4 space-y-4">
|
||||||
|
<label className="block">
|
||||||
|
<span className="text-[10px] uppercase tracking-[0.2em] text-[var(--foreground-dim)] font-mono">Command</span>
|
||||||
|
<textarea
|
||||||
|
value={commandInput}
|
||||||
|
onChange={(event) => setCommandInput(event.target.value)}
|
||||||
|
spellCheck={false}
|
||||||
|
rows={3}
|
||||||
|
className="mt-2 w-full rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] px-3 py-2 text-sm font-mono text-[var(--foreground)] focus:border-[var(--nvidia-green)] focus:outline-none"
|
||||||
|
placeholder="pwd"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div className="flex items-center gap-3 flex-wrap">
|
||||||
|
<button
|
||||||
|
onClick={runCommand}
|
||||||
|
disabled={commandState === 'running' || !sandboxId || sessionState === 'loading'}
|
||||||
|
className="px-3 py-2 rounded-sm border border-[var(--border-subtle)] text-xs font-mono uppercase tracking-wider hover:border-[var(--nvidia-green)] disabled:opacity-50 disabled:cursor-not-allowed"
|
||||||
|
>
|
||||||
|
{commandState === 'running' ? 'Running Command…' : 'Run in Dashboard Terminal'}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={ensureTerminalSession}
|
||||||
|
disabled={!sandboxId || sessionState === 'loading'}
|
||||||
|
className="px-3 py-2 rounded-sm border border-[var(--border-subtle)] text-xs font-mono uppercase tracking-wider hover:border-[var(--nvidia-green)] disabled:opacity-50 disabled:cursor-not-allowed"
|
||||||
|
>
|
||||||
|
Refresh Session
|
||||||
|
</button>
|
||||||
|
<p className="text-[11px] text-[var(--foreground-dim)] font-mono">Stateful transcript and cwd; not raw keystroke streaming yet.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-3">
|
||||||
|
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-3">
|
||||||
|
<p className="text-[10px] uppercase tracking-[0.2em] text-[var(--foreground-dim)] font-mono">Last stdout</p>
|
||||||
|
<pre className="mt-2 text-xs whitespace-pre-wrap break-words font-mono text-[var(--foreground)] min-h-16">{commandResult?.stdout || 'No command output yet.'}</pre>
|
||||||
|
</div>
|
||||||
|
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-3 space-y-2">
|
||||||
|
<div className="flex items-center justify-between gap-3 flex-wrap">
|
||||||
|
<p className="text-[10px] uppercase tracking-[0.2em] text-[var(--foreground-dim)] font-mono">Last stderr / status</p>
|
||||||
|
{typeof commandResult?.exitCode === 'number' && (
|
||||||
|
<span className="text-[10px] font-mono text-[var(--foreground-dim)]">
|
||||||
|
exit {commandResult.exitCode}{commandResult.executionMode ? ` · ${commandResult.executionMode}` : ''}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<pre className="mt-2 text-xs whitespace-pre-wrap break-words font-mono text-[var(--foreground)] min-h-16">{commandResult?.error || commandResult?.stderr || commandResult?.note || 'No stderr.'}</pre>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="grid grid-cols-1 xl:grid-cols-[1.1fr_0.9fr] gap-6">
|
||||||
<div className="panel p-6 space-y-5">
|
<div className="panel p-6 space-y-5">
|
||||||
<div className="flex items-center justify-between gap-3 flex-wrap">
|
<div className="flex items-center justify-between gap-3 flex-wrap">
|
||||||
<div>
|
<div>
|
||||||
<h3 className="text-sm font-semibold uppercase tracking-wider">Attach Instructions</h3>
|
<h3 className="text-sm font-semibold uppercase tracking-wider">Direct Attach Fallbacks</h3>
|
||||||
<p className="text-xs text-[var(--foreground-dim)] mt-2">
|
<p className="text-xs text-[var(--foreground-dim)] mt-2">
|
||||||
Preferred path is the SSH alias. If your shell environment is missing the alias or key wiring, use the explicit fallback. The readiness check below is now the page's single preflight source.
|
If the dashboard terminal is degraded, these remain the authoritative escape hatches.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
@@ -282,86 +436,6 @@ export default function OperatorTerminalPage() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4 space-y-3">
|
|
||||||
<div className="flex items-center justify-between gap-3 flex-wrap">
|
|
||||||
<div>
|
|
||||||
<p className="text-[10px] uppercase tracking-[0.2em] text-[var(--foreground-dim)] font-mono">Bounded shell reachability</p>
|
|
||||||
<p className="text-xs text-[var(--foreground-dim)] mt-2">
|
|
||||||
This is now captured as part of the readiness contract, so the page can show command execution reachability immediately on load.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div className="text-[11px] text-[var(--foreground-dim)] font-mono">
|
|
||||||
{data?.shellProbe?.ok ? 'Probe passed' : 'Probe not confirmed'}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-3">
|
|
||||||
<p className="text-[10px] uppercase tracking-[0.2em] text-[var(--foreground-dim)] font-mono">Probe stdout</p>
|
|
||||||
<pre className="mt-2 text-xs whitespace-pre-wrap break-words font-mono text-[var(--foreground)] min-h-16">{data?.shellProbe?.output || 'No backend shell output captured yet.'}</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-3">
|
|
||||||
<p className="text-[10px] uppercase tracking-[0.2em] text-[var(--foreground-dim)] font-mono">Probe stderr / status</p>
|
|
||||||
<pre className="mt-2 text-xs whitespace-pre-wrap break-words font-mono text-[var(--foreground)] min-h-16">{data?.shellProbe?.error || data?.shellProbe?.stderr || data?.note || 'No stderr.'}</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4 space-y-4">
|
|
||||||
<div className="flex items-center justify-between gap-3 flex-wrap">
|
|
||||||
<div>
|
|
||||||
<p className="text-[10px] uppercase tracking-[0.2em] text-[var(--foreground-dim)] font-mono">Bounded dashboard command runner</p>
|
|
||||||
<p className="text-xs text-[var(--foreground-dim)] mt-2">
|
|
||||||
Minimal in-dashboard execution while PTY transport is still pending. Runs a single bounded command through the dashboard backend against the selected sandbox.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div className="text-[11px] text-[var(--foreground-dim)] font-mono">
|
|
||||||
{commandState === 'running' ? 'Running…' : commandState === 'done' ? 'Last run succeeded' : commandState === 'error' ? 'Last run failed' : 'Idle'}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<label className="block">
|
|
||||||
<span className="text-[10px] uppercase tracking-[0.2em] text-[var(--foreground-dim)] font-mono">Command</span>
|
|
||||||
<textarea
|
|
||||||
value={commandInput}
|
|
||||||
onChange={(event) => setCommandInput(event.target.value)}
|
|
||||||
spellCheck={false}
|
|
||||||
rows={3}
|
|
||||||
className="mt-2 w-full rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] px-3 py-2 text-sm font-mono text-[var(--foreground)] focus:border-[var(--nvidia-green)] focus:outline-none"
|
|
||||||
placeholder="pwd && whoami"
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<div className="flex items-center gap-3 flex-wrap">
|
|
||||||
<button
|
|
||||||
onClick={runCommand}
|
|
||||||
disabled={commandState === 'running' || !sandboxId}
|
|
||||||
className="px-3 py-2 rounded-sm border border-[var(--border-subtle)] text-xs font-mono uppercase tracking-wider hover:border-[var(--nvidia-green)] disabled:opacity-50 disabled:cursor-not-allowed"
|
|
||||||
>
|
|
||||||
{commandState === 'running' ? 'Running Command…' : 'Run Bounded Command'}
|
|
||||||
</button>
|
|
||||||
<p className="text-[11px] text-[var(--foreground-dim)] font-mono">One-shot only. No persistent PTY state yet.</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="grid grid-cols-1 gap-3">
|
|
||||||
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-3">
|
|
||||||
<p className="text-[10px] uppercase tracking-[0.2em] text-[var(--foreground-dim)] font-mono">Command stdout</p>
|
|
||||||
<pre className="mt-2 text-xs whitespace-pre-wrap break-words font-mono text-[var(--foreground)] min-h-16">{commandResult?.stdout || 'No command output yet.'}</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-3 space-y-2">
|
|
||||||
<div className="flex items-center justify-between gap-3 flex-wrap">
|
|
||||||
<p className="text-[10px] uppercase tracking-[0.2em] text-[var(--foreground-dim)] font-mono">Command stderr / status</p>
|
|
||||||
{typeof commandResult?.exitCode === 'number' && (
|
|
||||||
<span className="text-[10px] font-mono text-[var(--foreground-dim)]">
|
|
||||||
exit {commandResult.exitCode}{commandResult.executionMode ? ` · ${commandResult.executionMode}` : ''}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<pre className="mt-2 text-xs whitespace-pre-wrap break-words font-mono text-[var(--foreground)] min-h-16">{commandResult?.error || commandResult?.stderr || commandResult?.note || 'No stderr.'}</pre>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{copyMessage && (
|
{copyMessage && (
|
||||||
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-3 text-xs text-[var(--foreground-dim)]">
|
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-3 text-xs text-[var(--foreground-dim)]">
|
||||||
{copyMessage}
|
{copyMessage}
|
||||||
@@ -373,7 +447,7 @@ export default function OperatorTerminalPage() {
|
|||||||
<div>
|
<div>
|
||||||
<h3 className="text-sm font-semibold uppercase tracking-wider">Readiness Evidence</h3>
|
<h3 className="text-sm font-semibold uppercase tracking-wider">Readiness Evidence</h3>
|
||||||
<p className="text-xs text-[var(--foreground-dim)] mt-2">
|
<p className="text-xs text-[var(--foreground-dim)] mt-2">
|
||||||
Live pod introspection and bounded shell evidence from the dashboard backend. This is the page's truth source until persistent PTY transport exists.
|
Live pod introspection and bounded shell evidence from the backend.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -390,27 +464,27 @@ export default function OperatorTerminalPage() {
|
|||||||
<p className="text-[10px] uppercase tracking-[0.2em] text-[var(--foreground-dim)] font-mono">Images</p>
|
<p className="text-[10px] uppercase tracking-[0.2em] text-[var(--foreground-dim)] font-mono">Images</p>
|
||||||
<p className="mt-2 font-mono break-words">{data?.pod?.images?.length ? data.pod.images.join(', ') : 'Unavailable'}</p>
|
<p className="mt-2 font-mono break-words">{data?.pod?.images?.length ? data.pod.images.join(', ') : 'Unavailable'}</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4">
|
|
||||||
<p className="text-[10px] uppercase tracking-[0.2em] text-[var(--foreground-dim)] font-mono">Running statuses</p>
|
|
||||||
<p className="mt-2 font-mono break-words">{data?.pod?.runningStatuses?.length ? data.pod.runningStatuses.join(', ') : 'Unavailable'}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4">
|
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4 space-y-3">
|
||||||
<p className="text-[10px] uppercase tracking-[0.2em] text-[var(--foreground-dim)] font-mono">Recovery notes</p>
|
<div className="flex items-center justify-between gap-3 flex-wrap">
|
||||||
<ul className="mt-2 space-y-2 text-xs text-[var(--foreground-dim)] list-disc pl-4">
|
<div>
|
||||||
<li>If the dashboard reports degraded but SSH still works, use the local attach command and treat the dashboard as degraded, not authoritative.</li>
|
<p className="text-[10px] uppercase tracking-[0.2em] text-[var(--foreground-dim)] font-mono">Shell probe</p>
|
||||||
<li>If SSH fails, verify the Mac host alias and key path first: <span className="font-mono text-[var(--foreground)]">~/.ssh/id_ed25519_openclaw_labmac</span>.</li>
|
<p className="text-xs text-[var(--foreground-dim)] mt-2">Readiness-side shell evidence.</p>
|
||||||
<li>If helper commands miss Homebrew binaries in non-interactive mode, use a login shell or prepend <span className="font-mono text-[var(--foreground)]">PATH=/opt/homebrew/bin:$PATH</span>.</li>
|
</div>
|
||||||
</ul>
|
<div className="text-[11px] text-[var(--foreground-dim)] font-mono">
|
||||||
</div>
|
{data?.shellProbe?.ok ? 'Probe passed' : 'Probe not confirmed'}
|
||||||
|
</div>
|
||||||
{(data?.note || data?.error) && (
|
|
||||||
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background-tertiary)] p-4 text-xs text-[var(--foreground-dim)] space-y-2">
|
|
||||||
{data?.note && <p><span className="text-[var(--foreground)]">Note:</span> {data.note}</p>}
|
|
||||||
{data?.error && <p><span className="text-[var(--status-stopped)]">Error:</span> {data.error}</p>}
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-3">
|
||||||
|
<p className="text-[10px] uppercase tracking-[0.2em] text-[var(--foreground-dim)] font-mono">Probe stdout</p>
|
||||||
|
<pre className="mt-2 text-xs whitespace-pre-wrap break-words font-mono text-[var(--foreground)] min-h-16">{data?.shellProbe?.output || 'No backend shell output captured yet.'}</pre>
|
||||||
|
</div>
|
||||||
|
<div className="rounded-sm border border-[var(--border-subtle)] bg-[var(--background)] p-3">
|
||||||
|
<p className="text-[10px] uppercase tracking-[0.2em] text-[var(--foreground-dim)] font-mono">Probe stderr / status</p>
|
||||||
|
<pre className="mt-2 text-xs whitespace-pre-wrap break-words font-mono text-[var(--foreground)] min-h-16">{data?.shellProbe?.error || data?.shellProbe?.stderr || data?.note || 'No stderr.'}</pre>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user