Documentation
¶
Index ¶
- Constants
- Variables
- func AppData() (string, error)
- func AppState() (string, error)
- func Clear(key string) error
- func Dir() (string, error)
- func EnsureInstanceID() (uuid.UUID, error)
- func IsTelemetry(cfg UserConfig) bool
- func MaskKey(key string) string
- func Path() (string, error)
- func ProjectDataDir(projectRoot string) (string, error)
- func ResolveOrgID(workDir string) (value, source string)
- func Save(cfg UserConfig) error
- func SaveCommand(workDir, name, command string) error
- func SaveProjectConfig(workDir string, cfg *ProjectConfig) error
- type Command
- type EnvVars
- type ProjectConfig
- type ResolvedConfig
- type TaskConfig
- type UserConfig
- type VCSConfig
- type ValidationConfig
Constants ¶
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.
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.
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.
const ( RoleGate = "gate" // enforce at Stop, run-and-record at PreToolUse RolePrecheck = "precheck" // check at PreToolUse, enforce at Stop (changed-file variants) RoleAutofix = "autofix" // run at PreToolUse, enforce at Stop (formatters) )
Command roles determine hook placement in settings.json.
Variables ¶
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.
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 EnsureInstanceID ¶ added in v0.7.117
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 ProjectDataDir ¶ added in v0.7.38
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
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
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"`
FileExt string `json:"fileExt,omitempty"`
Timeout int `json:"timeout,omitempty"`
Limit int `json:"limit,omitempty"`
Always bool `json:"always,omitempty"`
Staged bool `json:"staged,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.
type ProjectConfig ¶ added in v0.7.2
type ProjectConfig struct {
Commands []Command `json:"commands,omitempty"`
Triggers map[string][]string `json:"triggers,omitempty"`
Tasks map[string]TaskConfig `json:"tasks,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 TaskConfig ¶ added in v0.7.2
type TaskConfig struct {
Instructions string `json:"instructions,omitempty"`
Schema string `json:"schema,omitempty"`
Limit int `json:"limit,omitempty"`
Always bool `json:"always,omitempty"`
Timeout int `json:"timeout,omitempty"`
}
TaskConfig holds task delegation configuration.
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 ValidationConfig ¶ added in v0.7.35
type ValidationConfig struct {
SidecarImage string `json:"sidecarImage,omitempty"`
}
ValidationConfig holds project-level defaults for validation behaviour.