platform

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package platform provides cross-platform path resolution, shell detection, and session launching for dispatch.

Package platform provides OS-specific shell, terminal, font, and path helpers.

Index

Constants

View Source
const (
	// LaunchStyleTab opens a new tab in the current terminal window.
	LaunchStyleTab = ""
	// LaunchStyleWindow opens a brand-new terminal window.
	LaunchStyleWindow = "window"
	// LaunchStylePane opens a split pane in the current tab (Windows Terminal only).
	LaunchStylePane = "pane"
)

LaunchStyle constants control how a session is opened externally.

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

func ConfigDir() (string, error)

ConfigDir returns the OS-appropriate configuration directory for dispatch:

  • Windows: %APPDATA%\dispatch
  • macOS: ~/Library/Application Support/dispatch
  • Linux: ~/.config/dispatch

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 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 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

func SessionStorePath() (string, error)

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.

Inside WSL the Copilot CLI runs on the Windows side, so the session store lives under the Windows user profile (e.g. /mnt/c/Users/<user>). When the database is not found at the Linux home directory, we fall back to scanning the Windows user-profile directories exposed via the WSL mount.

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
	LaunchStyle   string // "", "window", or "pane" — controls tab vs window vs split pane
	PaneDirection string // "auto", "right", "down", "left", "up" — split direction for pane mode
}

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL