config

package
v1.1.60 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProjectDirName       = ".mothx"
	LegacyProjectDirName = ".vibe"
)

Variables

View Source
var Verbose bool

Verbose controls whether config loading prints diagnostic messages to stderr.

Functions

func BoolPtr

func BoolPtr(v bool) *bool

BoolPtr returns a pointer to the given bool value.

func CloneBoolPtr

func CloneBoolPtr(src *bool) *bool

CloneBoolPtr returns a deep copy of a bool pointer, or nil if src is nil.

func CloneFloat64Ptr

func CloneFloat64Ptr(src *float64) *float64

CloneFloat64Ptr returns a deep copy of a float64 pointer, or nil if src is nil.

func CloneStringMap

func CloneStringMap(src map[string]string) map[string]string

CloneStringMap returns a deep copy of a string map, or nil if src is nil.

func CloneStringSlice

func CloneStringSlice(src []string) []string

CloneStringSlice returns a deep copy of a string slice, or nil if src is nil.

func ConfigDir

func ConfigDir() string

func DefaultProviderConfigs

func DefaultProviderConfigs() map[string]*ProviderConfig

DefaultProviderConfigs returns a deep copy of all built-in provider presets. The returned map is safe for callers to modify without affecting the global defaults.

func GlobalAllowPath

func GlobalAllowPath() string

GlobalAllowPath returns the global allow.json path.

func GlobalMCPPath

func GlobalMCPPath() string

GlobalMCPPath returns the global mcp.json path.

func GlobalSettingsPath

func GlobalSettingsPath() string

func LoadSettingsWithMeta

func LoadSettingsWithMeta() (*Settings, LoadMeta, error)

LoadSettingsWithMeta loads settings and reports whether the global settings file was created during this call. The loaded schema is the same as LoadSettings.

func NormalizeMCPConfig

func NormalizeMCPConfig(cfg *MCPConfig)

NormalizeMCPConfig applies basic defaults.

func ProjectAllowPath

func ProjectAllowPath() string

ProjectAllowPath returns the project-level allow.json path.

func ProjectMCPPath

func ProjectMCPPath() string

ProjectMCPPath returns the project-local mcp.json path.

func ProjectPath added in v1.1.59

func ProjectPath(elem ...string) string

ProjectPath returns a project-level path under .mothx in the current working directory. It also performs the one-time legacy .vibe migration.

func ProjectPathFor added in v1.1.59

func ProjectPathFor(cwd string, elem ...string) string

ProjectPathFor returns a project-level path under cwd/.mothx. It also performs the one-time legacy .vibe migration for cwd.

func ProjectSettingsPath

func ProjectSettingsPath() string

func SaveGlobalSettings

func SaveGlobalSettings(s *Settings) error

SaveGlobalSettings writes settings.json atomically with private permissions.

func SaveGlobalSettingsPatch

func SaveGlobalSettingsPatch(updates map[string]any) error

SaveGlobalSettingsPatch updates only the given top-level keys in the global settings file. It preserves keys that are already present without expanding defaults into settings.json.

func SaveMCPConfig

func SaveMCPConfig(path string, cfg *MCPConfig) error

SaveMCPConfig writes mcp.json to path.

func SaveProjectSettings

func SaveProjectSettings(s *Settings) error

SaveProjectSettings writes .mothx/settings.json atomically with private permissions.

Types

type AllowConfig

type AllowConfig struct {
	AutoEdit     bool     `json:"autoEdit,omitempty"`
	EditPaths    []string `json:"editPaths,omitempty"`
	BashCommands []string `json:"bashCommands,omitempty"`
	BashPrefixes []string `json:"bashPrefixes,omitempty"`
	// contains filtered or unexported fields
}

