跳到正文
DEV Community· SATINATH MONDAL·· 3 小時前AI 評分57

Nathstar:作者為何打造本機優先的 120Hz macOS 終端模擬器

Why I Built Nathstar: A Local-First, 120Hz Native macOS Terminal for Projects, Live Ops & Private AI

AI 導讀

SATINATH MONDAL 介紹自己打造的 Nathstar,一款採 MIT 授權、無遙測的本機優先 macOS 終端模擬器。它提供持續保存的專案工作區、即時環境變數注入、連接埠與程序管理、命令編輯及執行前風險分析,並支援本機 Ollama 和 BYOK 雲端 AI。

正文

If you are a developer on macOS today, picking a terminal emulator feels like a forced compromise:

  1. Minimalist GPU Emulators (Ghostty, Alacritty, Kitty): Blazingly fast and standards-compliant, but they treat every window as an isolated, stateless text grid. When you're juggling four microservices, two SSH sessions, and a CLI coding agent, they have no idea which pane is holding port :3000 hostage, which background build failed ten minutes ago, or which .env variables are loaded.
  2. Cloud-Tethered "Block" Terminals (Warp): Great input editing and AI features, but built around cloud accounts, telemetry by default, and metered subscriptions—while replacing standard terminal buffers with custom UI layers that can fight full-screen TUIs like nvim, lazygit, or htop.

I wanted both worlds without the trade-offs.

So I built Nathstar — an open-source (MIT), 100% local-first, zero-telemetry macOS terminal written in Swift 6, SwiftUI, AppKit, and Metal.

Nathstar Feature Tour

Here is a look at what Nathstar does differently and the engineering under the hood.


1. Projects Over Windows: Persistent Workspaces

Traditional terminals organize your work by disposable windows and tabs. When you return to a project after a reboot or context switch, you're left reconstructing your layout from shell history and memory.

Project Workspaces & Command Blocks

In Nathstar, the primary unit of organization is a Project Workspace:

  • Categorized & Collapsible Sidebar: Organize repositories into Projects, Personal, and Others, plus an auto-discovered SSH Hosts section parsed directly from ~/.ssh/config. You can rename sections, drag-and-drop workspaces between them, or unpin the sidebar into an auto-expanding 44pt hover rail (⇧⌘S).
  • Recursive Split Panes & Zoom: Split panes vertically (⌘D) or horizontally (⇧⌘D), equalize ratios (⇧⌘=), or temporarily maximize a single pane (⇧⌘⏎).
  • True Single-Window Persistence (⌘W vs. ⌘Q): Closing the window with ⌘W hides the UI while keeping every PTY process, dev server, and SSH connection alive in memory. Double-tapping ⌃ (Control) summons Nathstar back from any app—or docks it to the top of your screen in Quake Visor Mode.

2. Silent Live Environment Sync (SIGUSR1) & .env Management

Have you ever updated an API key or feature flag in a .env file, only to realize you have to restart your shell—or paste export FOO=bar across five open panes—for it to take effect?

Silent Live Environment Sync & Project Manifests

Nathstar introduces Silent Live Environment Injection:

  1. When Nathstar spawns zsh, it uses a lightweight, transparent ZDOTDIR shim that sources your real .zshenv and .zshrc untouched and installs a TRAPUSR1 signal handler.
  2. When you add or edit a KEY=VALUE variable in Nathstar's Manifest panel and click Set & Apply, Nathstar writes a private 0600 session file and sends SIGUSR1 (kill(shellPid, SIGUSR1)) to the running zsh process.
  3. Your live shell immediately sources the updated environment variables silently in the background—with zero commands echoed into your scrollback buffer.

You can also import/export .env files with one click, and define a .nathstar/manifest.json file to orchestrate multi-pane project startups (while automatically keeping *_KEY, *_SECRET, and *_TOKEN values strictly local).


3. Who Is Using :3000? Built-In Live Port & Process Manager (⇧⌘P)

Every full-stack developer knows the pain of EADDRINUSE: address already in use :::3000, followed by running lsof -ti :3000 | xargs kill -9.

Live Ports & Processes Manager

Nathstar includes a dedicated Live Ports & Processes (⇧⌘P) tab in the right-hand panel:

  • Every 3 seconds (while open), LivePortScanner inspects listening TCP sockets (lsof) and walks the parent PID (ppid) tree (ps) up to the root shellPid of every Nathstar pane.
  • It maps every active port (:3000, :5173, :8080) back to the exact Workspace and Terminal Pane that spawned it.
  • With a single click, you can Open the port in your browser, Focus the exact terminal pane running the server, send a graceful Kill (SIGTERM), or Kill -9 (SIGKILL) a stuck process.

4. Native Command Editing (⌘E), Click-to-Cursor & Blast-Radius Safety

Editing a 200-character curl or docker command in a traditional terminal usually means holding down the Left arrow key or memorizing readline chords.

Search, Quick Links, Click-to-Cursor & Autocomplete

