cm-dashboard/CLAUDE.md
Christoffer Martinsson 8cb5650fbb Implement complete keyboard navigation and UI enhancement
Phase 1 - Panel Navigation:
- Add PanelType enum and panel focus state management
- Implement Shift+Tab cycling between panels (System → Services → Backup → Network)
- Add visual focus indicators with blue borders for focused panels
- Preserve existing Tab behavior for host switching

Phase 2 - Dynamic Statusbar:
- Add bottom statusbar with context-aware shortcuts
- Display different shortcuts based on focused panel
- Global shortcuts: Tab, Shift+Tab, Up/Down arrows, Q
- Panel-specific shortcuts: R (Rebuild), Space/R (Services), B (Backup), N (Network)

Phase 3 - Scrolling Support:
- Add scroll state management per host and panel type
- Implement Up/Down arrow key scrolling within focused panels
- Smart scrolling that activates only when content exceeds panel height
- Scroll bounds checking to prevent over-scrolling

Complete keyboard navigation experience with visual feedback and contextual help.
2025-10-23 20:34:45 +02:00

7.5 KiB

CM Dashboard - Infrastructure Monitoring TUI

Overview

A high-performance Rust-based TUI dashboard for monitoring CMTEC infrastructure. Built to replace Glance with a custom solution tailored for our specific monitoring needs and ZMQ-based metric collection.

Implementation Strategy

Current Implementation Status

System Panel Enhancement - COMPLETED

All system panel features successfully implemented:

  • NixOS Collector: Created collector for version and active users
  • System Widget: Unified widget combining NixOS, CPU, RAM, and Storage
  • Build Display: Shows NixOS build information without codename
  • Active Users: Displays currently logged in users
  • Tmpfs Monitoring: Added /tmp usage to RAM section
  • Agent Deployment: NixOS collector working in production

Current Status - October 23, 2025:

  • Agent successfully collecting NixOS metrics (confirmed in logs)
  • Dashboard shows "Build: unknown" - investigating metric reception/display
  • Tmpfs monitoring working correctly in RAM section
  • All other system metrics functioning properly

Layout Achieved:

NixOS:
Build: 25.05.20251004.3bcc93c  # Target (currently shows "unknown")
Active users: cm, simon
CPU:
● Load: 0.02 0.31 0.86 • 3000MHz
RAM:
● Usage: 33% 2.6GB/7.6GB  
● /tmp: 0% 0B/2.0GB  
Storage:  
● root (Single):  
 ├─ ● nvme0n1 W: 1%
 └─ ● 18% 167.4GB/928.2GB

Current Status - October 23, 2025:

  • System panel layout fully implemented with blue tree symbols
  • Backup panel layout restructured per specification
  • Tree symbols now use consistent blue theming across all panels
  • Overflow handling restored for all widgets ("... and X more")
  • Agent hash display working correctly

Next Implementation Phase: Keyboard Navigation & UI Enhancement

Phase 1 - Panel Navigation (In Progress):

  • Add panel focus state management to TuiApp
  • Implement Shift-Tab for panel cycling (System → Services → Backup → Network)
  • Keep Tab for host switching as current behavior
  • Add visual focus indicators to panel borders

Phase 2 - Dynamic Statusbar:

  • Create bottom statusbar showing context-aware shortcuts
  • System panel: "R: Rebuild", "S: Services"
  • Services panel: "Space: Start/Stop", "R: Restart"
  • Backup panel: "B: Trigger Backup"
  • Global: "Tab: Switch Host", "Shift-Tab: Switch Panel"

Phase 3 - Scrolling Support:

  • Add Up/Down arrow key handling within focused panels
  • Implement scroll offset tracking for overflow content
  • Add scroll position indicators (↑/↓) when needed

Future - Remote Execution:

  • Remote nixos rebuild commands via dashboard
  • Service start/stop/restart controls
  • Backup trigger functionality

Core Architecture Principles - CRITICAL

Individual Metrics Philosophy

NEW ARCHITECTURE: Agent collects individual metrics, dashboard composes widgets from those metrics.

Maintenance Mode

Purpose:

  • Suppress email notifications during planned maintenance or backups
  • Prevents false alerts when services are intentionally stopped

