Files
linux-connector/docs/plans/linux-connector/02-architecture.md
T

5.7 KiB

Gate 2 — Architecture: linux-connector

1. System Fit & Architecture Diagram

                                  ┌────────────────────────┐
                                  │      CLI Parser        │
                                  │ (connect, exec, status)│
                                  └───────────┬────────────┘
                                              │
                                              ▼
                                  ┌────────────────────────┐
                                  │    Inventory Engine    │
                                  │  - ~/.ssh/config       │
                                  │  - /etc/ssh/ssh_config │
                                  │  - hosts.yaml / json   │
                                  └───────────┬────────────┘
                                              │
                    ┌─────────────────────────┼─────────────────────────┐
                    ▼                         ▼                         ▼
         ┌─────────────────────┐   ┌─────────────────────┐   ┌─────────────────────┐
         │ Interactive TUI     │   │ Concurrent Runner   │   │ Status Prober       │
         │ - Pure ANSI Menu    │   │ - ThreadPoolExecutor│   │ - Non-blocking TCP  │
         │ - Fuzzy Search      │   │ - Async Line Stream │   │ - Socket connect    │
         │ - fzf delegation    │   │ - Exit aggregator   │   │ - Latency timing    │
         └──────────┬──────────┘   └──────────┬──────────┘   └──────────┬──────────┘
                    │                         │                         │
                    ▼                         ▼                         ▼
         ┌─────────────────────┐   ┌─────────────────────┐   ┌─────────────────────┐
         │ Native execvp(ssh)  │   │ OpenSSH / Paramiko  │   │ Raw Socket Probe    │
         │ (100% Native TTY)   │   │ (Parallel Subprocess│   │ (TCP Port 22)       │
         └─────────────────────┘   └─────────────────────┘   └─────────────────────┘

2. Inventory Model & Discovery Hierarchy

linux-connector loads host definitions hierarchically:

  1. ~/.ssh/config & /etc/ssh/ssh_config (Primary Source):
    • Automatically parsed using an RFC/OpenSSH-compliant lexer.
    • Extracts: Host, HostName, User, Port, IdentityFile, ProxyJump, ForwardAgent.
  2. ~/.config/linux-connector/hosts.yaml (or .json) (Enrichment Source):
    • Supplements SSH hosts with metadata (groups, environment, human tags, description).
    • Also supports standalone host declarations.

Inventory Data Contract

{
  "hosts": [
    {
      "name": "pve-01",
      "hostname": "192.168.10.11",
      "user": "root",
      "port": 22,
      "identity_file": "~/.ssh/id_ed25519_homelab",
      "proxy_jump": null,
      "groups": ["pve", "hypervisors", "production"],
      "tags": ["proxmox", "ceph-mon", "zfs"],
      "description": "Proxmox Node 1 (Dell R730)"
    }
  ],
  "groups": {
    "pve": ["pve-01", "pve-02", "pve-03"],
    "k8s": ["k8s-master-01", "k8s-worker-01", "k8s-worker-02"]
  }
}

3. Execution Engine & Output Streaming

For the exec sub-command:

  • Worker pool powered by concurrent.futures.ThreadPoolExecutor (or standard asyncio subprocess runner).
  • Configurable concurrency limit (default: 10 concurrent streams).
  • Real-time line streaming: standard output and standard error from each node are consumed non-blockingly, stamped with ANSI color-coded [hostname], and flushed immediately to the terminal.
  • Aggregate summary table tracks:
    • Host identifier
    • Status (SUCCESS, FAILED, TIMEOUT, UNREACHABLE)
    • Exit code
    • Execution duration in seconds.

4. Interactive Terminal Handover Strategy

A common failure mode in SSH manager tools is attempting to proxy interactive terminal I/O through Python buffers, which breaks terminal resizing, raw mode, and complex ncurses programs.

linux-connector uses a two-phase connection strategy:

  1. Phase 1 (Inspection & Selection): Python handles inventory discovery, TCP socket latency check, and terminal interactive fuzzy search.
  2. Phase 2 (Handover): Once the target host is confirmed, Python performs os.execvp("ssh", ssh_args). This cleanly replaces the Python process image with the native /usr/bin/ssh process, granting it 100% direct access to the user's TTY, signals, and agent keys.

5. Exit Codes

Code Status Meaning
0 SUCCESS Selected host connected, or all remote commands succeeded (exit code 0).
1 COMMAND_FAILURE One or more remote commands returned non-zero exit code.
2 UNREACHABLE Target host(s) could not be reached over network / port 22 refused.
3 CONFIG_ERROR Malformed inventory file, missing host argument, or unknown group.
130 ABORTED User interrupted operation (Ctrl+C).