AllowConfig holds runtime auto-approval settings that are persisted separately from settings.json in allow.json.

  • AutoEdit: when true, write/edit tools auto-approve in agent mode.
  • EditPaths: glob whitelist of paths whose write/edit auto-approve in agent mode. Supports "**" (cross-directory) and "*" (single segment).
  • BashCommands/BashPrefixes: project-level command allow rules for bash auto-approval in agent mode.

Loading follows the same global->project override order as settings.json: AutoEdit is taken from the project file when present, otherwise the global file. EditPaths and bash allow rules are project-level only.

func LoadAllow

func LoadAllow() *AllowConfig

LoadAllow loads allow configuration with global->project override semantics. AutoEdit defaults to enabled unless global or project allow.json explicitly sets it; EditPaths and bash allow rules are project-level only.

func (*AllowConfig) AddBashCommand

func (c *AllowConfig) AddBashCommand(command string) bool

AddBashCommand appends an exact bash command allow rule if not already present.

func (*AllowConfig) AddBashPrefix

func (c *AllowConfig) AddBashPrefix(prefix string) bool

AddBashPrefix appends a bash command prefix allow rule if not already present. Trailing spaces are preserved because command prefixes are matched literally.

func (*AllowConfig) AddEditPath

func (c *AllowConfig) AddEditPath(glob string) bool

AddEditPath appends a glob to the whitelist if not already present. Returns true when the list changed.

func (*AllowConfig) ClearEditPaths

func (c *AllowConfig) ClearEditPaths()

ClearEditPaths empties the whitelist.

func (*AllowConfig) EditPathList

func (c *AllowConfig) EditPathList() []string

EditPathList returns a copy of the current edit-path whitelist.

func (*AllowConfig) GetAutoEdit

func (c *AllowConfig) GetAutoEdit() bool

GetAutoEdit reports the current AutoEdit flag.

func (*AllowConfig) MatchBashCommand

func (c *AllowConfig) MatchBashCommand(command string) bool

MatchBashCommand reports whether command matches any project bash allow rule.

func (*AllowConfig) MatchEditPath

func (c *AllowConfig) MatchEditPath(path string) bool

MatchEditPath reports whether path matches any whitelist glob.

func (*AllowConfig) RemoveBashCommand

func (c *AllowConfig) RemoveBashCommand(command string) bool

RemoveBashCommand removes an exact bash command allow rule if present.

func (*AllowConfig) RemoveBashPrefix

func (c *AllowConfig) RemoveBashPrefix(prefix string) bool

RemoveBashPrefix removes a bash command prefix allow rule if present.

func (*AllowConfig) RemoveEditPath

func (c *AllowConfig) RemoveEditPath(glob string) bool

RemoveEditPath removes a glob from the whitelist. Returns true when removed.

func (*AllowConfig) SaveGlobalAutoEdit

func (c *AllowConfig) SaveGlobalAutoEdit() error

SaveGlobalAutoEdit persists only autoEdit to the global file, preserving any other keys that may exist there.

func (*AllowConfig) SaveGlobalAutoEditValue

func (c *AllowConfig) SaveGlobalAutoEditValue(v bool) error

SaveGlobalAutoEditValue persists the provided global autoEdit value without changing project-scoped effective state in memory.

func (*AllowConfig) SaveProject

func (c *AllowConfig) SaveProject() error

SaveProject persists the project config. The project autoEdit key is written only when it was explicitly set at project scope; inherited global state is never copied into .mothx/allow.json as a side effect of editing path rules.

func (*AllowConfig) SetAutoEdit

func (c *AllowConfig) SetAutoEdit(v bool)

SetAutoEdit updates the in-memory AutoEdit flag.

func (*AllowConfig) SetGlobalAutoEdit

func (c *AllowConfig) SetGlobalAutoEdit(v bool) bool

SetGlobalAutoEdit updates the effective AutoEdit flag only when the project file does not explicitly override it. It returns the current effective value.

func (*AllowConfig) SetProjectAutoEdit

func (c *AllowConfig) SetProjectAutoEdit(v bool)

