import { useState, useEffect } from 'react'; import { Terminal, CheckCircle, XCircle, Shield, History } from 'lucide-react'; import { Button, Card, CardHeader, CardTitle, CardContent, Badge } from '@/components/ui'; import { Link } from 'react-router-dom'; import { checkKubectlInstalledCmd, listCommandExecutionsCmd, type KubectlStatus, type CommandExecution, } from '@/lib/tauriCommands'; export default function ShellExecution() { const [kubectlStatus, setKubectlStatus] = useState(null); const [executions, setExecutions] = useState([]); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(''); const loadKubectlStatus = async () => { try { const status = await checkKubectlInstalledCmd(); setKubectlStatus(status); } catch (err) { setError(String(err)); } }; const loadExecutions = async () => { setIsLoading(true); try { const data = await listCommandExecutionsCmd(); setExecutions(data); } catch (err) { setError(String(err)); } finally { setIsLoading(false); } }; useEffect(() => { loadKubectlStatus(); loadExecutions(); }, []); const getTierBadge = (tier: number) => { const colors = { 1: 'bg-green-100 text-green-700 border-green-300', 2: 'bg-yellow-100 text-yellow-700 border-yellow-300', 3: 'bg-red-100 text-red-700 border-red-300', }; return colors[tier as keyof typeof colors] || colors[1]; }; const getStatusBadge = (status: string) => { const config = { auto: { label: 'Auto-executed', color: 'bg-blue-100 text-blue-700 border-blue-300' }, approved: { label: 'Approved', color: 'bg-green-100 text-green-700 border-green-300' }, denied: { label: 'Denied', color: 'bg-red-100 text-red-700 border-red-300' }, }; const statusConfig = config[status as keyof typeof config] || config.auto; return statusConfig; }; return (

Shell Execution

Configure and monitor autonomous shell command execution with intelligent safety controls

{error && (
{error}
)} {/* kubectl Status */} kubectl Status {kubectlStatus ? ( <>
{kubectlStatus.installed ? ( <> kubectl is installed ) : ( <> kubectl is not installed )}
{kubectlStatus.path && (
Path: {kubectlStatus.path}
)} {kubectlStatus.version && (
{kubectlStatus.version}
)} ) : (

Checking kubectl status...

)}
{/* Safety Architecture */} Safety Architecture

Commands are automatically classified into three safety tiers:

Tier 1
Auto-execute (Read-only)
kubectl get, describe, logs | cat, grep, ls
Tier 2
Require approval (Mutating)
kubectl apply, delete, scale | ssh, chmod, systemctl restart
Tier 3
Always deny (Destructive)
rm -rf, shutdown, mkfs, dd
{/* Command Execution History */} Recent Command Executions ({executions.length}) {isLoading ? (

Loading...

) : executions.length === 0 ? (

No command executions yet

) : (
{executions.slice(0, 10).map((exec) => { const statusConfig = getStatusBadge(exec.approval_status); return (
{exec.command}
T{exec.tier} {statusConfig.label}
{exec.exit_code !== undefined && ( Exit: {exec.exit_code} )} {exec.execution_time_ms !== undefined && ( {exec.execution_time_ms}ms )} {new Date(exec.executed_at).toLocaleString()}
{exec.stdout && (
Show output
                          {exec.stdout}
                        
)}
); })}
)}
); }