config

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package config manages user preferences for copilot-dispatch.

Configuration is stored as a JSON file inside the platform-specific config directory. When the file does not exist, sensible defaults are returned so the application can run without prior configuration.

Index

Constants

View Source
const (
	// PaneDirectionAuto lets Windows Terminal choose the best split direction.
	PaneDirectionAuto = "auto"
	// PaneDirectionRight splits the pane to the right (vertical split).
	PaneDirectionRight = "right"
	// PaneDirectionDown splits the pane downward (horizontal split).
	PaneDirectionDown = "down"
	// PaneDirectionLeft splits the pane to the left.
	PaneDirectionLeft = "left"
	// PaneDirectionUp splits the pane upward.
	PaneDirectionUp = "up"
)

PaneDirection constants control the split direction for pane mode.

View Source
const (
	// PreviewPositionRight places the preview to the right of the session list.
	PreviewPositionRight = "right"
	// PreviewPositionBottom places the preview below the session list.
	PreviewPositionBottom = "bottom"
	// PreviewPositionLeft places the preview to the left of the session list.
	PreviewPositionLeft = "left"
	// PreviewPositionTop places the preview above the session list.
	PreviewPositionTop = "top"
)

PreviewPosition constants control where the preview panel is displayed.

View Source
const (
	// SortOrderAsc sorts results in ascending order.
	SortOrderAsc = "asc"
	// SortOrderDesc sorts results in descending order.
	SortOrderDesc = "desc"
)

Sort order constants for DefaultSortOrder.

View Source
const (
	TimeRange1h  = "1h"
	TimeRange1d  = "1d"
	TimeRange7d  = "7d"
	TimeRangeAll = "all"
)

Time range constants for NamedView.TimeRange.

View Source
const (
	SortFieldUpdated  = "updated"
	SortFieldCreated  = "created"
	SortFieldTurns    = "turns"
	SortFieldName     = "name"
	SortFieldFolder   = "folder"
	SortFieldFrecency = "frecency"
)

Sort field constants for NamedView.Sort and DefaultSort.

View Source
const (
	PivotNone   = "none"
	PivotFolder = "folder"
	PivotRepo   = "repo"
	PivotBranch = "branch"
	PivotDate   = "date"
	PivotHost   = "host"
)

Pivot mode constants for NamedView.Pivot.

View Source
const (
	ColumnRepo   = "repo"
	ColumnFolder = "folder"
	ColumnTurns  = "turns"
	ColumnHost   = "host"
)

Session-list column keys used by HiddenColumns to control which optional columns appear in the session list.

Variables

ToggleableColumns lists the optional session-list columns that can be shown or hidden. The session name and attention indicator are always shown and are not included here.

Functions

func ConfigPath added in v0.14.0

func ConfigPath() (string, error)

ConfigPath returns the full path to the configuration file.

func FrecencyScore added in v0.14.0

func FrecencyScore(st SessionLaunch, now time.Time) float64

FrecencyScore returns a ranking score for a session's launch history. Higher scores rank first. The score is the launch count scaled by an exponential recency decay, so a session launched often and recently outranks one that is launched often but long ago, or recently but only once. A session with no launches scores zero, which lets the sort fall back to its incoming order.

func NormalizeAlias added in v0.14.0

func NormalizeAlias(input string) string

NormalizeAlias trims and lowercases an alias and reduces it to its first whitespace-delimited token so aliases stay usable as a single CLI argument.

func ParseTags added in v0.14.0

func ParseTags(input string) []string

ParseTags splits a comma-separated tag string into a normalized, de-duplicated slice. Tags are lowercased and trimmed; blank entries are dropped. The result is sorted so persistence and display stay stable.

func Reset

func Reset() error

Reset deletes the config file, reverting to defaults on next Load.

func Save

func Save(cfg *Config) error

Save writes the given Config to disk as a JSON file. The parent directory is created if it does not already exist.

Types

type ColorScheme added in v0.10.7

type ColorScheme struct {
	Name                string `json:"name"`
	Foreground          string `json:"foreground"`
	Background          string `json:"background"`
	CursorColor         string `json:"cursorColor,omitempty"`
	SelectionBackground string `json:"selectionBackground,omitempty"`

	// Standard 8 ANSI colors.
	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"`

	// Bright variants.
	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"`
}

ColorScheme mirrors the Windows Terminal color scheme JSON object. All color values must be #RRGGBB hex strings.

func (*ColorScheme) Palette added in v0.10.7

func (cs *ColorScheme) Palette() [16]string

Palette returns the 16 ANSI colors in index order: [0]=Black, [1]=Red, …, [7]=White, [8]=BrightBlack, …, [15]=BrightWhite.

func (*ColorScheme) Validate added in v0.10.7

func (cs *ColorScheme) Validate() error

Validate checks that all required color fields are valid #RRGGBB values.

type Config

type Config struct {
	// ConfigVersion tracks the schema version of this config file. Used to
	// detect and apply migrations when the config schema changes across
	// dispatch releases. The current version is set by [currentConfigVersion].
	ConfigVersion int `json:"config_version,omitempty"`

	// DefaultShell is the preferred shell name (e.g. "pwsh", "bash", "zsh").
	DefaultShell string `json:"default_shell"`

	// DefaultTerminal is the preferred terminal emulator name
	// (e.g. "Windows Terminal", "alacritty", "iTerm2").
	DefaultTerminal string `json:"default_terminal"`

	// DefaultTimeRange is the default time filter applied to session lists.
	// Valid values: "1h", "1d", "7d", "all".
	DefaultTimeRange string `json:"default_time_range"`

	// DefaultSort is the field used to order session lists.
	// Valid values: "updated", "created", "turns", "name", "folder".
	DefaultSort string `json:"default_sort"`

	// DefaultSortOrder is the direction used to order session lists.
	// Valid values: "asc", "desc".
	DefaultSortOrder string `json:"default_sort_order,omitempty"`

	// DefaultPivot is the default grouping applied to session lists.
	// Valid values: "none", "folder", "repo", "branch", "date", "host".
	DefaultPivot string `json:"default_pivot"`

	// ShowPreview controls whether the detail/preview panel is visible.
	ShowPreview bool `json:"show_preview"`

	// MaxSessions is the maximum number of sessions to load initially.
	MaxSessions int `json:"max_sessions"`

	// YoloMode enables the --allow-all flag when resuming sessions,
	// allowing the Copilot CLI to run commands without confirmation prompts.
	YoloMode bool `json:"yoloMode"`

	// Agent specifies the --agent <name> flag passed to the Copilot CLI
	// when resuming sessions. Empty string means no agent override.
	Agent string `json:"agent"`

	// Model specifies the --model <name> flag passed to the Copilot CLI
	// when resuming sessions. Empty string means no model override.
	Model string `json:"model"`

	// LaunchMode controls how sessions are opened:
	//   "in-place" — resume in the current terminal (replaces the TUI)
	//   "tab"      — open in a new tab of the current terminal
	//   "window"   — open in a new terminal window
	//   "pane"     — open in a split pane (Windows Terminal only)
	// Default is "tab" when unset.
	LaunchMode string `json:"launch_mode,omitempty"`

	// PaneDirection controls the split direction when LaunchMode is "pane":
	//   "auto"  — let Windows Terminal choose (default)
	//   "right" — split to the right (vertical)
	//   "down"  — split downward (horizontal)
	//   "left"  — split to the left
	//   "up"    — split upward
	// Only used when LaunchMode is "pane" and the terminal is Windows Terminal.
	PaneDirection string `json:"pane_direction,omitempty"`

	// LaunchInPlace is deprecated; kept for backward compatibility.
	// When LaunchMode is unset and LaunchInPlace is true, the effective
	// mode is "in-place". New code should use LaunchMode.
	LaunchInPlace bool `json:"launchInPlace"`

	// ExcludedDirs is a list of directory paths to exclude from session
	// listings. Sessions whose Cwd starts with any of these paths are hidden.
	ExcludedDirs []string `json:"excluded_dirs,omitempty"`

	// CustomCommand is a user-defined command that replaces the default
	// copilot CLI resume command. The placeholder {sessionId} is replaced
	// with the actual session ID at launch time. When set, YoloMode, Agent,
	// and Model are ignored (they only apply to the default copilot CLI).
	// Terminal and Shell settings are still used.
	CustomCommand string `json:"custom_command,omitempty"`

	// ExcludedWords is a list of words used to filter sessions from the
	// dispatch list. Sessions whose summary or turn content contains any
	// of these words (case-insensitive) are hidden from the session list.
	ExcludedWords []string `json:"excluded_words,omitempty"`

	// HiddenSessions is a list of session IDs that the user has chosen to
	// hide from the main session list. They can be revealed with the
	// "show hidden" toggle and unhidden individually.
	HiddenSessions []string `json:"hiddenSessions,omitempty"`

	// FavoriteSessions is a list of session IDs that the user has starred
	// as favorites. They can be filtered with the "filter favorites" toggle.
	FavoriteSessions []string `json:"favoriteSessions,omitempty"`

	// SessionNotes maps session IDs to user-defined note strings.
	// Notes provide context about why a session matters or what follow-up
	// is needed. They are displayed in the preview panel and indicated
	// by a marker in the session list.
	SessionNotes map[string]string `json:"sessionNotes,omitempty"`

	// SessionLaunches maps session IDs to their launch statistics. It is
	// used by the frecency sort to rank sessions the user launches often
	// and recently ahead of ones they rarely open.
	SessionLaunches map[string]SessionLaunch `json:"sessionLaunches,omitempty"`

	// SessionTags maps session IDs to a list of user-defined tags. Tags group
	// related sessions for quick filtering with the tag: search token and are
	// indicated by a marker in the session list.
	SessionTags map[string][]string `json:"sessionTags,omitempty"`

	// SessionAliases maps session IDs to a single short, user-chosen alias.
	// Aliases are unique and let "dispatch open <alias>" resume a session
	// without typing the full ID.
	SessionAliases map[string]string `json:"sessionAliases,omitempty"`
	// HiddenColumns lists optional session-list columns the user has chosen
	// to hide (for example "repo", "folder", "turns", "host"). When empty
	// (the default), every column is shown. The session name and attention
	// indicator are always visible and cannot be hidden.
	HiddenColumns []string `json:"hidden_columns,omitempty"`

	// AISearch enables Copilot SDK-powered AI search. When false (the
	// default), only the local FTS5 index is used.  Set to true to also
	// query the Copilot backend for semantically relevant sessions.
	AISearch bool `json:"ai_search,omitempty"`

	// AttentionThreshold is the duration string (e.g. "15m", "1h") after
	// which a running session with no activity is classified as "stale"
	// instead of "waiting" or "active". Default is "15m".
	AttentionThreshold string `json:"attention_threshold,omitempty"`

	// NotifyOnWaiting rings the terminal bell and shows a footer message when
	// a session enters the waiting state (the AI has responded and is waiting
	// for user input). The bell fires once per transition into waiting, not on
	// every scan and not for sessions already waiting when dispatch starts.
	NotifyOnWaiting bool `json:"notify_on_waiting,omitempty"`

	// Keybindings remaps keyboard shortcuts. Keys are action names (see the
	// README for the full list, e.g. "search", "quit", "preview") and values
	// are comma-separated key lists (e.g. "/,ctrl+f"). Listed actions replace
	// their default keys; unlisted actions keep their defaults. Unknown action
	// names and keys that collide with another action are ignored.
	Keybindings map[string]string `json:"keybindings,omitempty"`

	// Theme is the active color scheme name.  "auto" (or empty) means
	// detect from the terminal; any other value is looked up in Schemes
	// and then the built-in scheme list.
	Theme string `json:"theme,omitempty"`

	// Schemes is a list of user-defined color schemes in Windows Terminal
	// format.  Users can paste any WT scheme JSON directly here.
	Schemes []ColorScheme `json:"schemes,omitempty"`

	// PreviewPosition controls where the session detail/preview panel
	// is displayed relative to the session list.
	// Valid values: "right", "bottom", "left", "top".
	// Default is "right" when unset.
	PreviewPosition string `json:"preview_position,omitempty"`

	// DefaultCollapsed controls whether session header rows start in
	// collapsed (single-line) or expanded (multi-line) state. When false
	// (default), sessions are expanded showing full details. When true,
	// sessions start collapsed showing only the compact indicator row.
	DefaultCollapsed bool `json:"default_collapsed,omitempty"`

	// ConversationNewestFirst controls the turn display order in the
	// preview panel's Conversation section. When true (default), turns
	// are shown newest-first (descending). When false, turns are shown
	// oldest-first (ascending by TurnIndex).
	ConversationNewestFirst bool `json:"conversation_newest_first"`

	// WorkspaceRecovery enables detection of sessions interrupted by
	// crash/reboot. When false, stale lock files are ignored. Default true.
	WorkspaceRecovery bool `json:"workspace_recovery"`

	// RedactPreviewSecrets enables replacement of common secret patterns
	// (bearer tokens, GitHub PATs, Azure connection strings, .env secrets)
	// with [redacted] in the preview pane. Only affects rendering; stored
	// session data is never modified.
	RedactPreviewSecrets bool `json:"redact_preview_secrets,omitempty"`

	// AutoRefreshSeconds controls the session-list auto-refresh poll
	// interval, in seconds. When unset (nil), the built-in default interval
	// is used. A value of 0 disables polling entirely, so the list refreshes
	// only on explicit reload or reindex. A positive value sets the interval
	// (clamped to a one-second minimum); negative values are ignored and fall
	// back to the default. A pointer is used so "unset" and "0" are distinct.
	AutoRefreshSeconds *int `json:"auto_refresh_seconds,omitempty"`

	// Views is a list of named views, each storing a combination of
	// filter/sort/pivot settings that can be applied together.
	Views []NamedView `json:"views,omitempty"`

	// ActiveView is the name of the currently active named view.
	// Empty or "Default" means no named view is active.
	ActiveView string `json:"active_view,omitempty"`
}

