config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AgentDefaultMaxRetries     = 4
	AgentDefaultInitialDelayMs = 2000
	AgentDefaultBackoffFactor  = 2.0
)
View Source
const (
	WorkflowScopeUser   = "user"
	WorkflowScopeRepo   = "repo"
	WorkflowScopeGlobal = "global"
	WorkflowScopePlugin = "plugin"

	WorkflowStepKindAgent = ""
	WorkflowStepKindLoop  = "loop"

	WorkflowLoopBreak    = "break"
	WorkflowLoopContinue = "continue"

	WorkflowLoopDefaultMaxIterations = 10
)
View Source
const AskLockPrefix = "ask:"
View Source
const GitHubMCPDefaultEndpoint = "https://api.githubcopilot.com/mcp"
View Source
const LinearGraphQLDefaultEndpoint = "https://api.linear.app/graphql"

Variables

View Source
var ProviderConfigReservedKeys = []string{providerConfigKeyModel, providerConfigKeySlashCommands}

ProviderConfigReservedKeys are the typed keys of a provider block; a provider must not declare a setting under one of them.

Functions

func AgentRetryOptions

func AgentRetryOptions(cfg Config) (maxRetries int, initialDelay time.Duration, backoffFactor float64)

func ConfigPath

func ConfigPath() (string, error)

ConfigPath returns the standard configuration file path.

func EnsureWorktreeGitignore

func EnsureWorktreeGitignore(cwd string)

func GitHubMCPEndpointOrDefault

func GitHubMCPEndpointOrDefault(c GitHubMCPConfig) string

func GitignoreCoversWorktrees

func GitignoreCoversWorktrees(contents string) bool

GitignoreCoversWorktrees reports whether a .gitignore body already ignores the .claude/worktrees/ tree (directly or via a broader .claude rule).

func InGitCheckout

func InGitCheckout() bool

func InGitCheckoutAt

func InGitCheckoutAt(cwd string) bool

func InJujutsuCheckoutAt

func InJujutsuCheckoutAt(cwd string) bool

func IsProjectConfigEmpty

func IsProjectConfigEmpty(pc ProjectConfig) bool

IsProjectConfigEmpty reports whether pc carries no user-meaningful data.

func LinearGraphQLEndpointOrDefault

func LinearGraphQLEndpointOrDefault(c LinearMCPConfig) string

func MigrateLegacyIssuesGitHub

func MigrateLegacyIssuesGitHub(cfg *Config, data []byte)

MigrateLegacyIssuesGitHub lifts the old per-project `issues.github.{endpoint,token}` block into the new `mcp.github.{endpoint,token}` slot.

func MigrateLegacyProviderBlocks

func MigrateLegacyProviderBlocks(cfg *Config, data []byte)

MigrateLegacyProviderBlocks lifts the pre-registry top-level provider blocks ("vertex": {…}, "openrouter": {…}) into Config.Providers. Each block is already flat, so it decodes as a ProviderConfig directly; the keys listed in legacyProviderBlocks are dropped after the serviceAccount alias is honoured. Runs only for ids absent from the new map — an explicit new block always wins.

func MigrateLegacyProviderEffort

func MigrateLegacyProviderEffort(cfg *Config, data []byte)

MigrateLegacyProviderEffort folds old per-provider effort fields into the new global Config.Effort field. It maps the first non-empty value found.

func MigrateLegacyToolOutput

func MigrateLegacyToolOutput(cfg *Config, data []byte)

MigrateLegacyToolOutput folds the deprecated "renderToolOutput" bool into the new tri-state "toolOutput" string so users who upgrade don't see their tool rendering reset on first launch. Runs only when the new key is absent — an explicit new setting always wins.

func ProjectKey

func ProjectKey(cwd string) string

ProjectKey returns the canonical key for project lookups.

func ProjectRoot

func ProjectRoot(cwd string) string

ProjectRoot returns the repository root for cwd, or the cleaned cwd if not in a repository.

func ResolveBraveAPIKey

func ResolveBraveAPIKey(c WebSearchConfig) string

ResolveBraveAPIKey returns the Brave Search API key from config or environment.

func Save

func Save(cfg Config) error

Save marshals and writes the configuration file atomically with 0600 permissions.

func SaveProject

func SaveProject(cwd string, pc ProjectConfig) error

SaveProject updates the per-project settings bag for cwd.

func SaveProjectLocked

func SaveProjectLocked(cwd string, pc ProjectConfig) error

SaveProjectLocked updates the per-project settings bag for cwd without acquiring the lock.

func WithConfigLock

func WithConfigLock(fn func() error) error

WithConfigLock holds configFileMu around fn for atomic read-modify-write sequences.

func WorktreeEnabled

func WorktreeEnabled(cfg Config, cwd string) bool

WorktreeEnabled resolves the effective worktree flag for cwd: the project override when set, else the global UI.Worktree, else false.

func WorktreeNameFromCwd

func WorktreeNameFromCwd(cwd string) string

