Documentation
¶
Overview ¶
Package platform provides cross-platform path resolution, shell detection, and session launching for dispatch.
Index ¶
- func BuildResumeArgs(sessionID string, cfg ResumeConfig) []string
- func ConfigDir() (string, error)
- func DefaultShellConfigPath() (string, error)
- func DefaultTerminal() string
- func DetectIsDark() bool
- func DetectTerminalScheme() *styles.ColorScheme
- func EnsureConfigDir() error
- func FindCLIBinary() string
- func InstallNerdFont() error
- func IsNerdFontInstalled() bool
- func LaunchSession(shell ShellInfo, sessionID string, cfg ResumeConfig) error
- func LaunchSessionInPlace(shell ShellInfo, sessionID string, cfg ResumeConfig) error
- func NewResumeCmd(sessionID string, cfg ResumeConfig) (*exec.Cmd, error)
- func SessionStorePath() (string, error)
- type ResumeConfig
- type ShellInfo
- type TerminalInfo
- type WTColorScheme
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildResumeArgs ¶
func BuildResumeArgs(sessionID string, cfg ResumeConfig) []string
BuildResumeArgs constructs the argument list for resuming a session using "copilot --resume <sessionID>" with optional flags from cfg. If sessionID is empty, the --resume flag is omitted (starts a new session).
func ConfigDir ¶
ConfigDir returns the OS-appropriate configuration directory for dispatch:
- Windows: %APPDATA%\dispatch
- macOS: ~/Library/Application Support/dispatch
- Linux: ~/.config/dispatch
func DefaultShellConfigPath ¶
DefaultShellConfigPath returns the path to the shell-preference configuration file inside the app config directory.
func DefaultTerminal ¶
func DefaultTerminal() string
DefaultTerminal returns the name of the default terminal emulator for the current OS. On Windows this is "Windows Terminal" when wt.exe is available, falling back to "conhost". On macOS it is "Terminal.app". On Linux it returns the first detected terminal from the standard candidate list, or "xterm" as a last resort.
func DetectIsDark ¶
func DetectIsDark() bool
DetectIsDark returns true when the terminal has a dark background. It uses termenv's built-in heuristic (OSC 11 background luminance).
func DetectTerminalScheme ¶
func DetectTerminalScheme() *styles.ColorScheme
DetectTerminalScheme attempts to detect the terminal's color scheme via the following chain:
- Windows Terminal settings.json (Windows only)
- OSC 10/11 queries via termenv (foreground/background)
- Environment variable hints (WT_SESSION, COLORFGBG)
If detection succeeds it returns a ColorScheme. If all probes fail it returns nil and the caller should fall back to a built-in scheme.
func EnsureConfigDir ¶
func EnsureConfigDir() error
EnsureConfigDir creates the application config directory (and any parent directories) if it does not already exist.
func FindCLIBinary ¶
func FindCLIBinary() string
FindCLIBinary returns the absolute path to the Copilot CLI binary, preferring "ghcs" and falling back to "copilot". Returns an empty string when neither is found on PATH.
func InstallNerdFont ¶
func InstallNerdFont() error
InstallNerdFont downloads the JetBrainsMono Nerd Font archive, extracts .ttf files, and installs them to the user-level font directory. The function is safe to call from a goroutine.
func IsNerdFontInstalled ¶
func IsNerdFontInstalled() bool
IsNerdFontInstalled checks whether any Nerd Font .ttf file is present in the OS-appropriate user or system font directories.
func LaunchSession ¶
func LaunchSession(shell ShellInfo, sessionID string, cfg ResumeConfig) error
LaunchSession opens a new terminal window running the Copilot CLI session resume command for the given sessionID. The detected CLI binary ("ghcs" or "copilot") is used with "session resume <sessionID>" plus any flags from cfg. If cfg.Terminal is set, that terminal emulator is preferred.
When shell has an empty Path, the platform default shell is used. When cfg.Terminal is empty, the platform default terminal is used. This allows callers to omit shell/terminal configuration and still get a working launch.
func LaunchSessionInPlace ¶
func LaunchSessionInPlace(shell ShellInfo, sessionID string, cfg ResumeConfig) error
LaunchSessionInPlace starts the Copilot CLI session in the current terminal. On Unix this replaces the current process via syscall.Exec; on Windows it starts a child process and waits for it to exit.
When shell has an empty Path, the platform default shell is used so that callers can omit shell configuration and still get a working launch.
func NewResumeCmd ¶
func NewResumeCmd(sessionID string, cfg ResumeConfig) (*exec.Cmd, error)
NewResumeCmd creates an *exec.Cmd for resuming a Copilot CLI session. The returned command has no Stdin/Stdout/Stderr configured; callers (or tea.ExecProcess) should attach them as needed.
When cfg.CustomCommand is set, the custom command string (with {sessionId} replaced) is split on whitespace and executed directly, bypassing the copilot CLI binary lookup.
func SessionStorePath ¶
SessionStorePath returns the absolute path to the Copilot CLI session store SQLite database (~/.copilot/session-store.db).
If the DISPATCH_DB environment variable is set, its value is returned instead. This allows tests and demo mode to point at a custom database.
Types ¶
type ResumeConfig ¶
type ResumeConfig struct {
YoloMode bool
Agent string
Model string
Terminal string // preferred terminal emulator name (empty = auto-detect)
CustomCommand string // when set, replaces the entire copilot CLI command
Cwd string // working directory to launch the session in
ForceNewWindow bool // when true, open a new terminal window instead of a tab
}
ResumeConfig holds optional CLI flags appended when resuming a session.
type ShellInfo ¶
type ShellInfo struct {
Name string // Human-readable name (e.g. "PowerShell", "bash").
Path string // Absolute path to the shell executable.
Args []string // Default arguments used when launching the shell.
}
ShellInfo describes a shell that can be used to launch Copilot CLI sessions.
func DefaultShell ¶
func DefaultShell() ShellInfo
DefaultShell returns the user's preferred shell. On Unix systems this is derived from the $SHELL environment variable; on Windows it defaults to PowerShell.
func DetectShells ¶
func DetectShells() []ShellInfo
DetectShells returns the list of shells available on the current OS.
type TerminalInfo ¶
type TerminalInfo struct {
Name string // Human-readable name (e.g. "Windows Terminal", "alacritty").
}
TerminalInfo describes a terminal emulator available on the system.
func DetectTerminals ¶
func DetectTerminals() []TerminalInfo
DetectTerminals returns the list of terminal emulators available on the current OS.
type WTColorScheme ¶
type WTColorScheme struct {
Name string `json:"name"`
Foreground string `json:"foreground"`
Background string `json:"background"`
CursorColor string `json:"cursorColor,omitempty"`
SelectionBackground string `json:"selectionBackground,omitempty"`
Black string `json:"black"`
Red string `json:"red"`
Green string `json:"green"`
Yellow string `json:"yellow"`
Blue string `json:"blue"`
Purple string `json:"purple"`
Cyan string `json:"cyan"`
White string `json:"white"`
BrightBlack string `json:"brightBlack"`
BrightRed string `json:"brightRed"`
BrightGreen string `json:"brightGreen"`
BrightYellow string `json:"brightYellow"`
BrightBlue string `json:"brightBlue"`
BrightPurple string `json:"brightPurple"`
BrightCyan string `json:"brightCyan"`
BrightWhite string `json:"brightWhite"`
}
WTColorScheme mirrors the color scheme object in Windows Terminal settings.json. On non-Windows platforms this type is provided so the rest of the codebase can reference it without build-tag guards.
func DetectWTColorScheme ¶
func DetectWTColorScheme() (*WTColorScheme, error)
DetectWTColorScheme is a no-op on non-Windows platforms. It always returns (nil, nil).