config

package
v0.12.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	ToolNameBash              = "Bash"
	ToolNameMCPGitHubCreatePR = "mcp__github__create_pull_request"
)

Tool names for PreToolUse hook matching

View Source
const ClaudeStateDirEnv = "CONFAB_CLAUDE_DIR"

ClaudeStateDirEnv is the environment variable to override the default Claude state directory

View Source
const DisableLinkFromGitHubEnv = "CONFAB_DISABLE_LINK_FROM_GITHUB"

DisableLinkFromGitHubEnv is the environment variable to disable GitHub linking. When set to any non-empty value, GitHub linking (commits and PRs) is disabled.

Variables

This section is empty.

Functions

func ApplyLogLevel

func ApplyLogLevel()

ApplyLogLevel reads the log level from config and applies it to the logger

func AtomicUpdateSettings

func AtomicUpdateSettings(updateFn func(*ClaudeSettings) error) error

AtomicUpdateSettings performs a read-modify-write with optimistic locking. It retries up to maxRetries times if the file is modified by another process. The updateFn receives the current settings and should modify them in-place.

Race condition limitation: The mtime check and rename are not truly atomic. There's a small window (<1ms) between os.Stat() and os.Rename() where another process could modify the file. The retry mechanism mitigates but does not eliminate this race. For most use cases (CLI hook installation, infrequent config changes), the retry logic provides sufficient reliability. If truly atomic updates are required, file locking (flock) would be needed.

func EnsureDefaultRedaction

func EnsureDefaultRedaction() (bool, error)

EnsureDefaultRedaction ensures the config has a redaction section with defaults. If redaction config already exists (even if disabled), it's left unchanged. Returns true if defaults were added, false if config already had redaction settings.

func GetBinaryPath

func GetBinaryPath() (string, error)

GetBinaryPath returns the absolute path to the confab binary

func GetClaudeSettingsPath

func GetClaudeSettingsPath() (string, error)

GetSettingsPath returns the path to the Claude settings file

func GetClaudeStateDir

func GetClaudeStateDir() (string, error)

GetClaudeStateDir returns the Claude state directory path. Defaults to ~/.claude but can be overridden with CONFAB_CLAUDE_DIR env var. This is useful for testing and non-standard installations.

func GetProjectsDir

func GetProjectsDir() (string, error)

GetProjectsDir returns the path to the Claude projects directory

func GetSettingsPath

func GetSettingsPath() (string, error)

GetSettingsPath returns the path to the Claude settings file (defaults to ~/.claude/settings.json, can be overridden with CONFAB_CLAUDE_DIR)

func InstallPostToolUseHooks

func InstallPostToolUseHooks() error

InstallPostToolUseHooks installs the PostToolUse hook for GitHub link tracking. This installs hooks with "Bash" and MCP matchers to capture PR creation output.

func InstallPreToolUseHooks

func InstallPreToolUseHooks() error

InstallPreToolUseHooks installs the PreToolUse hook for git commit validation. This installs a hook with a "Bash" matcher to intercept git commit commands.

func InstallSyncHooks

func InstallSyncHooks() error

InstallSyncHooks installs hooks for incremental sync daemon This installs both SessionStart (to start daemon) and SessionEnd (to stop daemon)

func InstallUserPromptSubmitHook

func InstallUserPromptSubmitHook() error

InstallUserPromptSubmitHook installs the UserPromptSubmit hook. Unlike other hooks, UserPromptSubmit doesn't use matchers.

func IsLinkFromGitHubDisabled

func IsLinkFromGitHubDisabled() bool

IsLinkFromGitHubDisabled returns true if GitHub linking is disabled via environment variable.

func IsPostToolUseHooksInstalled

func IsPostToolUseHooksInstalled() (bool, error)

IsPostToolUseHooksInstalled checks if the PostToolUse hook is installed

func IsPreToolUseHooksInstalled

func IsPreToolUseHooksInstalled() (bool, error)

IsPreToolUseHooksInstalled checks if the PreToolUse hook is installed

func IsSyncHooksInstalled

func IsSyncHooksInstalled() (bool, error)

IsSyncHooksInstalled checks if sync daemon hooks are installed This checks for both old ("sync start/stop") and new ("hook session-start/end") patterns

func IsUserPromptSubmitHookInstalled

