All files / src/components SecurityLayersPanel.tsx

0% Statements 0/584
0% Branches 0/1
0% Functions 0/1
0% Lines 0/584

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
import { useState, useEffect } from 'react';
import {
  Shield,
  ShieldCheck,
  ShieldAlert,
  ShieldX,
  ChevronDown,
  ChevronRight,
  Key,
  Users,
  Gauge,
  Clock,
  LockKeyhole,
  FileText,
  CheckCircle2,
  Box,
  Globe,
  Cpu,
  DoorOpen as Gate,
  MessageSquareWarning,
  Filter,
  Radar,
  Siren,
  RefreshCw,
  Lock,
  Wifi,
  WifiOff,
} from 'lucide-react';
import type { SecurityLayer, SecurityStatus } from '../store/securityStore';
import { useSecurityStore } from '../store/securityStore';
import { useConnectionStore } from '../store/connectionStore';
 
// OpenFang 16-layer security architecture definitions
export const SECURITY_LAYERS: Array<{
  id: string;
  name: string;
  nameZh: string;
  description: string;
  category: 'input' | 'auth' | 'authz' | 'rate' | 'session' | 'encryption' | 'audit' | 'integrity' | 'sandbox' | 'network' | 'resource' | 'capability' | 'prompt' | 'output' | 'anomaly' | 'incident';
  icon: React.ComponentType<{ className?: string }>;
}> = [
  {
    id: 'input.validation',
    name: 'Input Validation Layer',
    nameZh: '输入验证',
    description: 'Validates and sanitizes all user inputs to prevent injection attacks and malformed data.',
    category: 'input',
    icon: Filter,
  },
  {
    id: 'auth.identity',
    name: 'Authentication Layer',
    nameZh: '身份认证',
    description: 'Ed25519 cryptographic authentication with JWT tokens for secure identity verification.',
    category: 'auth',
    icon: Key,
  },
  {
    id: 'auth.rbac',
    name: 'Authorization Layer (RBAC)',
    nameZh: '权限控制',
    description: 'Role-based access control with fine-grained permissions and capability gates.',
    category: 'authz',
    icon: Users,
  },
  {
    id: 'rate.limit',
    name: 'Rate Limiting Layer',
    nameZh: '速率限制',
    description: 'Prevents abuse by limiting request frequency per user, IP, and endpoint.',
    category: 'rate',
    icon: Gauge,
  },
  {
    id: 'session.management',
    name: 'Session Management Layer',
    nameZh: '会话管理',
    description: 'Secure session handling with automatic expiration, rotation, and invalidation.',
    category: 'session',
    icon: Clock,
  },
  {
    id: 'encryption',
    name: 'Encryption Layer',
    nameZh: '数据加密',
    description: 'End-to-end encryption for data at rest and in transit using AES-256-GCM.',
    category: 'encryption',
    icon: LockKeyhole,
  },
  {
    id: 'audit.logging',
    name: 'Audit Logging Layer',
    nameZh: '审计日志',
    description: 'Merkle hash chain audit logging for tamper-evident operation records.',
    category: 'audit',
    icon: FileText,
  },
  {
    id: 'integrity',
    name: 'Integrity Verification Layer',
    nameZh: '完整性验证',
    description: 'Cryptographic verification of code and data integrity using SHA-256 hashes.',
    category: 'integrity',
    icon: CheckCircle2,
  },
  {
    id: 'sandbox',
    name: 'Sandbox Isolation Layer',
    nameZh: '沙箱隔离',
    description: 'Isolated execution environments for untrusted code and operations.',
    category: 'sandbox',
    icon: Box,
  },
  {
    id: 'network.security',
    name: 'Network Security Layer',
    nameZh: '网络安全',
    description: 'TLS 1.3 encryption, firewall rules, and network segmentation.',
    category: 'network',
    icon: Globe,
  },
  {
    id: 'resource.limits',
    name: 'Resource Limits Layer',
    nameZh: '资源限制',
    description: 'Memory, CPU, and I/O limits to prevent resource exhaustion attacks.',
    category: 'resource',
    icon: Cpu,
  },
  {
    id: 'capability.gates',
    name: 'Capability Gates Layer',
    nameZh: '能力门控',
    description: 'Explicit permission gates for sensitive operations like file access and network calls.',
    category: 'capability',
    icon: Gate,
  },
  {
    id: 'prompt.defense',
    name: 'Prompt Injection Defense',
    nameZh: '提示注入防御',
    description: 'Detects and mitigates prompt injection and jailbreak attempts.',
    category: 'prompt',
    icon: MessageSquareWarning,
  },
  {
    id: 'output.filter',
    name: 'Output Filtering Layer',
    nameZh: '输出过滤',
    description: 'Filters sensitive information from outputs and enforces content policies.',
    category: 'output',
    icon: Filter,
  },
  {
    id: 'anomaly.detection',
    name: 'Anomaly Detection Layer',
    nameZh: '异常检测',
    description: 'ML-based detection of unusual patterns and potential security threats.',
    category: 'anomaly',
    icon: Radar,
  },
  {
    id: 'incident.response',
    name: 'Incident Response Layer',
    nameZh: '事件响应',
    description: 'Automated incident detection, alerting, and response orchestration.',
    category: 'incident',
    icon: Siren,
  },
];
 