Types

type AskCwdInvalidErr

type AskCwdInvalidErr struct {
	Msg          string
	WorktreeName string
}

func ValidateAskCwd

func ValidateAskCwd(cwd string) AskCwdInvalidErr

type Config

type Config struct {
	Provider string `json:"provider,omitempty"`
	Effort   string `json:"effort,omitempty"`
	// Providers holds one block per registered provider id. Providers
	// declare their own fields (pkg/providers SettingField); config only
	// stores them.
	Providers  map[string]ProviderConfig  `json:"providers,omitempty"`
	UI         UIConfig                   `json:"ui,omitempty"`
	WebSearch  WebSearchConfig            `json:"webSearch,omitempty"`
	MCPServers map[string]MCPServerConfig `json:"mcpServers,omitempty"`
	// MCPDisabled overrides the effective enabled/disabled state of an MCP
	// server by name, regardless of which source defined it (project
	// .mcp.json, user/project config, or a plugin). true = disabled,
	// false = force-enabled. Absent = fall back to the server's own state.
	MCPDisabled  map[string]bool          `json:"mcpDisabled,omitempty"`
	Keybindings  map[string]string        `json:"keybindings,omitempty"`
	RecentModels []RecentModelRef         `json:"recentModels,omitempty"`
	Projects     map[string]ProjectConfig `json:"projects,omitempty"`
	Memory       MemoryConfig             `json:"memory,omitempty"`
}

Config represents the user-global ask configuration (~/.config/ask/ask.json).

func Load

func Load() (Config, error)

Load reads and unmarshals the configuration file, applying legacy migrations.

func UpsertProjectConfig

func UpsertProjectConfig(cfg Config, cwd string, pc ProjectConfig) Config

UpsertProjectConfig writes pc into cfg.Projects under cwd's key.

func (Config) ProviderConfig

func (c Config) ProviderConfig(id string) ProviderConfig

ProviderConfig returns provider id's block, zero when absent.

func (*Config) SetProviderConfig

func (c *Config) SetProviderConfig(id string, pc ProviderConfig)

SetProviderConfig stores pc under id, dropping the entry (and the map, when it empties) for an empty block so ask.json never grows "{}" rows.

type GitHubMCPConfig

type GitHubMCPConfig struct {
	Endpoint string `json:"endpoint,omitempty"`
	Token    string `json:"token,omitempty"`
}

type IssuesConfig

type IssuesConfig struct {
	Provider string `json:"provider,omitempty"`
	Tracker  string `json:"tracker,omitempty"`
	Repo     string `json:"repo,omitempty"`
	Project  string `json:"project,omitempty"`
	Team     string `json:"team,omitempty"`
	Cycle    string `json:"cycle,omitempty"`
}

type LinearMCPConfig

type LinearMCPConfig struct {
	Endpoint string `json:"endpoint,omitempty"`
	Token    string `json:"token,omitempty"`
	TeamKey  string `json:"teamKey,omitempty"`
}

type MCPServerConfig

type MCPServerConfig struct {
	Type          string            `json:"type,omitempty"`
	Command       string            `json:"command,omitempty"`
	Args          []string          `json:"args,omitempty"`
	Env           map[string]string `json:"env,omitempty"`
	URL           string            `json:"url,omitempty"`
	OAuth         bool              `json:"oauth,omitempty"`
	Timeout       int               `json:"timeout,omitempty"`
	EnabledTools  []string          `json:"enabledTools,omitempty"`
	DisabledTools []string          `json:"disabledTools,omitempty"`
	Disabled      bool              `json:"disabled,omitempty"`
}

type MemoryConfig

type MemoryConfig struct {
	Provider string `json:"provider,omitempty"`
	Model    string `json:"model,omitempty"`
}

MemoryConfig picks the model that runs the post-turn concept extraction. Empty Provider means the session's provider; empty Model means that provider's cheapest listed model.

type ProjectConfig

type ProjectConfig struct {
	Issues      IssuesConfig               `json:"issues,omitempty"`
	MCP         ProjectMCPConfig           `json:"mcp,omitempty"`
	Workflows   WorkflowsConfig            `json:"workflows,omitempty"`
	MCPServers  map[string]MCPServerConfig `json:"mcpServers,omitempty"`
	MCPDisabled map[string]bool            `json:"mcpDisabled,omitempty"`
	Worktree    *bool                      `json:"worktree,omitempty"`
}

func LoadProject

func LoadProject(cwd string) (ProjectConfig, error)

LoadProject returns the project configuration for the canonical cwd.

func LoadProjectConfig

func LoadProjectConfig(cfg Config, cwd string) ProjectConfig

LoadProjectConfig returns the saved ProjectConfig for cwd, or zero value if absent.

type ProjectMCPConfig

type ProjectMCPConfig struct {
	GitHub GitHubMCPConfig `json:"github,omitempty"`
	Linear LinearMCPConfig `json:"linear,omitempty"`
}