func IsUserPromptSubmitHookInstalled() (bool, error)

IsUserPromptSubmitHookInstalled checks if the UserPromptSubmit hook is installed

func ParseLogLevel

func ParseLogLevel(level string) (logger.Level, error)

ParseLogLevel parses a log level string and returns the corresponding logger.Level

func SaveUploadConfig

func SaveUploadConfig(config *UploadConfig) error

SaveUploadConfig writes upload configuration to ~/.confab/config.json

func UninstallPostToolUseHooks

func UninstallPostToolUseHooks() error

UninstallPostToolUseHooks removes the PostToolUse hook

func UninstallPreToolUseHooks

func UninstallPreToolUseHooks() error

UninstallPreToolUseHooks removes the PreToolUse hook

func UninstallSyncHooks

func UninstallSyncHooks() error

UninstallSyncHooks removes the sync daemon hooks This handles both old ("sync start/stop") and new ("hook session-start/end") patterns

func UninstallUserPromptSubmitHook

func UninstallUserPromptSubmitHook() error

UninstallUserPromptSubmitHook removes the UserPromptSubmit hook

func ValidateAPIKey

func ValidateAPIKey(apiKey string) error

ValidateAPIKey checks if the API key format is valid. Confab API keys have the format: cfb_<40 alphanumeric chars> Returns nil for empty string (not configured), but empty is not a valid key.

func ValidateBackendURL

func ValidateBackendURL(backendURL string) error

ValidateBackendURL checks if the backend URL is valid

Types

type ClaudeSettings

type ClaudeSettings struct {
	// contains filtered or unexported fields
}

ClaudeSettings wraps the raw settings map to preserve all fields. This is similar to Python's json.load/json.dump pattern. We intentionally avoid typed structs for hooks since the schema is controlled by Claude Code and evolves rapidly.

func ReadSettings

func ReadSettings() (*ClaudeSettings, error)

ReadSettings reads the Claude settings file, preserving all fields

type RedactionConfig

type RedactionConfig struct {
	Enabled            bool               `json:"enabled"`
	UseDefaultPatterns *bool              `json:"use_default_patterns,omitempty"` // defaults to true if nil
	Patterns           []RedactionPattern `json:"patterns,omitempty"`
}

RedactionConfig holds redaction settings

func (*RedactionConfig) ShouldUseDefaultPatterns

func (c *RedactionConfig) ShouldUseDefaultPatterns() bool

ShouldUseDefaultPatterns returns true if default patterns should be used. Defaults to true if UseDefaultPatterns is nil.

type RedactionPattern

type RedactionPattern struct {
	Name         string `json:"name"`
	Pattern      string `json:"pattern,omitempty"`
	Type         string `json:"type"`
	CaptureGroup int    `json:"capture_group,omitempty"`
	FieldPattern string `json:"field_pattern,omitempty"`
}

RedactionPattern represents a single redaction pattern

func GetDefaultRedactionPatterns

func GetDefaultRedactionPatterns() []RedactionPattern

GetDefaultRedactionPatterns returns the default high-precision redaction patterns

type UploadConfig

type UploadConfig struct {
	BackendURL string           `json:"backend_url"`
	APIKey     string           `json:"api_key"`
	LogLevel   string           `json:"log_level,omitempty"`   // debug, info, warn, error (default: info)
	AutoUpdate *bool            `json:"auto_update,omitempty"` // nil = enabled (default), false = disabled
	Redaction  *RedactionConfig `json:"redaction,omitempty"`
}

UploadConfig holds backend upload configuration

func EnsureAuthenticated

func EnsureAuthenticated() (*UploadConfig, error)

EnsureAuthenticated reads the config and verifies it has valid credentials Returns the config if authenticated, or an error if not configured

func GetUploadConfig

func GetUploadConfig() (*UploadConfig, error)

GetUploadConfig reads upload configuration from ~/.confab/config.json

func (*UploadConfig) IsAutoUpdateEnabled added in v0.10.2

func (c *UploadConfig) IsAutoUpdateEnabled() bool

IsAutoUpdateEnabled returns whether auto-update is enabled. Defaults to true when AutoUpdate is nil (not set in config).

func (*UploadConfig) Validate

func (c *UploadConfig) Validate() error

Validate checks if the upload config is valid

Jump to

Keyboard shortcuts

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