SetProjectAutoEdit updates the AutoEdit flag and marks it as explicitly set at project scope, so SaveProject can persist false as an intentional override.

type ApprovalSettings

type ApprovalSettings struct {
	// BashWhitelist is a list of command prefixes that auto-approve in agent mode
	BashWhitelist []string `json:"bashWhitelist,omitempty"`
	// BashBlacklist is a list of command prefixes that always require approval (even in yolo mode if configured)
	BashBlacklist []string `json:"bashBlacklist,omitempty"`
	// ConfirmBeforeWrite requires user approval before write/edit tools run in agent mode.
	ConfirmBeforeWrite *bool `json:"confirmBeforeWrite,omitempty"`
}

type CompactionSettings

type CompactionSettings struct {
	Enabled          bool   `json:"enabled"`
	ReserveTokens    int    `json:"reserveTokens"`
	KeepRecentTokens int    `json:"keepRecentTokens"`
	Tokenizer        string `json:"tokenizer,omitempty"`
	TokenizerModel   string `json:"tokenizerModel,omitempty"`
	Template         string `json:"template,omitempty"`

	// Idle compression settings (R5.1-R5.5)
	IdleCompressionEnabled   bool `json:"idleCompressionEnabled,omitempty"`   // R5.1: off by default
	IdleTimeoutSeconds       int  `json:"idleTimeoutSeconds,omitempty"`       // seconds of inactivity (default: 90)
	IdleMinTokensForCompress int  `json:"idleMinTokensForCompress,omitempty"` // minimum tokens to trigger (default: 150000)
}

type ContextFilesSettings

type ContextFilesSettings struct {
	Enabled    bool     `json:"enabled"`
	ExtraFiles []string `json:"extraFiles,omitempty"`
}

type CostConfig

type CostConfig struct {
	Input      float64 `json:"input"`
	Output     float64 `json:"output"`
	CacheRead  float64 `json:"cacheRead,omitempty"`
	CacheWrite float64 `json:"cacheWrite,omitempty"`
}

type DirMigration added in v1.1.59

type DirMigration struct {
	Scope    string
	OldPath  string
	NewPath  string
	Migrated bool
	Skipped  bool
	Err      error
}

func AutoMigrateGlobalDir added in v1.1.59

func AutoMigrateGlobalDir() (DirMigration, bool)

AutoMigrateGlobalDir migrates the default global directory from .vibecoding to .mothx. Custom directories from MOTHX_DIR/VIBECODING_DIR are left alone.

func AutoMigrateLegacyDirs added in v1.1.59

func AutoMigrateLegacyDirs(cwd string) []DirMigration

AutoMigrateLegacyDirs moves legacy VibeCoding directories to their MothX names when the destination does not already exist.

func AutoMigrateProjectDir added in v1.1.59

func AutoMigrateProjectDir(cwd string) (DirMigration, bool)

AutoMigrateProjectDir migrates cwd/.vibe to cwd/.mothx when needed.

type LoadMeta

type LoadMeta struct {
	CreatedGlobalConfig bool
	GlobalSettingsPath  string
}

LoadMeta describes side effects and paths from settings loading.

type MCPConfig

type MCPConfig struct {
	MCPServers []MCPServer `json:"mcpServers,omitempty"`
}

MCPConfig is the standalone MCP configuration file schema.

func DefaultMCPConfig

func DefaultMCPConfig() *MCPConfig

DefaultMCPConfig returns a starter mcp.json template.

func FullMCPConfigTemplate

func FullMCPConfigTemplate() *MCPConfig

FullMCPConfigTemplate returns a comprehensive multi-transport template.

func LoadMCPConfig

func LoadMCPConfig(path string) (*MCPConfig, error)

LoadMCPConfig reads and parses mcp.json from path.

type MCPServer