Implementation:

  • Agent checks for /tmp/cm-maintenance file before sending notifications
  • File presence suppresses all email notifications while continuing monitoring
  • Dashboard continues to show real status, only notifications are blocked

Usage:

# Enable maintenance mode
touch /tmp/cm-maintenance

# Run maintenance tasks (backups, service restarts, etc.)
systemctl stop service
# ... maintenance work ...
systemctl start service

# Disable maintenance mode
rm /tmp/cm-maintenance

NixOS Integration:

  • Borgbackup script automatically creates/removes maintenance file
  • Automatic cleanup via trap ensures maintenance mode doesn't stick
  • All cinfiguration are shall be done from nixos config

ARCHITECTURE ENFORCEMENT:

  • ZERO legacy code reuse - Fresh implementation following ARCHITECT.md exactly
  • Individual metrics only - NO grouped metric structures
  • Reference-only legacy - Study old functionality, implement new architecture
  • Clean slate mindset - Build as if legacy codebase never existed

Implementation Rules:

  1. Individual Metrics: Each metric is collected, transmitted, and stored individually
  2. Agent Status Authority: Agent calculates status for each metric using thresholds
  3. Dashboard Composition: Dashboard widgets subscribe to specific metrics by name
  4. Status Aggregation: Dashboard aggregates individual metric statuses for widget status Testing & Building:
  • Workspace builds: cargo build --workspace for all testing
  • Clean compilation: Remove target/ between architecture changes
  • ZMQ testing: Test agent-dashboard communication independently
  • Widget testing: Verify UI layout matches legacy appearance exactly

NEVER in New Implementation:

  • Copy/paste ANY code from legacy backup
  • Calculate status in dashboard widgets
  • Hardcode metric names in widgets (use const arrays)

Important Communication Guidelines

NEVER write that you have "successfully implemented" something or generate extensive summary text without first verifying with the user that the implementation is correct. This wastes tokens. Keep responses concise.

NEVER implement code without first getting explicit user agreement on the approach. Always ask for confirmation before proceeding with implementation.

Commit Message Guidelines

NEVER mention:

  • Claude or any AI assistant names
  • Automation or AI-generated content
  • Any reference to automated code generation

ALWAYS:

  • Focus purely on technical changes and their purpose
  • Use standard software development commit message format
  • Describe what was changed and why, not how it was created
  • Write from the perspective of a human developer

Examples:

  • "Generated with Claude Code"
  • "AI-assisted implementation"
  • "Automated refactoring"
  • "Implement maintenance mode for backup operations"
  • "Restructure storage widget with improved layout"
  • "Update CPU thresholds to production values"

NixOS Configuration Updates

When code changes are made to cm-dashboard, the NixOS configuration at ~/nixosbox must be updated to deploy the changes.

Update Process

  1. Get Latest Commit Hash

    git log -1 --format="%H"
    
  2. Update NixOS Configuration Edit ~/nixosbox/hosts/common/cm-dashboard.nix:

    src = pkgs.fetchgit {
      url = "https://gitea.cmtec.se/cm/cm-dashboard.git";
      rev = "NEW_COMMIT_HASH_HERE";
      sha256 = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; # Placeholder
    };
    
  3. Get Correct Source Hash Build with placeholder hash to get the actual hash:

    cd ~/nixosbox
    nix-build --no-out-link -E 'with import <nixpkgs> {}; fetchgit {
      url = "https://gitea.cmtec.se/cm/cm-dashboard.git";
      rev = "NEW_COMMIT_HASH";
      sha256 = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
    }' 2>&1 | grep "got:"
    

    Example output:

    error: hash mismatch in fixed-output derivation '/nix/store/...':
             specified: sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
                got:    sha256-x8crxNusOUYRrkP9mYEOG+Ga3JCPIdJLkEAc5P1ZxdQ=
    
  4. Update Configuration with Correct Hash Replace the placeholder with the hash from the error message (the "got:" line).

  5. Commit NixOS Configuration

    cd ~/nixosbox
    git add hosts/common/cm-dashboard.nix
    git commit -m "Update cm-dashboard to latest version (SHORT_HASH)"
    git push
    
  6. Rebuild System The user handles the system rebuild step - this cannot be automated.