config

package
v0.7.150 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultModel    = "claude-sonnet-4-6"
	AnalyzeModel    = "claude-sonnet-4-6"
	PromptModel     = "claude-opus-4-6"
	ValidationModel = "claude-haiku-4-5-20251001"

	// SourceConfigFile is the source label used when a value comes from the user config file.
	SourceConfigFile = "Config file (user config)"

	// SourceProjectConfig is the source label for values from .chunk/config.json.
	SourceProjectConfig = "Project config (.chunk/config.json)"
)

Model constants define the Claude models used for different operations.

View Source
const (
	EnvCircleToken        = "CIRCLE_TOKEN"
	EnvCircleCIToken      = "CIRCLECI_TOKEN"
	EnvCircleCIBaseURL    = "CIRCLECI_BASE_URL"
	EnvAnthropicAPIKey    = "ANTHROPIC_API_KEY"
	EnvAnthropicBaseURL   = "ANTHROPIC_BASE_URL"
	EnvGitHubToken        = "GITHUB_TOKEN"
	EnvGitHubAPIURL       = "GITHUB_API_URL"
	EnvModel              = "CODE_REVIEW_CLI_MODEL"
	EnvCircleCIOrgID      = "CIRCLECI_ORG_ID"
	EnvChunkHooksDisabled = "CHUNK_HOOKS_DISABLED"
	EnvChunkNoTelemetry   = "CHUNK_NO_TELEMETRY"
)

Chunk-specific environment variable names.

View Source
const (
	EnvHome          = "HOME"
	EnvShell         = "SHELL"
	EnvSSHAuthSock   = "SSH_AUTH_SOCK"
	EnvNoColor       = "NO_COLOR"
	EnvXDGConfigHome = "XDG_CONFIG_HOME"
	EnvXDGStateHome  = "XDG_STATE_HOME"
	EnvXDGDataHome   = "XDG_DATA_HOME"
	EnvNoAnalytics   = "NO_ANALYTICS"
	EnvDoNotTrack    = "DO_NOT_TRACK"
	EnvCI            = "CI"
)

System/standard environment variable names.

View Source
const (
	RoleGate    = "gate"    // pass/fail check
	RoleAutofix = "autofix" // rewrites files (formatters)
)

Command roles describe what a command does. Only RoleGate is acted on: sidecar setup marks gate commands for remote execution.

Variables

View Source
var ValidConfigKeys = map[string]bool{
	"model":              true,
	"useSSHIdentityFile": true,
	"telemetry":          true,
}

ValidConfigKeys are the keys accepted by "config set" that write to the user config. Credentials (anthropicAPIKey, circleCIToken) are intentionally excluded — users should use "auth set" which validates before storing.

View Source
var ValidProjectConfigKeys = map[string]bool{
	"orgID":                   true,
	"validation.sidecarImage": true,
}

ValidProjectConfigKeys are the keys accepted by "config set" that write to the project config (.chunk/config.json).

Functions

func AppData added in v0.7.38

func AppData() (string, error)

AppData returns the chunk data directory, respecting XDG_DATA_HOME.

func AppState added in v0.7.1

func AppState() (string, error)

AppState returns XDG_STATE_HOME or ~/.local/state.

func Clear added in v0.7.24

func Clear(key string) error

Clear removes a stored config value by key.

func Dir

func Dir() (string, error)

Dir returns the chunk config directory, respecting XDG_CONFIG_HOME.

func EnsureInstanceID added in v0.7.117

func EnsureInstanceID() (uuid.UUID, error)

EnsureInstanceID returns the persisted anonymous instance ID used to associate telemetry events with a single install, generating and saving one on first run.

func IsTelemetry added in v0.7.117

func IsTelemetry(cfg UserConfig) bool

IsTelemetry reports whether telemetry should be collected, honoring (in order) well-known opt-out environment variables and the persisted telemetry preference. Telemetry is opt-out: it defaults to enabled when no preference has been set.

func MaskKey added in v0.7.24