Nathstar gives you two ways to edit long commands naturally:

  1. Click-to-Position Cursor in the Prompt: Click (or ⌥-Click) directly on any character in your active terminal command—even across multi-line wrapped lines. Using a hybrid of OSC 133 semantic prompt markers and automatic wrapped-line cell calculation (compatible with Powerlevel10k, Starship, and Oh My Zsh), Nathstar moves the shell cursor straight to that character.
  2. Pull to Native Composer (⌘E): Press ⌘E at any time to pull your active terminal line into the bottom multi-line macOS text editor. Edit with standard macOS selection and undo, use Tab ⇥ IDE-style autocomplete (ranking Git branches, file paths, command history, and {{parameterized}} snippets), and press ⇧⏎ to insert it back into the prompt or ⌘⏎ to run it.

Pre-Execution Blast-Radius Analyzer (Safe-Run)

Before executing commands from the composer, CommandRiskAnalyzer checks for destructive patterns—like git push --force, rm -rf near / or ~, git reset --hard, or piping curl directly into sudo bash—and warns you of the blast radius before execution.


5. Zero-Telemetry Streaming AI (Local Ollama + BYOK Cloud)

AI in the terminal shouldn't require a monthly SaaS subscription or sending proprietary stack traces to someone else's cloud.

Streaming AI Assistant & Error Fix

Nathstar's AI layer is 100% opt-in and bring-your-own-model:

  • Zero-Config Local Ollama: Automatically queries http://127.0.0.1:11434/api/tags to discover your locally installed Ollama models (llama3, qwen2.5-coder, deepseek-coder, etc.) for completely offline, private inference.
  • BYOK Cloud & Custom Endpoints: Supports OpenAI (gpt-4o), Anthropic (claude-3-5-sonnet), Groq, LM Studio, OpenRouter, vLLM, or any OpenAI-compatible gateway.
  • One-Click "Explain & Fix with AI": Whenever a command exits non-zero, an inline banner appears at the top of the pane. Click it to attach the failed command and the last 35 lines of terminal output for an immediate diagnosis and runnable fix.
  • Inline ⌘I Command Generator: Press ⌘I to translate plain English right into a zsh command.

6. How Nathstar Compares to Other macOS Terminals

Capability Nathstar Warp Ghostty iTerm2 WezTerm / Kitty
Open Source (MIT) & Zero Telemetry ✅ Yes ❌ Cloud ✅ Yes ✅ GPLv2 ✅ Yes
Project Workspaces Sidebar (Projects / Personal / Others) ✅ Built-in ❌ No ❌ No ⚠️ Profiles ❌ No
Silent Live Env Var Injection (SIGUSR1) ✅ Unique ❌ No ❌ No ❌ No ❌ No
Live Port & Process Manager (Open, Focus, Kill -9) ✅ Built-in ❌ No ❌ No ❌ No ❌ No
Pre-Execution Blast-Radius Safety Analyzer (Safe-Run) ✅ Built-in ⚠️ Basic ❌ No ⚠️ Triggers ❌ No
Click-to-Move Cursor in Long Commands ✅ Built-in ✅ Yes ⚠️ OSC 133 ⚠️ ⌥-Click ⚠️ OSC 133
Pull Active Terminal Line into Native Editor (⌘E) ✅ Built-in ✅ Native ❌ No ⚠️ Popover ❌ No
Local Ollama Auto-Discovery + Streaming BYOK AI ✅ Built-in ❌ Paid Cloud ❌ No ⚠️ Plugin ❌ No
120Hz Metal GPU Shader Rendering ✅ Built-in ✅ Metal ✅ Metal ✅ Metal ✅ OpenGL/Metal

7. Under the Hood: Swift 6, 120Hz Metal & Zero-Permission Hotkeys

Themes & Command Palette

For fellow macOS engineers, here are three architectural details that made a huge difference when building Nathstar:

  1. Deferred Non-Zero Frame PTY Initialization: A subtle bug in SwiftUI-hosted NSView terminals occurs when forkpty is called inside makeNSView while the view frame is still 0×0, causing TIOCSWINSZ race conditions and missing prompts in themes like Powerlevel10k. NathstarTerminalView defers startProcess until layout() reports a real non-zero geometry (width > 10 && height > 10), guaranteeing every tab and split pane starts with exact row/column dimensions.
  2. Runtime-Compiled 120Hz Metal Shaders: Rather than relying on precompiled .metallib bundles that fail on machines without full Xcode toolchains, Nathstar compiles its Metal shaders at runtime via MTLDevice.makeLibrary(source:).
  3. Zero-Permission Double-Tap ⌃ Global Hotkey: macOS blocks global keyDown monitors unless the user grants invasive Accessibility/Input Monitoring permissions. Nathstar combines NSEvent flag monitors with 60Hz hardware modifier state polling (CGEventSource.flagsState(.combinedSessionState)), enabling global Double-Tap ⌃ summoning out of the box with zero system permission prompts.

Try Nathstar Today

Nathstar is free, open-source under the MIT License, and builds 100% offline with zero external network fetches (all dependencies are vendored in the repo).

🔗 GitHub Repository: https://github.com/satinath-nit/Nathstar

To build and launch it on any Apple Silicon Mac (macOS 15+):


bash
git clone https://github.com/satinath-nit/Nathstar.git
cd Nathstar
./scripts/package-macos.sh
open release/Nathstar.app

來源:DEV Community · dev.to