Documentation
¶
Overview ¶
Package platform — gitstate.go provides lightweight Git workspace state detection for session directories. It runs bounded git commands with context timeouts to avoid blocking the TUI.
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
- Variables
- func BuildResumeArgs(sessionID string, cfg ResumeConfig) []string
- func BuildResumeCommandString(sessionID string, cfg ResumeConfig) (string, error)
- func ConfigDir() (string, error)
- func DefaultTerminal() string
- func FindCLIBinary() string
- func IsNerdFontInstalled() bool
- func IsProcessAlive(pid int) bool
- func LaunchSession(shell ShellInfo, sessionID string, cfg ResumeConfig) error
- func NewResumeCmd(sessionID string, cfg ResumeConfig) (*exec.Cmd, error)
- func OpenDir(path string) error
- func OpenFile(path string) error
- func OpenURL(rawURL string) error
- func RedactSecrets(text string) string
- func ScanGitStatuses(sessions map[string]string) map[string]GitStatus
- func SessionStorePath() (string, error)
- type GitFileStatus
- type GitState
- type GitStatus
- type ResumeConfig
- type ShellInfo
- type TerminalInfo
- type WTColorScheme
Constants ¶
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 ¶
var ( ErrCLINotFound = errors.New("ghcs/copilot CLI not found in PATH") ErrEmptyAfterExpansion = errors.New("custom command is empty after expansion") ErrNoTerminalEmulator = errors.New("no supported terminal emulator found") )
Sentinel errors returned by platform operations.
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 BuildResumeCommandString ¶ added in v0.14.0
func BuildResumeCommandString(sessionID string, cfg ResumeConfig) (string, error)
BuildResumeCommandString returns the shell command Dispatch uses to start or resume a Copilot CLI session, including configured flags and custom command templates. It is exported for UI and diagnostics code that need to display or copy the same command used by the launcher.
func ConfigDir ¶
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 IsNerdFontInstalled ¶
func IsNerdFontInstalled() bool
IsNerdFontInstalled checks whether any Nerd Font .ttf file is present in the OS-appropriate user or system font directories.
func IsProcessAlive ¶ added in v0.1.3
IsProcessAlive reports whether the process with the given PID is running. On Unix-like systems this sends signal 0, which checks for existence without actually delivering a signal.
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 OpenDir ¶ added in v0.14.0
OpenDir opens the given directory in the platform file manager. It returns an error if the path is empty or is not an existing directory, so callers can surface a clear message instead of spawning against a bad path.
func OpenFile ¶ added in v0.13.0
OpenFile opens the given file path using the platform default application. On Windows it uses explorer.exe (avoids cmd.exe metacharacter injection), on macOS "open", and on Linux "xdg-open".
func OpenURL ¶ added in v0.14.0
OpenURL opens the given URL in the platform default browser. Only absolute http and https URLs are allowed, so a malformed or non-web value cannot be handed to the OS opener (which could otherwise launch an unexpected handler).
func RedactSecrets ¶ added in v0.13.0
RedactSecrets replaces common secret patterns in text with a [redacted] placeholder. The function is designed for display purposes and does not modify the underlying data store.
func ScanGitStatuses ¶ added in v0.14.0
ScanGitStatuses runs DetectGitStatus for each session directory in the provided map (session ID to directory path) and returns the detailed results. It is the single git-scanning entry point used by the background refresh: the session-list badge enum is derived from each GitStatus via State(), while the inline push/pull column and the preview pane use the full status.
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.
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 GitFileStatus ¶ added in v0.14.0
GitFileStatus is a single changed path paired with its short two-character status code as shown by `git status --short` (e.g. " M", "??", "A ", "UU").
type GitState ¶ added in v0.13.0
type GitState int
GitState represents the workspace state of a Git checkout.
const ( // GitStateUnknown means the state has not been determined yet. GitStateUnknown GitState = iota // GitStateClean means the working tree is clean with no pending changes. GitStateClean // GitStateDirty means tracked files have uncommitted modifications. GitStateDirty // GitStateUntracked means untracked files exist in the working tree. GitStateUntracked // GitStateAhead means the local branch is ahead of its upstream. GitStateAhead // GitStateBehind means the local branch is behind its upstream. GitStateBehind // GitStateMissing means the session directory no longer exists on disk. GitStateMissing )
type GitStatus ¶ added in v0.14.0
type GitStatus struct {
Dir string
Exists bool // directory exists on disk
IsRepo bool // directory is inside a Git work tree
Branch string
Detached bool
Upstream string // upstream ref, empty when there is none
HasUpstream bool
Ahead int // commits ahead of upstream (to push)
Behind int // commits behind upstream (to pull)
Staged int // entries with an index (staged) change
Modified int // entries modified in the work tree (not staged)
Untracked int // untracked files
Deleted int // entries deleted in the work tree (not staged)
Conflicts int // unmerged (conflicted) entries
Files []GitFileStatus // changed entries, capped at maxGitStatusFiles
Truncated bool // Files was capped
}
GitStatus is a detailed snapshot of a directory's Git workspace. Unlike GitState (a single collapsed enum used for the list badge), it carries the standard push/pull counts and per-category working-tree counts needed for a full status view.
func DetectGitStatus ¶ added in v0.14.0
DetectGitStatus gathers a detailed Git status for dir. It returns a GitStatus with Exists=false when the path is missing, IsRepo=false when the path is not a Git repository (or git is unavailable / times out), and the fully populated status otherwise.
It runs a single bounded `git status --porcelain=v2 --branch` command so the branch headers, ahead/behind counts, and changed entries come from one consistent snapshot and the call never blocks longer than gitCommandTimeout.
func (GitStatus) Clean ¶ added in v0.14.0
Clean reports whether the working tree has no changes of any category.
func (GitStatus) State ¶ added in v0.14.0
State collapses a detailed GitStatus into the single GitState enum used for the session-list badge and the git-dirty / missing-workspace filters. The precedence matches the historical DetectGitState behaviour: missing and non-repo first, then working-tree changes (dirty over untracked), then upstream divergence (behind over ahead), then clean.
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).