// Category groupings for UI organization
const LAYER_CATEGORIES = {
  perimeter: {
    label: 'Perimeter Defense',
    labelZh: '边界防护',
    layers: ['input.validation', 'network.security', 'rate.limit'],
  },
  identity: {
    label: 'Identity & Access',
    labelZh: '身份与访问',
    layers: ['auth.identity', 'auth.rbac', 'session.management'],
  },
  data: {
    label: 'Data Protection',
    labelZh: '数据保护',
    layers: ['encryption', 'integrity', 'output.filter'],
  },
  execution: {
    label: 'Execution Safety',
    labelZh: '执行安全',
    layers: ['sandbox', 'resource.limits', 'capability.gates', 'prompt.defense'],
  },
  monitoring: {
    label: 'Monitoring & Response',
    labelZh: '监控与响应',
    layers: ['audit.logging', 'anomaly.detection', 'incident.response'],
  },
} as const;
 
interface LayerStatus {
  status: 'active' | 'warning' | 'inactive';
  details?: string;
}
 
function getLayerStatus(layer: SecurityLayer): LayerStatus {
  if (layer.enabled) {
    return { status: 'active', details: layer.description };
  }
  return { status: 'inactive', details: layer.description };
}
 
function getStatusIcon(status: 'active' | 'warning' | 'inactive') {
  switch (status) {
    case 'active':
      return <ShieldCheck className="w-4 h-4 text-green-500" />;
    case 'warning':
      return <ShieldAlert className="w-4 h-4 text-yellow-500" />;
    case 'inactive':
      return <ShieldX className="w-4 h-4 text-red-400" />;
  }
}
 
function getStatusColor(status: 'active' | 'warning' | 'inactive') {
  switch (status) {
    case 'active':
      return 'bg-green-50 border-green-200 text-green-700';
    case 'warning':
      return 'bg-yellow-50 border-yellow-200 text-yellow-700';
    case 'inactive':
      return 'bg-gray-50 border-gray-200 text-gray-500';
  }
}
 
interface LayerRowProps {
  layerDef: typeof SECURITY_LAYERS[0];
  status: LayerStatus;
  expanded: boolean;
  onToggle: () => void;
}
 