type MCPServer struct {
	Name       string   `json:"name"`
	Type       string   `json:"type,omitempty"`
	Command    string   `json:"command,omitempty"`
	URL        string   `json:"url,omitempty"`
	MessageURL string   `json:"messageUrl,omitempty"`
	Args       []string `json:"args,omitempty"`
	Headers    []struct {
		Name  string `json:"name"`
		Value string `json:"value"`
	} `json:"headers,omitempty"`
	Env []struct {
		Name  string `json:"name"`
		Value string `json:"value"`
	} `json:"env,omitempty"`
}

MCPServer defines one MCP server entry in mcp.json.

type ModelCompat

type ModelCompat struct {
	// Thinking/reasoning
	ThinkingFormat                              string `json:"thinkingFormat,omitempty"`
	RequiresReasoningContentOnAssistant         bool   `json:"requiresReasoningContentOnAssistant,omitempty"`
	RequiresReasoningContentOnAssistantMessages bool   `json:"requiresReasoningContentOnAssistantMessages,omitempty"`
	ForceAdaptiveThinking                       bool   `json:"forceAdaptiveThinking,omitempty"`
	// ParseReasoningInContent extracts reasoning wrapped in <think>...</think>
	// tags from the content stream (for models that inline thinking in the body
	// instead of using a separate reasoning_content field).
	ParseReasoningInContent bool `json:"parseReasoningInContent,omitempty"`

	// API parameter compatibility
	SupportsDeveloperRole   *bool  `json:"supportsDeveloperRole,omitempty"`
	SupportsStore           *bool  `json:"supportsStore,omitempty"`
	SupportsReasoningEffort *bool  `json:"supportsReasoningEffort,omitempty"`
	SupportsStrictMode      *bool  `json:"supportsStrictMode,omitempty"`
	MaxTokensField          string `json:"maxTokensField,omitempty"`

	// Cache
	SupportsCacheControlOnTools *bool `json:"supportsCacheControlOnTools,omitempty"`
	SupportsLongCacheRetention  *bool `json:"supportsLongCacheRetention,omitempty"`
	SupportsPromptCacheKey      *bool `json:"supportsPromptCacheKey,omitempty"`
	SupportsReasoningSummary    *bool `json:"supportsReasoningSummary,omitempty"`
	SendSessionAffinityHeaders  bool  `json:"sendSessionAffinityHeaders,omitempty"`

	// Streaming
	SupportsEagerToolInputStreaming *bool `json:"supportsEagerToolInputStreaming,omitempty"`
}

ModelCompat defines per-model compatibility flags (Decision 14). Reference: pi/packages/ai/src/models.generated.ts compat field

type ModelConfig

type ModelConfig struct {
	ID            string       `json:"id"`
	Name          string       `json:"name"`
	Reasoning     bool         `json:"reasoning,omitempty"`
	ContextWindow int          `json:"contextWindow,omitempty"`
	MaxTokens     int          `json:"maxTokens,omitempty"`
	Temperature   *float64     `json:"temperature,omitempty"` // nil = use API default
	TopP          *float64     `json:"top_p,omitempty"`       // nil = use API default
	Cost          *CostConfig  `json:"cost,omitempty"`
	Input         []string     `json:"input,omitempty"`
	Compat        *ModelCompat `json:"compat,omitempty"` // Vendor compatibility flags (Decision 14)
	// contains filtered or unexported fields
}

func DefaultModelConfig

func DefaultModelConfig(providerID, modelID string) *ModelConfig

DefaultModelConfig returns a deep copy of a specific model's built-in config under a given provider. Returns nil if the provider or model is unknown.

func ResolveModelConfig

func ResolveModelConfig(providerID, modelID string, runtime *Settings) *ModelConfig

ResolveModelConfig merges built-in model defaults with runtime overrides.

func (ModelConfig) MaxTokensWasSet added in v1.1.59

func (mc ModelConfig) MaxTokensWasSet() bool

func (*ModelConfig) UnmarshalJSON

func (mc *ModelConfig) UnmarshalJSON(data []byte) error