type ProviderConfig

type ProviderConfig struct {
	Model         string
	SlashCommands []ProviderSlashEntry
	Fields        map[string]string
}

ProviderConfig is one provider's block under Config.Providers: the model the user picked, the slash commands the provider discovered, and the settings the provider declares (an API key, a project id, …) keyed by their setting key. On disk the block is flat — {"model": "…", "apiKey": "…"} — so ask.json stays hand-editable and byte-compatible with the per-provider blocks it replaced.

func (ProviderConfig) Field

func (pc ProviderConfig) Field(key string) string

Field returns the stored value for key, "" when unset.

func (ProviderConfig) IsEmpty

func (pc ProviderConfig) IsEmpty() bool

IsEmpty reports whether the block carries nothing worth persisting.

func (ProviderConfig) MarshalJSON

func (pc ProviderConfig) MarshalJSON() ([]byte, error)

func (*ProviderConfig) UnmarshalJSON

func (pc *ProviderConfig) UnmarshalJSON(data []byte) error

UnmarshalJSON reads the flat block: the typed keys land on their fields, every other string-valued key lands in Fields. Non-string extras are dropped — provider settings are strings by contract.

func (ProviderConfig) WithField

func (pc ProviderConfig) WithField(key, value string) ProviderConfig

WithField returns a copy of pc with key set to value; an empty value removes the key. The Fields map is copied, never shared.

type ProviderSlashEntry

type ProviderSlashEntry struct {
	Name        string `json:"name"`
	Description string `json:"description"`
}

type RecentModelRef

type RecentModelRef struct {
	Provider string `json:"provider"`
	Model    string `json:"model"`
}

type RetryConfig

type RetryConfig = RetryUIConfig

type RetryUIConfig

type RetryUIConfig struct {
	MaxRetries     *int     `json:"maxRetries,omitempty"`
	InitialDelayMs *int     `json:"initialDelayMs,omitempty"`
	BackoffFactor  *float64 `json:"backoffFactor,omitempty"`
}

type UIConfig

type UIConfig struct {
	QuietMode             *bool          `json:"quietMode,omitempty"`
	CursorBlink           *bool          `json:"cursorBlink,omitempty"`
	RenderDiffs           *bool          `json:"renderDiffs,omitempty"`
	ToolOutput            string         `json:"toolOutput,omitempty"`
	SkipAllPermissions    *bool          `json:"skipAllPermissions,omitempty"`
	Worktree              *bool          `json:"worktree,omitempty"`
	GateTodosBeforeMutate *bool          `json:"gateTodosBeforeMutate,omitempty"`
	Theme                 string         `json:"theme,omitempty"`
	Retry                 *RetryUIConfig `json:"retry,omitempty"`
}

type WebSearchConfig

type WebSearchConfig struct {
	BraveAPIKey string `json:"braveApiKey,omitempty"`
}

type WorkflowDef

type WorkflowDef struct {
	Name        string         `json:"name"`
	Description string         `json:"description,omitempty"`
	Steps       []WorkflowStep `json:"steps,omitempty"`
	Scope       string         `json:"-"`
	// Plugin is the "name@marketplace" that ships this workflow when
	// Scope == WorkflowScopePlugin (read-only).
	Plugin string `json:"-"`
}

type WorkflowSession

type WorkflowSession struct {
	Workflow  string    `json:"workflow"`
	StepIndex int       `json:"stepIndex"`
	Status    string    `json:"status"`
	StartedAt time.Time `json:"startedAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

func (*WorkflowSession) UnmarshalJSON

func (s *WorkflowSession) UnmarshalJSON(data []byte) error

type WorkflowStep

type WorkflowStep struct {
	Name          string         `json:"name"`
	Kind          string         `json:"kind,omitempty"`
	Provider      string         `json:"provider,omitempty"`
	Model         string         `json:"model,omitempty"`
	Prompt        string         `json:"prompt,omitempty"`
	Steps         []WorkflowStep `json:"steps,omitempty"`
	MaxIterations int            `json:"maxIterations,omitempty"`
	ExitCondition string         `json:"exitCondition,omitempty"`
}

func (WorkflowStep) EffectiveMaxIterations

func (s WorkflowStep) EffectiveMaxIterations() int

func (WorkflowStep) IsLoop

func (s WorkflowStep) IsLoop() bool

type WorkflowsConfig

type WorkflowsConfig struct {
	ActiveWorkflow string                     `json:"activeWorkflow,omitempty"`
	Items          []WorkflowDef              `json:"items,omitempty"`
	Sessions       map[string]WorkflowSession `json:"sessions,omitempty"`
}

type WorkspaceBackend

type WorkspaceBackend int
const (
	WorkspaceBackendNone WorkspaceBackend = iota
	WorkspaceBackendGit
	WorkspaceBackendJJ
)

func WorktreeBackendAt

func WorktreeBackendAt(cwd string) WorkspaceBackend

Jump to

Keyboard shortcuts

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