'use client' /** * NeuralPreFlight - SSH_COMMAND 安全預審面板 * =========================================== * 顯示 8 項安全審查結果 + 通過狀態 + 功能開關 * Sprint 3 指揮鏈可視化 + T1-T7 任務進度 */ import { useTranslations } from 'next-intl' import { CheckCircle2, AlertTriangle, ShieldCheck, ArrowRight, Shield, Database, Cpu, Key, Lock, GitBranch, Activity } from 'lucide-react' import { cn } from '@/lib/utils' import type { AutoRepairStats, PlaybookItem } from './types' // ============================================================================= // Audit items — 8 checks across A/B/C // ============================================================================= interface AuditCheck { id: string category: 'A' | 'B' | 'C' labelKey: string descKey: string status: 'fixed' | 'pending' | 'warning' } const AUDIT_CHECKS: AuditCheck[] = [ { id: 'A1', category: 'A', labelKey: 'checkA1Label', descKey: 'checkA1Desc', status: 'fixed' }, { id: 'A2', category: 'A', labelKey: 'checkA2Label', descKey: 'checkA2Desc', status: 'fixed' }, { id: 'A3', category: 'A', labelKey: 'checkA3Label', descKey: 'checkA3Desc', status: 'fixed' }, { id: 'B1', category: 'B', labelKey: 'checkB1Label', descKey: 'checkB1Desc', status: 'fixed' }, { id: 'B2', category: 'B', labelKey: 'checkB2Label', descKey: 'checkB2Desc', status: 'fixed' }, { id: 'C1', category: 'C', labelKey: 'checkC1Label', descKey: 'checkC1Desc', status: 'fixed' }, { id: 'C2', category: 'C', labelKey: 'checkC2Label', descKey: 'checkC2Desc', status: 'fixed' }, { id: 'C3', category: 'C', labelKey: 'checkC3Label', descKey: 'checkC3Desc', status: 'fixed' }, ] const CATEGORY_META = { A: { label: '安全性', color: 'text-orange-500', bg: 'bg-orange-500/10', border: 'border-orange-500/25' }, B: { label: '可觀測性', color: 'text-blue-500', bg: 'bg-blue-500/10', border: 'border-blue-500/25' }, C: { label: '系統架構', color: 'text-purple-500', bg: 'bg-purple-500/10', border: 'border-purple-500/25' }, } // ============================================================================= // Component // ============================================================================= interface Props { stats: AutoRepairStats | null playbooks: PlaybookItem[] } export function NeuralPreFlight({ stats, playbooks }: Props) { const t = useTranslations('neuralCommand') const totalChecks = AUDIT_CHECKS.length const fixedChecks = AUDIT_CHECKS.filter(c => c.status === 'fixed').length const allPassed = fixedChecks === totalChecks const categories = ['A', 'B', 'C'] as const return (
{/* ── Header meta ── */}

{t('preFlightTitle')}

{t('preFlightSubtitle')}

{t('progress')}
{fixedChecks} / {totalChecks}
{t('riskLevel')}
{t('riskLow')}
{t('auditStatus')}
{allPassed ? t('passed') : t('pending')}
{/* ── Pass banner ── */} {allPassed && (

{t('passBannerTitle')}

{t('passBannerDesc')}

)} {/* ── Three-column audit ── */}
{categories.map(cat => { const meta = CATEGORY_META[cat] const checks = AUDIT_CHECKS.filter(c => c.category === cat) return (
{cat} {meta.label}
{checks.map(check => (

{t(check.labelKey)}

{t(check.descKey)}

{check.status === 'fixed' ? t('statusFixed') : t('statusPending')}
))}
) })}
{/* ── Feature toggles ── */}

{t('featureToggles')}

{AUDIT_CHECKS.map(check => (

{check.id}: {t(check.labelKey)}

{t(check.descKey)}

{/* Toggle visual — always ON (reflects actual state) */}
))}
{/* ── Sprint 3 指揮鏈可視化 ── */}

Sprint 3 SSH 指揮權鏈 — 神經嫁接架構

{/* Chain nodes */}
{[ { icon: Shield, label: 'SSH Gateway', sub: 'Port 22 + 白名單', color: 'text-orange-500', bg: 'bg-orange-500/10', border: 'border-orange-500/30' }, { icon: Key, label: 'URI 解析器', sub: 'openclaw:// ansible:// ssh://', color: 'text-blue-500', bg: 'bg-blue-500/10', border: 'border-blue-500/30' }, { icon: Lock, label: 'Shell 防注入', sub: '; | && $() 阻斷', color: 'text-purple-500', bg: 'bg-purple-500/10', border: 'border-purple-500/30' }, { icon: Cpu, label: 'Redis 冪等鎖', sub: 'repair_lock TTL 300s', color: 'text-green-500', bg: 'bg-green-500/10', border: 'border-green-500/30' }, { icon: Database, label: 'Ansible Playbook DB', sub: '.188 控制節點 → .110', color: 'text-yellow-500', bg: 'bg-yellow-500/10', border: 'border-yellow-500/30' }, ].map((node, i, arr) => { const Icon = node.icon return (

{node.label}

{node.sub}

{i < arr.length - 1 && ( )}
) })}
{/* T1-T7 任務進度 */}
{[ { id: 'T1', label: 'URI 解析器', desc: 'Shell 防注入', done: true }, { id: 'T2', label: 'known_hosts', desc: 'K8s Secret', done: true }, { id: 'T3', label: '三條執行路徑', desc: 'HostRepairAgent', done: false }, { id: 'T4', label: 'Redis 鎖', desc: '冪等保護', done: false }, { id: 'T5', label: 'AuditLog', desc: 'Langfuse Trace', done: false }, { id: 'T6', label: 'Service 整合', desc: '成功率回饋', done: false }, { id: 'T7', label: 'Ansible 部署', desc: 'E2E 驗證', done: false }, ].map(task => (

{task.id}

{task.label}

{task.desc}

{task.done &&

✓ 完成

}
))}
{/* Implementation metrics */}
{[ { label: '實作總速度', value: '28%', sub: 'T1-T2 完成', color: 'text-blue-500' }, { label: '安全防禦等級', value: 'A', sub: '注入/known_hosts/鎖', color: 'text-green-500' }, { label: '可觀測性', value: '計劃中', sub: 'T5 Langfuse+AuditLog', color: 'text-orange-500' }, { label: '架構健康度', value: '優良', sub: 'URI scheme 設計', color: 'text-purple-500' }, ].map(m => (

{m.value}

{m.label}

{m.sub}

))}
{/* ── Playbook count summary ── */}
{[ { label: t('approvedPlaybooks'), value: stats?.approved_playbooks ?? playbooks.length, color: 'text-green-500' }, { label: t('highQuality'), value: stats?.high_quality_playbooks ?? 0, color: 'text-blue-500' }, { label: t('totalExecutions'), value: stats?.total_executions ?? 0, color: 'text-orange-500' }, { label: t('successRate'), value: `${Math.round((stats?.overall_success_rate ?? 0) * 100)}%`, color: 'text-purple-500' }, ].map(({ label, value, color }) => (

{value}

{label}

))}
) }