type ProviderConfig

type ProviderConfig struct {
	Vendor         string            `json:"vendor,omitempty"`    // Explicit vendor adapter (Decision 12/13)
	APIKey         string            `json:"apiKey,omitempty"`    // API key or env/shell reference
	BaseURL        string            `json:"baseUrl,omitempty"`   // API base URL
	HTTPProxy      string            `json:"httpProxy,omitempty"` // optional per-provider HTTP proxy URL, e.g. http://127.0.0.1:7890
	ForceHTTP11    bool              `json:"forceHTTP11,omitempty"`
	Headers        map[string]string `json:"headers,omitempty"` // optional per-provider HTTP headers
	API            string            `json:"api,omitempty"`
	ThinkingFormat string            `json:"thinkingFormat,omitempty"` // "", "openai", "anthropic", "deepseek", "xiaomi"
	CacheControl   *bool             `json:"cacheControl,omitempty"`   // enable Anthropic prompt caching (nil/false=off, true=on; set true for Claude models)
	Responses      ResponsesConfig   `json:"responses,omitempty"`
	Models         []ModelConfig     `json:"models"`
	// contains filtered or unexported fields
}

func DefaultProviderConfig

func DefaultProviderConfig(providerID string) *ProviderConfig

DefaultProviderConfig returns a deep copy of a single built-in provider preset, or nil if the provider ID has no built-in default.

func ResolveProviderConfig

func ResolveProviderConfig(providerID string, runtime *Settings) *ProviderConfig

ResolveProviderConfig merges built-in provider defaults with runtime overrides. Priority: runtime settings > built-in defaults > safe generic defaults.

func (*ProviderConfig) UnmarshalJSON

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

type ResponsesConfig

type ResponsesConfig struct {
	ReasoningSummary     string `json:"reasoningSummary,omitempty"`     // "auto" (default), "concise", or "detailed"
	PromptCacheEnabled   *bool  `json:"promptCacheEnabled,omitempty"`   // nil/true = on, false = off
	PromptCacheKey       string `json:"promptCacheKey,omitempty"`       // optional explicit cache key; defaults to provider/model stable key
	PromptCacheRetention string `json:"promptCacheRetention,omitempty"` // optional OpenAI prompt cache retention value
}

type RetrySettings

type RetrySettings struct {
	Enabled     bool `json:"enabled"`
	MaxRetries  int  `json:"maxRetries"`
	BaseDelayMs int  `json:"baseDelayMs"`
}

type SandboxSettings

type SandboxSettings struct {
	Enabled      bool     `json:"enabled"`
	Level        string   `json:"level"`
	BwrapPath    string   `json:"bwrapPath,omitempty"`
	AllowNetwork bool     `json:"allowNetwork"`
	AllowedRead  []string `json:"allowedRead,omitempty"`
	AllowedWrite []string `json:"allowedWrite,omitempty"`
	DeniedPaths  []string `json:"deniedPaths,omitempty"`
	PassEnv      []string `json:"passEnv,omitempty"`
	TmpSize      string   `json:"tmpSize,omitempty"`
}

type Settings