func MaskKey(key string) string

MaskKey masks all but the last 4 characters with *.

func Path

func Path() (string, error)

Path returns the full path to config.json.

func ProjectDataDir added in v0.7.38

func ProjectDataDir(projectRoot string) (string, error)

ProjectDataDir returns the per-project data directory keyed by projectRoot. The directory name is the hex-encoded SHA-256 of the real absolute path (symlinks resolved via EvalSymlinks, falling back to filepath.Clean), which ensures callers that discover the root via different means — git's --show-toplevel vs. a manual filesystem walk — always hash the same string.

One-time migration: if the resolved path yields an empty directory but the old unresolved path has existing data, the old directory is renamed to the new location so users with symlinked project roots don't silently lose their sidecar/snapshot/event-log state.

func ResolveOrgID added in v0.7.66

func ResolveOrgID(workDir string) (value, source string)

ResolveOrgID returns the CircleCI org ID for display in config show. Priority: CIRCLECI_ORG_ID env var > orgID in .chunk/config.json for workDir.

func Save

func Save(cfg UserConfig) error

Save writes the config file, creating the directory with 0o700 and file with 0o600.

func SaveCommand added in v0.7.2

func SaveCommand(workDir, name, command string) error

SaveCommand upserts a command in .chunk/config.json.

func SaveProjectConfig added in v0.7.2

func SaveProjectConfig(workDir string, cfg *ProjectConfig) error

SaveProjectConfig writes the config back to .chunk/config.json.

Types

type Command added in v0.7.2

type Command struct {
	Name         string `json:"name"`
	Run          string `json:"run"`
	Role         string `json:"role,omitempty"`
	Timeout      int    `json:"timeout,omitempty"`
	Remote       bool   `json:"remote,omitempty"`
	SidecarImage string `json:"sidecarImage,omitempty"`
}

Command is a single validation command.

type EnvVars added in v0.7.29

type EnvVars struct {
	CircleToken      string `env:"CIRCLE_TOKEN"`
	CircleCIToken    string `env:"CIRCLECI_TOKEN"`
	CircleCIBaseURL  string `env:"CIRCLECI_BASE_URL,default=https://circleci.com"`
	AnthropicAPIKey  string `env:"ANTHROPIC_API_KEY"`
	AnthropicBaseURL string `env:"ANTHROPIC_BASE_URL,default=https://api.anthropic.com"`
	GitHubToken      string `env:"GITHUB_TOKEN"`
	GitHubAPIURL     string `env:"GITHUB_API_URL,default=https://api.github.com"`
	Model            string `env:"CODE_REVIEW_CLI_MODEL"`
	CircleCIOrgID    string `env:"CIRCLECI_ORG_ID"`
	Home             string `env:"HOME"`
	Shell            string `env:"SHELL"`
	SSHAuthSock      string `env:"SSH_AUTH_SOCK"`
	NoColor          string `env:"NO_COLOR"`
	XDGConfigHome    string `env:"XDG_CONFIG_HOME"`
	XDGStateHome     string `env:"XDG_STATE_HOME"`
	XDGDataHome      string `env:"XDG_DATA_HOME"`
}

EnvVars holds all environment variables the application reads.

func LoadEnv added in v0.7.29

func LoadEnv(ctx context.Context) (EnvVars, error)

LoadEnv populates an EnvVars struct from the process environment.

type ProjectConfig added in v0.7.2

type ProjectConfig struct {
	Commands            []Command            `json:"commands,omitempty"`
	VCS                 *VCSConfig           `json:"vcs,omitempty"`
	Validation          *ValidationConfig    `json:"validation,omitempty"`
	OrgID               string               `json:"orgID,omitempty"`
	StopHookMaxAttempts int                  `json:"stopHookMaxAttempts,omitempty"`
	Environment         *envspec.Environment `json:"environment,omitempty"`
}

ProjectConfig is the per-repo configuration stored in .chunk/config.json.

func LoadProjectConfig added in v0.7.2