Config holds the user's preferences.

func Default

func Default() *Config

Default returns a Config populated with sensible default values.

func Load

func Load() (*Config, error)

Load reads the configuration file from disk and returns the parsed Config. If the file does not exist, Load returns Default values with a nil error.

func (*Config) AliasFor added in v0.14.0

func (c *Config) AliasFor(sessionID string) string

AliasFor returns the alias for a session, or an empty string when none.

func (*Config) ColumnVisible added in v0.14.0

func (c *Config) ColumnVisible(key string) bool

ColumnVisible reports whether the given session-list column should be shown. A column is visible unless its key is present in HiddenColumns, so the default (empty HiddenColumns) shows every column.

func (*Config) EffectiveAttentionThreshold added in v0.1.3

func (c *Config) EffectiveAttentionThreshold() time.Duration

EffectiveAttentionThreshold returns the configured attention threshold as a time.Duration, defaulting to 15 minutes when unset or invalid.

func (*Config) EffectiveAutoRefreshInterval added in v0.14.0

func (c *Config) EffectiveAutoRefreshInterval() (interval time.Duration, enabled bool)

EffectiveAutoRefreshInterval returns the session-list auto-refresh poll interval and whether polling is enabled. The rules are:

  • unset (nil): the default interval, enabled.
  • 0: disabled (no polling).
  • negative: the default interval, enabled (the invalid value is ignored).
  • positive: that many seconds, clamped to a one-second minimum, enabled.