type Settings struct {
	Providers            map[string]*ProviderConfig `json:"providers,omitempty"`
	DefaultProvider      string                     `json:"defaultProvider,omitempty"`
	DefaultModel         string                     `json:"defaultModel,omitempty"`
	DefaultThinkingLevel string                     `json:"defaultThinkingLevel,omitempty"`
	DefaultMode          string                     `json:"defaultMode,omitempty"`
	StatusLine           StatusLineSettings         `json:"statusLine,omitempty"`
	EnablePlanTool       *bool                      `json:"enablePlanTool,omitempty"`
	WebSearch            WebSearchSettings          `json:"webSearch"`
	MaxContextTokens     int                        `json:"maxContextTokens,omitempty"`
	MaxOutputTokens      int                        `json:"maxOutputTokens,omitempty"`
	ContextFiles         ContextFilesSettings       `json:"contextFiles"`
	SkillsDir            string                     `json:"skillsDir,omitempty"`
	Compaction           CompactionSettings         `json:"compaction"`
	Sandbox              SandboxSettings            `json:"sandbox"`
	SessionDir           string                     `json:"sessionDir,omitempty"`
	ShellPath            string                     `json:"shellPath,omitempty"`
	ShellCommandPrefix   string                     `json:"shellCommandPrefix,omitempty"`
	Theme                string                     `json:"theme,omitempty"`
	Retry                RetrySettings              `json:"retry"`
	Approval             ApprovalSettings           `json:"approval"`
	UpdateCheck          *bool                      `json:"updateCheck,omitempty"` // nil/true = check npm for updates on startup, false = disabled
}

Settings holds all configuration for vibecoding.

func DefaultSettings

func DefaultSettings() *Settings

func LoadGlobalSettingsOrDefault

func LoadGlobalSettingsOrDefault() (*Settings, error)

LoadGlobalSettingsOrDefault loads only the global settings file over defaults. It intentionally does not apply project settings or environment overrides, so callers that need a full runnable global config can avoid persisting runtime state.

func LoadGlobalSettingsSparse

func LoadGlobalSettingsSparse() (*Settings, error)

LoadGlobalSettingsSparse loads only fields explicitly present in the global settings file. If the file does not exist, it returns an empty Settings. Use this for patch-style writes so defaults are not expanded into settings.json.

func LoadProjectSettingsSparse

func LoadProjectSettingsSparse() (*Settings, error)

LoadProjectSettingsSparse loads only fields explicitly present in the project settings file. If the file does not exist, it returns an empty Settings.

func LoadSettings

func LoadSettings() (*Settings, error)

func (*Settings) GetGlobalSkillsDir

func (s *Settings) GetGlobalSkillsDir() string

func (*Settings) GetModelConfig

func (s *Settings) GetModelConfig(providerName, modelID string) *ModelConfig

func (*Settings) GetProviderConfig

func (s *Settings) GetProviderConfig(name string) *ProviderConfig

func (*Settings) GetSessionDir

func (s *Settings) GetSessionDir() string

func (*Settings) GetShell

func (s *Settings) GetShell() string

func (*Settings) IsPlanToolEnabled

func (s *Settings) IsPlanToolEnabled() bool

func (*Settings) IsUpdateCheckEnabled

func (s *Settings) IsUpdateCheckEnabled() bool

IsUpdateCheckEnabled reports whether startup update checks against the npm registry are enabled. Defaults to true when unset.

func (*Settings) IsWebSearchEnabled

func (s *Settings) IsWebSearchEnabled() bool

func (*Settings) ResolveKey

func (s *Settings) ResolveKey(providerName string) string

func (*Settings) ResolveProviderHeaders

func (s *Settings) ResolveProviderHeaders(providerName string) map[string]string

ResolveProviderHeaders resolves configured per-provider HTTP header values. Header values use the same env-var and shell-command resolution rules as apiKey.

func (*Settings) UnmarshalJSON

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

type StatusLineSettings

type StatusLineSettings struct {
	Enabled         bool   `json:"enabled,omitempty"`
	Type            string `json:"type,omitempty"`
	Command         string `json:"command,omitempty"`
	Padding         int    `json:"padding,omitempty"`
	RefreshInterval int    `json:"refreshInterval,omitempty"`
	TimeoutMs       int    `json:"timeoutMs,omitempty"`
	Fallback        string `json:"fallback,omitempty"`
}

type WebSearchSettings

type WebSearchSettings struct {
	Enabled      *bool  `json:"enabled,omitempty"`
	Provider     string `json:"provider,omitempty"`
	ProviderType string `json:"providerType,omitempty"`
	Model        string `json:"model,omitempty"`
}

Jump to

Keyboard shortcuts

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