function LayerRow({ layerDef, status, expanded, onToggle }: LayerRowProps) {
  const Icon = layerDef.icon;
 
  return (
    <div className={`rounded-lg border transition-all ${getStatusColor(status.status)}`}>
      <button
        onClick={onToggle}
        className="w-full flex items-center gap-3 px-3 py-2.5 text-left"
      >
        <Icon className="w-4 h-4 flex-shrink-0" />
        <div className="flex-1 min-w-0">
          <div className="flex items-center gap-2">
            <span className="text-sm font-medium truncate">{layerDef.nameZh}</span>
            <span className="text-xs opacity-60 truncate">{layerDef.name}</span>
          </div>
        </div>
        {getStatusIcon(status.status)}
        {expanded ? (
          <ChevronDown className="w-4 h-4 opacity-50" />
        ) : (
          <ChevronRight className="w-4 h-4 opacity-50" />
        )}
      </button>
      {expanded && (
        <div className="px-3 pb-3 pt-0">
          <p className="text-xs leading-relaxed opacity-80">{layerDef.description}</p>
          {status.details && status.details !== layerDef.description && (
            <p className="text-xs mt-1 opacity-60">{status.details}</p>
          )}
        </div>
      )}
    </div>
  );
}
 
interface CategorySectionProps {
  categoryKey: keyof typeof LAYER_CATEGORIES;
  layers: SecurityLayer[];
  expandedLayers: Set<string>;
  onToggleLayer: (id: string) => void;
}
 
function CategorySection({
  categoryKey,
  layers,
  expandedLayers,
  onToggleLayer,
}: CategorySectionProps) {
  const category = LAYER_CATEGORIES[categoryKey];
  const categoryLayers = category.layers
    .map((id) => SECURITY_LAYERS.find((l) => l.id === id))
    .filter(Boolean)
    .map((layerDef) => {
      const apiLayer = layers.find((l) => l.name === layerDef!.id);
      return {
        def: layerDef!,
        status: getLayerStatus(apiLayer || { name: layerDef!.id, enabled: false }),
      };
    });
 
  const activeCount = categoryLayers.filter((l) => l.status.status === 'active').length;
  const totalCount = categoryLayers.length;
 
  return (
    <div className="space-y-2">
      <div className="flex items-center justify-between px-1">
        <span className="text-xs font-medium text-gray-600">{category.labelZh}</span>
        <span className={`text-xs ${activeCount === totalCount ? 'text-green-600' : 'text-gray-400'}`}>
          {activeCount}/{totalCount}
        </span>
      </div>
      <div className="space-y-1.5">
        {categoryLayers.map(({ def, status }) => (
          <LayerRow
            key={def.id}
            layerDef={def}
            status={status}
            expanded={expandedLayers.has(def.id)}
            onToggle={() => onToggleLayer(def.id)}
          />
        ))}
      </div>
    </div>
  );
}
 
interface SecurityLayersPanelProps {
  status: SecurityStatus;
  className?: string;
}
 