func (*Config) EffectiveLaunchMode

func (c *Config) EffectiveLaunchMode() string

EffectiveLaunchMode returns the active launch mode, resolving the deprecated LaunchInPlace boolean when LaunchMode is unset.

func (*Config) EffectivePaneDirection added in v0.1.1

func (c *Config) EffectivePaneDirection() string

EffectivePaneDirection returns the configured pane direction, defaulting to "auto" when unset.

func (*Config) EffectivePreviewPosition added in v0.4.0

func (c *Config) EffectivePreviewPosition() string

EffectivePreviewPosition returns the configured preview panel position, defaulting to "right" when unset or invalid.

func (*Config) EffectiveSortOrder added in v0.11.0

func (c *Config) EffectiveSortOrder() string

EffectiveSortOrder returns the configured sort order, defaulting to "desc" when unset or invalid.

func (*Config) FindView added in v0.13.0

func (c *Config) FindView(name string) *NamedView

FindView returns the named view with the given name, or nil if not found.

func (*Config) HasTag added in v0.14.0

func (c *Config) HasTag(sessionID, tag string) bool

HasTag reports whether a session carries the given tag. The comparison is case-insensitive.

func (*Config) RecordLaunch added in v0.14.0

func (c *Config) RecordLaunch(sessionID string, now time.Time)

