Documentation
¶
Overview ¶
Package nativeterm opens a command in the user's own terminal application — Ghostty, iTerm2, Terminal.app, Windows Terminal — rather than in the dashboard's web terminal.
The dashboard's xterm is a fine place to glance at a session and an awkward place to live in: its own key bindings, its own copy and paste, no tabs of the user's own (owner request, 2026-10-04). So a session can be carried on in the terminal the user already has, and Caprock goes on watching it the way it watches any session somebody started themselves (Phase 0): through the hooks and the transcript, not through a PTY it holds.
Every terminal is driven through its own documented interface, read from that terminal rather than guessed (see .ai/02-architecture.md § Native terminals for which ones were run on a real machine and which are written from their documentation):
- Terminal.app opens a `.command` file in a new window, run by the user's login shell — no AppleScript, so no Automation prompt.
- iTerm2 is told over AppleScript to open a window and type the command into the user's own shell there. It also opens `.command` files, but asks "OK to run …?" every time.
- Ghostty, WezTerm and kitty take the command as arguments; on macOS through `open -na <app> --args`, which is how their docs start a window from a script.
- Warp runs commands only from a launch configuration, so one is written and opened by its URI.
- On Linux every terminal takes a command after a flag; on Windows, Windows Terminal takes `-d <dir>` and a command line, and cmd and PowerShell are started in a console of their own.
Nothing here decides whether a session may be opened; that is the caller's (internal/api), because it depends on who owns the process.
Index ¶
- Variables
- func AppleScriptString(s string) string
- func Display(goos, cwd string, argv []string) string
- func Env(base []string) []string
- func IDs(goos string) []string
- func Line(cwd string, argv []string) string
- func Run(ctx context.Context, p Plan, env []string) error
- func Shell(env []string) string
- func ShellQuote(s string) string
- func YAMLString(s string) string
- type File
- type Opener
- type Plan
- type Probe
- type Request
- type Terminal
Constants ¶
This section is empty.
Variables ¶
var ErrNoTerminal = errors.New("no terminal")
ErrNoTerminal is returned when no terminal Caprock can drive is installed, or the one asked for is not.
var ErrUnsafe = errors.New("unsafe")
ErrUnsafe is returned for a command word or directory that cannot be passed on safely.
Functions ¶
func AppleScriptString ¶
AppleScriptString quotes s as an AppleScript string literal.
func Display ¶
Display is the command as the user would type it, for the response and the button's tooltip.
func Env ¶
Env is the environment a terminal is started with: the user's login-shell one, without the variables that would make what runs inside it think it is nested in another Claude Code session or in Caprock's own PTY.
func IDs ¶
IDs lists every terminal id this build knows on goos, installed or not — what the setting may be set to.
func Run ¶
Run carries a plan out: writes its file, starts its process with env, and for a plan that waits, reports the process's failure in its own words.
func ShellQuote ¶
ShellQuote quotes s for a POSIX shell. Plain words are left bare so the command reads the way a person would type it; anything else is put in single quotes, inside which nothing is special but the quote itself.
func YAMLString ¶
YAMLString quotes s as a YAML double-quoted scalar.
Types ¶
type Opener ¶
type Opener struct {
// DataDir holds the short-lived files some terminals are opened with.
DataDir string
// Env is the user's login-shell environment (internal/userenv).
Env func() []string
// Preferred is the terminal the user picked in settings, "" for none.
Preferred func() string
}
Opener is what the daemon hands the API: it detects terminals against the user's environment and opens a command in one.
func (*Opener) List ¶
List is the installed terminals, most preferred first, and the id of the one used when none is named: the user's choice if it is installed, else the first found.
func (*Opener) Open ¶
func (o *Opener) Open(ctx context.Context, id, cwd string, argv []string, before func() error) (Terminal, string, error)
Open runs argv in cwd in the terminal with this id, or the preferred one. before runs after the launch is planned and before it starts. The string returned is the command as the user would type it, also on failure, so the screen can offer it to copy.
type Plan ¶
type Plan struct {
Command string
Args []string
// Dir is the working directory of Command itself (Windows consoles and
// Linux terminals that have no directory flag of their own).
Dir string
// File is written, 0700, before Command runs.
File *File
// NewConsole starts Command in a console window of its own (Windows).
NewConsole bool
// Wait says Command returns once the window is open (open, osascript),
// so its exit status is the answer. Otherwise Command is the terminal
// itself and keeps running; it is started and let go.
Wait bool
}
Plan is the process that opens the window, and the file it needs first.
type Probe ¶
type Probe struct {
GOOS string
// Env is the environment the terminal would be started with — the user's
// login-shell one, so PATH is the PATH their own terminal has.
Env []string
// Home is the user's home directory, for ~/Applications.
Home string
// IsDir reports whether a path is a directory (an app bundle).
IsDir func(string) bool
// IsExec reports whether a path is an executable file.
IsExec func(string) bool
}
Probe is how Detect looks at the machine; swapped by tests.
type Request ¶
type Request struct {
// Cwd is the directory the command runs in. Empty means the home
// directory, for a command that does not need one.
Cwd string
// Argv is the command, already split: ["claude", "--resume", "<id>"].
// Every word must be plain (see safeWord): it is typed into shells and
// command lines on three operating systems, and an id with a quote in it
// is not an id.
Argv []string
// Shell is the user's login shell (POSIX), used where a terminal is given
// a command rather than a shell to type it into.
Shell string
// Scratch is a private directory for the files some terminals are opened
// with (Terminal.app's .command, Warp's launch configuration's twin).
Scratch string
// Name is a unique stem for those files.
Name string
}
Request is what to open.
type Terminal ¶
type Terminal struct {
// ID is the stable name the API and the setting use ("ghostty").
ID string `json:"id"`
// Name is what the button says ("Ghostty").
Name string `json:"name"`
// contains filtered or unexported fields
}
Terminal is one terminal application found on this machine.