export function SecurityLayersPanel({ status, className = '' }: SecurityLayersPanelProps) {
  const [expandedLayers, setExpandedLayers] = useState<Set<string>>(new Set());
  const [expandedCategories, setExpandedCategories] = useState<Set<string>>(
    new Set(Object.keys(LAYER_CATEGORIES))
  );
 
  const toggleLayer = (id: string) => {
    setExpandedLayers((prev) => {
      const next = new Set(prev);
      if (next.has(id)) {
        next.delete(id);
      } else {
        next.add(id);
      }
      return next;
    });
  };
 
  const toggleCategory = (key: string) => {
    setExpandedCategories((prev) => {
      const next = new Set(prev);
      if (next.has(key)) {
        next.delete(key);
      } else {
        next.add(key);
      }
      return next;
    });
  };
 
  // Calculate security score
  const activeLayers = status.layers.filter((l) => l.enabled).length;
  const totalLayers = SECURITY_LAYERS.length;
  const score = Math.round((activeLayers / totalLayers) * 100);
 
  return (
    <div className={`space-y-4 ${className}`}>
      {/* Security Score Circle */}
      <div className="flex items-center justify-center py-4">
        <div className="relative w-32 h-32">
          <svg className="w-full h-full transform -rotate-90" viewBox="0 0 100 100">
            {/* Background circle */}
            <circle
              cx="50"
              cy="50"
              r="45"
              fill="none"
              stroke="currentColor"
              strokeWidth="8"
              className="text-gray-100"
            />
            {/* Progress circle */}
            <circle
              cx="50"
              cy="50"
              r="45"
              fill="none"
              stroke="currentColor"
              strokeWidth="8"
              strokeLinecap="round"
              strokeDasharray={`${score * 2.83} 283`}
              className={
                score >= 90
                  ? 'text-green-500'
                  : score >= 70
                  ? 'text-blue-500'
                  : score >= 50
                  ? 'text-yellow-500'
                  : 'text-red-500'
              }
            />
          </svg>
          <div className="absolute inset-0 flex flex-col items-center justify-center">
            <span
              className={`text-3xl font-bold ${
                score >= 90
                  ? 'text-green-600'
                  : score >= 70
                  ? 'text-blue-600'
                  : score >= 50
                  ? 'text-yellow-600'
                  : 'text-red-600'
              }`}
            >
              {score}
            </span>
            <span className="text-xs text-gray-500">Security Score</span>
          </div>
        </div>
      </div>
 
      {/* Summary Stats */}
      <div className="grid grid-cols-3 gap-3 px-1">
        <div className="text-center">
          <div className="text-lg font-semibold text-green-600">{activeLayers}</div>
          <div className="text-xs text-gray-500">Active</div>
        </div>
        <div className="text-center">
          <div className="text-lg font-semibold text-yellow-600">
            {status.layers.filter((l) => !l.enabled).length}
          </div>
          <div className="text-xs text-gray-500">Inactive</div>
        </div>
        <div className="text-center">
          <div className="text-lg font-semibold text-gray-600">{totalLayers}</div>
          <div className="text-xs text-gray-500">Total</div>
        </div>
      </div>
 
      {/* Category Sections */}
      <div className="space-y-4">
        {(Object.keys(LAYER_CATEGORIES) as Array<keyof typeof LAYER_CATEGORIES>).map(
          (categoryKey) => (
            <div key={categoryKey} className="bg-gray-50 rounded-lg p-3">
              <button
                onClick={() => toggleCategory(categoryKey)}
                className="w-full flex items-center justify-between mb-2"
              >
                <div className="flex items-center gap-2">
                  <Shield className="w-4 h-4 text-gray-500" />
                  <span className="text-sm font-medium text-gray-700">
                    {LAYER_CATEGORIES[categoryKey].labelZh}
                  </span>
                </div>
                {expandedCategories.has(categoryKey) ? (
                  <ChevronDown className="w-4 h-4 text-gray-400" />
                ) : (
                  <ChevronRight className="w-4 h-4 text-gray-400" />
                )}
              </button>
              {expandedCategories.has(categoryKey) && (
                <CategorySection
                  categoryKey={categoryKey}
                  layers={status.layers}
                  expandedLayers={expandedLayers}
                  onToggleLayer={toggleLayer}
                />
              )}
            </div>
          )
        )}
      </div>
    </div>
  );
}
 
// Utility function to calculate security score
export function calculateSecurityScore(layers: SecurityLayer[]): number {
  const activeCount = layers.filter((l) => l.enabled).length;
  return Math.round((activeCount / SECURITY_LAYERS.length) * 100);
}
 
// ZCLAW 默认安全状态(独立于 OpenFang)
export function getDefaultSecurityStatus(): SecurityStatus {
  // ZCLAW 默认启用的安全层
  const defaultEnabledLayers = [
    'input.validation',
    'auth.identity',
    'session.management',
    'encryption',
    'audit.logging',
    'integrity',
    'sandbox',
    'network.security',
    'capability.gates',
    'prompt.defense',
    'output.filter',
    'anomaly.detection',
  ];
 
  const layers: SecurityLayer[] = SECURITY_LAYERS.map((layer) => ({
    name: layer.id,
    enabled: defaultEnabledLayers.includes(layer.id),
    description: layer.description,
  }));
 
  const enabledCount = layers.filter((l) => l.enabled).length;
 
  return {
    layers,
    enabledCount,
    totalCount: layers.length,
    securityLevel: enabledCount >= 12 ? 'critical' : enabledCount >= 8 ? 'high' : 'medium',
  };
}
 