RecordLaunch increments the launch count for a session and stamps the launch time. now is passed in so callers and tests control the clock. Empty session IDs are ignored so new sessions started without an ID do not pollute stats.

func (*Config) SessionIDForAlias added in v0.14.0

func (c *Config) SessionIDForAlias(alias string) string

SessionIDForAlias returns the session ID mapped to the given alias, or an empty string when no session uses it. The lookup is case-insensitive.

func (*Config) SetAlias added in v0.14.0

func (c *Config) SetAlias(sessionID, alias string) error

SetAlias assigns an alias to a session. An empty alias clears any existing alias for the session. It returns an error when the alias is already used by a different session so aliases stay unique.

func (*Config) SetTags added in v0.14.0

func (c *Config) SetTags(sessionID string, tags []string)

SetTags stores the tags for a session. Passing an empty slice removes the entry so the config stays compact.

func (*Config) TagsFor added in v0.14.0

func (c *Config) TagsFor(sessionID string) []string

TagsFor returns the tags for a session, or nil when it has none.

func (*Config) ValidViews added in v0.13.0

func (c *Config) ValidViews() []NamedView

ValidViews returns only the views that pass validation.

type LaunchMode added in v0.1.1

type LaunchMode = string

LaunchMode describes how sessions are opened in the terminal.

const (
	// LaunchModeInPlace resumes sessions in the current terminal.
	LaunchModeInPlace LaunchMode = "in-place"
	// LaunchModeTab opens sessions in a new terminal tab.
	LaunchModeTab LaunchMode = "tab"
	// LaunchModeWindow opens sessions in a new terminal window.
	LaunchModeWindow LaunchMode = "window"
	// LaunchModePane opens sessions in a split pane (Windows Terminal only).
	LaunchModePane LaunchMode = "pane"
)

Launch mode constants.

type NamedView added in v0.13.0

type NamedView struct {
	// Name is the unique display name for this view (e.g. "Work", "Personal").
	Name string `json:"name"`

	// Search is the search text to apply.
	Search string `json:"search,omitempty"`

	// TimeRange is the time filter (e.g. "1h", "1d", "7d", "all").
	TimeRange string `json:"time_range,omitempty"`

	// Sort is the sort field (e.g. "updated", "created", "turns", "name", "folder").
	Sort string `json:"sort,omitempty"`

	// SortOrder is the sort direction ("asc" or "desc").
	SortOrder string `json:"sort_order,omitempty"`

	// Pivot is the grouping mode (e.g. "none", "folder", "repo", "branch", "date", "host").
	Pivot string `json:"pivot,omitempty"`

	// FavoritesOnly restricts the list to favorited sessions.
	FavoritesOnly bool `json:"favorites_only,omitempty"`

	// ShowHidden includes hidden sessions in the list.
	ShowHidden bool `json:"show_hidden,omitempty"`

	// ExcludedDirs overrides the global excluded directories for this view.
	ExcludedDirs []string `json:"excluded_dirs,omitempty"`
}

NamedView holds a saved combination of list state filters that can be applied together to quickly switch between common session browsing setups.

func (*NamedView) Validate added in v0.13.0

func (v *NamedView) Validate() error

Validate returns an error if the view has invalid or missing fields.

type SessionLaunch added in v0.14.0

type SessionLaunch struct {
	// Count is the total number of times the session has been launched.
	Count int `json:"count"`

	// Last is the Unix time (seconds) of the most recent launch.
	Last int64 `json:"last"`
}

SessionLaunch records how many times a session has been launched from Dispatch and when it was last launched. It powers the frecency sort.

Jump to

Keyboard shortcuts

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