func LoadProjectConfig(workDir string) (*ProjectConfig, error)

LoadProjectConfig reads .chunk/config.json from workDir.

func (*ProjectConfig) FindCommand added in v0.7.2

func (c *ProjectConfig) FindCommand(name string) *Command

FindCommand returns the command with the given name, or nil if not found.

func (*ProjectConfig) HasCommands added in v0.7.2

func (c *ProjectConfig) HasCommands() bool

HasCommands reports whether any commands are configured.

func (*ProjectConfig) HasRemoteCommands added in v0.7.35

func (c *ProjectConfig) HasRemoteCommands() bool

HasRemoteCommands reports whether any commands are marked for remote execution.

func (*ProjectConfig) HasSidecarImage added in v0.7.85

func (c *ProjectConfig) HasSidecarImage() bool

HasSidecarImage reports whether a project-level sidecar snapshot image is configured.

func (*ProjectConfig) MarkRemoteCommandsForSidecarSetup added in v0.7.85

func (c *ProjectConfig) MarkRemoteCommandsForSidecarSetup() bool

MarkRemoteCommandsForSidecarSetup marks install and gate commands for remote execution after a successful sidecar setup. Returns true when any command was updated.

type ResolvedConfig

type ResolvedConfig struct {
	AnthropicAPIKey       string
	AnthropicAPIKeySource string
	AnthropicBaseURL      string
	CircleCIToken         string
	CircleCITokenSource   string
	CircleCIBaseURL       string
	GitHubToken           string
	GitHubTokenSource     string
	GitHubAPIURL          string
	Model                 string
	ModelSource           string
	AnalyzeModel          string
	PromptModel           string
	UseSSHIdentityFile    bool
}

ResolvedConfig holds the final resolved values with their sources.

func Resolve

func Resolve(flagAPIKey, flagModel string, _ bool) (ResolvedConfig, error)

Resolve computes the final config from flags, env, file, and keychain. Priority for API key: flag > env > config file > keychain > (none). Priority for model: flag > env > config file > default. insecureStorage affects credential writes elsewhere, but reads always use the same precedence order.

func ResolveCircleCI added in v0.7.137

func ResolveCircleCI(_ bool) (ResolvedConfig, error)

ResolveCircleCI returns only the CircleCI-related config needed by sidecar commands. It intentionally skips Anthropic and GitHub resolution so callers that only need CircleCI auth avoid unrelated keyring work.

type UserConfig

type UserConfig struct {
	AnthropicAPIKey    string `json:"anthropicAPIKey,omitempty"`
	CircleCIToken      string `json:"circleCIToken,omitempty"`
	GitHubToken        string `json:"gitHubToken,omitempty"`
	Model              string `json:"model,omitempty"`
	UseSSHIdentityFile bool   `json:"useSSHIdentityFile,omitempty"`
	InstanceID         string `json:"instanceID,omitempty"`

	// Telemetry is the persisted telemetry preference: true enables it,
	// false disables it. nil means no preference has been set, in which
	// case telemetry defaults to enabled (it is opt-out).
	Telemetry *bool `json:"telemetry,omitempty"`

	// LegacyAPIKey reads the pre-rename "apiKey" field so existing users don't
	// silently lose their stored Anthropic key on upgrade. Migrated into
	// AnthropicAPIKey by Load and dropped on the next Save (omitempty).
	LegacyAPIKey string `json:"apiKey,omitempty"`
}

UserConfig is the on-disk JSON config.

func Load

func Load() (UserConfig, error)

Load reads the config file. Returns empty config if not found.

type VCSConfig added in v0.7.2

type VCSConfig struct {
	Org  string `json:"org,omitempty"`
	Repo string `json:"repo,omitempty"`
}

VCSConfig holds VCS configuration for the project.

type ValidationConfig added in v0.7.35

type ValidationConfig struct {
	SidecarImage string `json:"sidecarImage,omitempty"`
}

ValidationConfig holds project-level defaults for validation behaviour.

Jump to

Keyboard shortcuts

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