// === 独立安全状态面板组件 ===
 
interface SecurityStatusPanelProps {
  className?: string;
}
 
export function SecurityStatusPanel({ className = '' }: SecurityStatusPanelProps) {
  const securityStatus = useSecurityStore((s) => s.securityStatus);
  const securityStatusLoading = useSecurityStore((s) => s.securityStatusLoading);
  const loadSecurityStatus = useSecurityStore((s) => s.loadSecurityStatus);
  const connectionState = useConnectionStore((s) => s.connectionState);
  const [localStatus, setLocalStatus] = useState<SecurityStatus>(getDefaultSecurityStatus());
  const [refreshing, setRefreshing] = useState(false);
 
  const connected = connectionState === 'connected';
 
  // 加载安全状态
  useEffect(() => {
    if (connected) {
      loadSecurityStatus();
    }
  }, [connected, loadSecurityStatus]);
 
  // 当从 API 获取到安全状态时,使用 API 数据,否则使用本地默认状态
  const displayStatus = connected && securityStatus ? securityStatus : localStatus;
 
  const handleRefresh = async () => {
    setRefreshing(true);
    try {
      if (connected) {
        await loadSecurityStatus();
      } else {
        // 如果没有连接,刷新本地状态
        setLocalStatus(getDefaultSecurityStatus());
      }
    } finally {
      setRefreshing(false);
    }
  };
 
  const score = calculateSecurityScore(displayStatus.layers);
 
  return (
    <div className={`space-y-4 ${className}`}>
      {/* 头部 */}
      <div className="flex items-center justify-between">
        <div className="flex items-center gap-2">
          <Shield className="w-5 h-5 text-blue-500" />
          <h2 className="text-lg font-semibold text-gray-900 dark:text-white">安全状态</h2>
        </div>
        <div className="flex items-center gap-2">
          <span className={`text-xs flex items-center gap-1 ${connected ? 'text-green-600' : 'text-gray-400'}`}>
            {connected ? <Wifi className="w-3 h-3" /> : <WifiOff className="w-3 h-3" />}
            {connected ? '已连接' : '本地模式'}
          </span>
          <button
            onClick={handleRefresh}
            disabled={refreshing || securityStatusLoading}
            className="p-1.5 text-gray-400 hover:text-blue-500 rounded-md transition-colors disabled:opacity-50"
            title="刷新安全状态"
          >
            <RefreshCw className={`w-4 h-4 ${refreshing || securityStatusLoading ? 'animate-spin' : ''}`} />
          </button>
        </div>
      </div>
 
      {/* 安全评分 */}
      <div className="flex items-center justify-center py-4">
        <div className="relative w-28 h-28">
          <svg className="w-full h-full transform -rotate-90" viewBox="0 0 100 100">
            <circle
              cx="50"
              cy="50"
              r="45"
              fill="none"
              stroke="currentColor"
              strokeWidth="8"
              className="text-gray-100 dark:text-gray-700"
            />
            <circle
              cx="50"
              cy="50"
              r="45"
              fill="none"
              stroke="currentColor"
              strokeWidth="8"
              strokeLinecap="round"
              strokeDasharray={`${score * 2.83} 283`}
              className={
                score >= 90
                  ? 'text-green-500'
                  : score >= 70
                  ? 'text-blue-500'
                  : score >= 50
                  ? 'text-yellow-500'
                  : 'text-red-500'
              }
            />
          </svg>
          <div className="absolute inset-0 flex flex-col items-center justify-center">
            <span
              className={`text-2xl font-bold ${
                score >= 90
                  ? 'text-green-600'
                  : score >= 70
                  ? 'text-blue-600'
                  : score >= 50
                  ? 'text-yellow-600'
                  : 'text-red-600'
              }`}
            >
              {score}
            </span>
            <span className="text-[10px] text-gray-500">安全评分</span>
          </div>
        </div>
      </div>
 
      {/* 状态统计 */}
      <div className="grid grid-cols-3 gap-3">
        <div className="bg-green-50 dark:bg-green-900/20 rounded-lg p-3 text-center">
          <div className="text-lg font-semibold text-green-600">
            {displayStatus.layers.filter((l) => l.enabled).length}
          </div>
          <div className="text-xs text-green-600">已启用</div>
        </div>
        <div className="bg-yellow-50 dark:bg-yellow-900/20 rounded-lg p-3 text-center">
          <div className="text-lg font-semibold text-yellow-600">
            {displayStatus.layers.filter((l) => !l.enabled).length}
          </div>
          <div className="text-xs text-yellow-600">未启用</div>
        </div>
        <div className="bg-gray-50 dark:bg-gray-800 rounded-lg p-3 text-center">
          <div className="text-lg font-semibold text-gray-600">
            {displayStatus.totalCount}
          </div>
          <div className="text-xs text-gray-500">总层数</div>
        </div>
      </div>
 
      {/* 安全等级 */}
      <div className={`rounded-lg p-3 border ${
        displayStatus.securityLevel === 'critical'
          ? 'bg-green-50 border-green-200'
          : displayStatus.securityLevel === 'high'
          ? 'bg-blue-50 border-blue-200'
          : 'bg-yellow-50 border-yellow-200'
      }`}>
        <div className="flex items-center gap-2">
          <Lock className={`w-4 h-4 ${
            displayStatus.securityLevel === 'critical'
              ? 'text-green-600'
              : displayStatus.securityLevel === 'high'
              ? 'text-blue-600'
              : 'text-yellow-600'
          }`} />
          <span className={`text-sm font-medium ${
            displayStatus.securityLevel === 'critical'
              ? 'text-green-700'
              : displayStatus.securityLevel === 'high'
              ? 'text-blue-700'
              : 'text-yellow-700'
          }`}>
            {displayStatus.securityLevel === 'critical'
              ? '最高安全等级'
              : displayStatus.securityLevel === 'high'
              ? '高安全等级'
              : '中等安全等级'}
          </span>
        </div>
        <p className="text-xs text-gray-500 mt-1">
          {!connected && 'ZCLAW 默认安全配置。连接 OpenFang 后可获取完整安全状态。'}
        </p>
      </div>
 
      {/* 快速查看安全层 */}
      <div className="space-y-2">
        <h3 className="text-xs font-semibold text-gray-500 uppercase tracking-wider">安全层概览</h3>
        <div className="flex flex-wrap gap-1.5">
          {SECURITY_LAYERS.slice(0, 8).map((layer) => {
            const isEnabled = displayStatus.layers.find((l) => l.name === layer.id)?.enabled ?? false;
            const Icon = layer.icon;
            return (
              <div
                key={layer.id}
                className={`flex items-center gap-1 px-2 py-1 rounded-md text-xs ${
                  isEnabled
                    ? 'bg-green-50 text-green-700'
                    : 'bg-gray-100 text-gray-500'
                }`}
                title={layer.nameZh}
              >
                <Icon className="w-3 h-3" />
                <span className="hidden sm:inline">{layer.nameZh}</span>
              </div>
            );
          })}
          <div className="flex items-center gap-1 px-2 py-1 rounded-md text-xs bg-gray-50 text-gray-400">
            <span>+8 层</span>
          </div>
        </div>
      </div>
    </div>
  );
}
 
// Export layer definitions for use in other components
export { SECURITY_LAYERS as SECURITY_LAYERS_DEFINITION };