Brain Structural Validation / Validate Markdown Structure & Links (push) Successful in 6s
relative links - Update all Homelab documents and engineering journals with core tags (`architecture`, `security`, `operations`, `ADR`). - Replace machine-specific `file:///` URLS and absolute local paths with portable relative Markdown links and code backticks. - Align Homelab project landing page and documentation status with current infrastructure topology
6.6 KiB
6.6 KiB
type, project, tags
| type | project | tags | |||||
|---|---|---|---|---|---|---|---|
| guide | nixos |
|
Terminal Workspace Subsystem Walkthrough
Summary of Completed Work
We evaluated, designed, and implemented the Terminal Workspace Subsystem for the laptop NixOS workstation. The subsystem enforces a clean, deterministic separation across four layers:
┌─────────────────────────────────────────────────────────────┐
│ Niri (Compositor / Window Manager) │
│ │
│ Mod+Return: Ephemeral Alacritty Shell ($SHELL) │
│ Mod+T: Persistent Workspace Terminal (Alacritty -> ts) │
└──────────────────────────────┬──────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Alacritty (Terminal Emulator) │
│ │
│ GPU rendering, PTY management, font metrics, input routing │
│ (Does NOT auto-launch tmux globally) │
└──────────────────────────────┬──────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Sessionizer (`tmux-sessionizer` / `ts`) │
│ │
│ Discovery → Normalization → Registry Validation │
│ → Deterministic Resolution → Tmux Lifecycle │
└──────────────────────────────┬──────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Tmux (Terminal Multiplexer) │
│ │
│ Persistent headless process state across window closures; │
│ Vi-mode copy, smart Neovim navigation, OSC-52 clipboard │
└─────────────────────────────────────────────────────────────┘
Files Modified & Created
home/scripts/tmux-sessionizer.sh[NEW]:- Discovers explicit workspaces (
~/Config,~/Brain,~/Homelab/Core) and git repositories under~/Projectsand~/Homelab. - Normalizes folder basenames to lowercase, regex-sanitized tmux session names without trailing hyphens/underscores (
tr '[:upper:]' '[:lower:]' | sed -E 's/[ .]+/-/g; s/[^a-z0-9_-]//g; s/[-_]+$//'). - Validates the complete registry up-front for session name collisions before resolving requests (Option A: global fatal refusal).
- Resolves CLI queries via strict precedence: (1) existing directory path, (2) exact session name, (3) exact basename, (4) unique substring match. Never guesses ambiguous matches.
- Parses final record via native Bash
IFS=$'\t' read -r session_name target_dir. - Dual-context switching: outside tmux calls
exec tmux attach-session -t ...; inside tmux callstmux switch-client -t ...(prevents nested sessions). - Establishes working directory with
-c "$target_dir"only when creating a new session; never resets an existing session's directory.
- Discovers explicit workspaces (
home/shell.nix[MODIFIED]:- Declared
tmuxSessionizeras a hermetic derivation usingpkgs.writeShellApplicationwith runtime dependencies:bash,coreutils,gnused,gawk,gnugrep,fd,fzf,tmux. - Added
tmuxSessionizertohome.packages. - Added shell alias
ts = "tmux-sessionizer";toprograms.bash.shellAliases.
- Declared
home/config/niri/custom.kdl[MODIFIED]:- Added
Mod+Thotkey binding to spawn Alacritty directly runningtmux-sessionizer. - Updated
Mod+Returnlabel to denote ephemeral shell terminal.
- Added
docs/reference/tmux.md[MODIFIED]:- Restructured into the comprehensive Terminal Workspace Architecture & Tmux Reference.
- Codified the 12 architectural invariants (INV-001 through INV-012).
- Documented naming, discovery hierarchy, collision policies, CLI usage, and tmux configuration.
Validation & Test Results
1. Script Quality & Shellcheck
- Ran
shellcheckacrosshome/scripts/tmux-sessionizer.sh. - Passed with 0 errors, 0 warnings.
2. Flake Validation (nix flake check)
- Ran
nix flake checkon~/Config. - All checks (
check-ruff-lint,check-ruff-format,check-pyright,check-shellcheck) passed cleanly.
3. Laptop Host Dry Build
- Executed dry build:
nix build .#nixosConfigurations.laptop.config.system.build.toplevel --no-link - Build succeeded completely, building
tmux-sessionizer.drv, Home Manager activation units, and the complete system top-level derivation.
Operational Guide
Interactive Workspace Selection
Press Mod+T from anywhere in Niri, or run ts in an existing terminal:
fzfdisplayssession_nameandabsolute_path.- Pressing
Escapeexits cleanly with code0and closes the Alacritty window. - Selecting a workspace creates or attaches to the persistent tmux session.
Direct CLI Selection
ts config # Attaches/switches to ~/Config session
ts brain # Attaches/switches to ~/Brain session
ts bitetrack-api # Attaches/switches to bitetrack-api session
ts magnet # Unique substring match -> attaches to MagNetFlix
ts ~/Projects/... # Explicit path
Context Switching Inside Tmux
- While inside any active tmux session, running
ts <target>or interactivetsswitches the client directly viatmux switch-clientwithout creating nested tmux instances.