settings

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package settings provides configuration loading for Trace. This package is separate from cli to allow strategy package to import it without creating an import cycle (cli imports strategy).

Index

Constants

View Source
const (
	// TraceSettingsFile is the path to the Trace settings file
	TraceSettingsFile = ".trace/settings.json"
	// TraceSettingsLocalFile is the path to the local settings override file (not committed)
	TraceSettingsLocalFile = ".trace/settings.local.json"
	// ClonePreferencesFile is the path inside the git common dir for clone-local preferences
	// (review migration state, etc.). Adapted from upstream "trace/preferences.json".
	ClonePreferencesFile = "trace/preferences.json"
)
View Source
const (
	// CommitLinkingAlways auto-links commits to sessions without prompting.
	CommitLinkingAlways = "always"
	// CommitLinkingPrompt prompts the user on each commit (default for existing users).
	CommitLinkingPrompt = "prompt"
)

Commit linking mode constants.

Variables

This section is empty.

Functions

func CheckpointsVersion

func CheckpointsVersion(ctx context.Context) int

CheckpointsVersion returns the configured checkpoints format version, or 1 if settings cannot be loaded or the value is unset/invalid.

func ClonePreferencesPath

func ClonePreferencesPath(ctx context.Context) (string, error)

ClonePreferencesPath returns the path to trace/preferences.json inside the git common dir.

func IsCheckpointsV2Enabled

func IsCheckpointsV2Enabled(ctx context.Context) bool

IsCheckpointsV2Enabled checks if checkpoints v2 is enabled in settings. Returns false by default if settings cannot be loaded or the key is missing.

func IsExternalAgentsEnabled

func IsExternalAgentsEnabled(ctx context.Context) bool

IsExternalAgentsEnabled checks if external agent discovery is enabled in settings. Returns false by default if settings cannot be loaded or the key is missing.

func IsFilteredFetchesEnabled

func IsFilteredFetchesEnabled(ctx context.Context) bool

IsFilteredFetchesEnabled checks if filtered fetches should be used. When enabled, filtered fetches always resolve remote names to URLs first so git does not persist promisor settings onto named remotes in local config. Returns false by default.

func IsPushV2RefsEnabled

func IsPushV2RefsEnabled(ctx context.Context) bool

IsPushV2RefsEnabled checks if pushing v2 refs is enabled in settings. Returns false by default if settings cannot be loaded or flags are missing.

func IsSetUp

func IsSetUp(ctx context.Context) bool

IsSetUp returns true if Trace has been set up in the current repository. This checks if .trace/settings.json exists. Use this to avoid creating files/directories in repos where Trace was never enabled.

func IsSetUpAndEnabled

func IsSetUpAndEnabled(ctx context.Context) bool

IsSetUpAndEnabled returns true if Trace is both set up and enabled. This checks if .trace/settings.json exists AND has enabled: true. Use this for hooks that should be no-ops when Trace is not active.

func IsSetUpAny

func IsSetUpAny(ctx context.Context) bool

IsSetUpAny returns true if Trace has been set up in the current repository, checking both .trace/settings.json and .trace/settings.local.json. Use this to detect any prior setup, even if only local settings exist.

func IsSignCheckpointCommitsEnabled

func IsSignCheckpointCommitsEnabled(ctx context.Context) bool

IsSignCheckpointCommitsEnabled checks if checkpoint commit signing is enabled in settings. Returns true by default if settings cannot be loaded or the key is missing.

func IsSummarizeEnabled

func IsSummarizeEnabled(ctx context.Context) bool

IsSummarizeEnabled checks if auto-summarize is enabled in settings. Returns false by default if settings cannot be loaded or the key is missing.

func LoadLocalRaw

func LoadLocalRaw(ctx context.Context) (path string, raw map[string]json.RawMessage, exists bool, err error)

LoadLocalRaw reads .trace/settings.local.json as a generic JSON object.

func LoadProjectRaw

func LoadProjectRaw(ctx context.Context) (path string, raw map[string]json.RawMessage, exists bool, err error)

LoadProjectRaw reads .trace/settings.json as a generic JSON object. Used by review migration to move keys without loading the full typed struct.

func Save

func Save(ctx context.Context, settings *TraceSettings) error

Save saves the settings to .trace/settings.json.

func SaveClonePreferences

func SaveClonePreferences(ctx context.Context, prefs *ClonePreferences) error

SaveClonePreferences saves clone-local preferences to the git common dir.

func SaveLocal

func SaveLocal(ctx context.Context, settings *TraceSettings) error

SaveLocal saves the settings to .trace/settings.local.json.

func SaveProjectRaw

func SaveProjectRaw(path string, raw map[string]json.RawMessage) error

SaveProjectRaw writes a generic JSON object back to .trace/settings.json atomically.

Types

type CheckpointRemoteConfig

type CheckpointRemoteConfig struct {
	Provider string // e.g., "github"
	Repo     string // e.g., "org/checkpoints-repo"
}

CheckpointRemoteConfig holds the structured checkpoint remote configuration. Stored in strategy_options.checkpoint_remote as {"provider": "github", "repo": "org/repo"}.

func (*CheckpointRemoteConfig) Owner

func (c *CheckpointRemoteConfig) Owner() string

Owner returns the owner portion of the repo field (before the slash). Returns empty string if the repo field doesn't contain a slash.

type ClonePreferences

type ClonePreferences struct {
	Review         map[string]ReviewConfig `json:"review,omitempty"`
	ReviewFixAgent string                  `json:"review_fix_agent,omitempty"`

	// ReviewMigrationDismissed records that the user declined the one-shot
	// migration of review keys from project settings to clone-local prefs.
	// Once true, `trace review` stops prompting on every invocation.
	ReviewMigrationDismissed bool `json:"review_migration_dismissed,omitempty"`
}

ClonePreferences holds per-clone (non-committed) preferences, primarily for the review feature (e.g. which agent to use for review fixes, migration dismissal state).

func LoadClonePreferences

func LoadClonePreferences(ctx context.Context) (*ClonePreferences, error)

LoadClonePreferences loads clone-local preferences from the git common dir.

type InvestigateConfig

type InvestigateConfig struct {
	// Agents is the ordered list of agent names to round-robin during the loop.
	Agents []string `json:"agents,omitempty"`

	// MaxTurns is the per-agent turn budget. Defaults to 2 when zero
	// (see investigate.defaultMaxTurns).
	MaxTurns int `json:"max_turns,omitempty"`

	// Quorum is the count of `approve` stances needed to terminate the loop.
	// Zero means "all agents must approve" (matches marvin's default).
	Quorum int `json:"quorum,omitempty"`

	// AlwaysPrompt is appended to every turn's composed prompt, parallel
	// to ReviewConfig.Prompt.
	AlwaysPrompt string `json:"always_prompt,omitempty"`
}

InvestigateConfig holds the configuration for `trace investigate`. Unlike ReviewConfig, investigate runs the same shared prompt across all configured agents, so the schema is a flat agent list with global loop knobs rather than per-agent skill lists.

func (*InvestigateConfig) IsZero

func (c *InvestigateConfig) IsZero() bool

IsZero reports whether the config is effectively unset.

type PIISettings

type PIISettings struct {
	Enabled        bool              `json:"enabled"`
	Email          *bool             `json:"email,omitempty"`
	Phone          *bool             `json:"phone,omitempty"`
	Address        *bool             `json:"address,omitempty"`
	CustomPatterns map[string]string `json:"custom_patterns,omitempty"`
}

PIISettings configures PII detection categories. When Enabled is true, email and phone default to true; address defaults to false.

type RedactionSettings

type RedactionSettings struct {
	PII *PIISettings `json:"pii,omitempty"`
}

RedactionSettings configures redaction behavior beyond the default secret detection.

type ReviewConfig

type ReviewConfig struct {
	// Skills is the list of slash-prefixed skill invocations configured
	// for this agent. May be empty when Prompt carries the full request.
	Skills []string `json:"skills,omitempty"`

	// Prompt, when non-empty, carries saved review instructions. When
	// Skills is non-empty it is appended after the selected skills; when
	// Skills is empty it is the full prompt for prompt-only review configs.
	Prompt string `json:"prompt,omitempty"`
}

ReviewConfig holds the per-agent review configuration. Both fields are optional; together they describe what `trace review` should ask the agent to do.

Precedence when composing the review prompt sent to the agent:

  • If Prompt is non-empty, it is used verbatim.
  • Otherwise, Skills are composed into a default template ("Please run these review skills in order: 1. /X 2. /Y").

Skills are always recorded on the checkpoint metadata regardless of which path composed the prompt — they're the structured, queryable tag alongside ReviewPrompt (which is the ground truth).

func (ReviewConfig) IsZero

func (c ReviewConfig) IsZero() bool

IsZero reports whether the config is effectively unset.

type SummaryGenerationSettings

type SummaryGenerationSettings struct {
	// Provider is the selected summary provider agent name
	// (for example "claude-code", "codex", or "gemini").
	Provider string `json:"provider,omitempty"`

	// Model is an optional model hint passed to the selected provider.
	Model string `json:"model,omitempty"`
}

SummaryGenerationSettings configures provider selection for on-demand checkpoint summaries generated by explain --generate.

func (*SummaryGenerationSettings) SetProvider

func (s *SummaryGenerationSettings) SetProvider(newProvider, newModel string)

SetProvider updates the provider and optionally the model, clearing any stale model from the previous provider when switching without a replacement. An empty newProvider preserves the current provider; an empty newModel preserves the current model unless the provider is changing, in which case the old model is cleared to avoid passing (say) a Claude model to Codex.

func (*SummaryGenerationSettings) Validate

func (s *SummaryGenerationSettings) Validate() error

Validate returns an error if the settings combination is semantically invalid. A model without a provider is meaningless: the model hint needs a provider to route to. The load path calls Validate() after merging, catching hand-edited files that land in this state.

type TraceSettings

type TraceSettings struct {
	// Enabled indicates whether Trace is active. When false, CLI commands
	// show a disabled message and hooks exit silently. Defaults to true.
	Enabled bool `json:"enabled"`

	// LocalDev indicates whether to use "go run" instead of the "trace" binary
	// This is used for development when the binary is not installed
	LocalDev bool `json:"local_dev,omitempty"`

	// LogLevel sets the logging verbosity (debug, info, warn, error).
	// Can be overridden by TRACE_LOG_LEVEL environment variable.
	// Defaults to "info".
	LogLevel string `json:"log_level,omitempty"`

	// StrategyOptions contains strategy-specific configuration
	StrategyOptions map[string]any `json:"strategy_options,omitempty"`

	// AbsoluteGitHookPath embeds the full binary path in git hooks instead of
	// bare "trace". This is needed for GUI git clients (Xcode, Tower, etc.)
	// that don't source shell profiles and can't find "trace" on PATH.
	AbsoluteGitHookPath bool `json:"absolute_git_hook_path,omitempty"`

	// Telemetry controls anonymous usage analytics.
	// nil = not asked yet (show prompt), true = opted in, false = opted out
	Telemetry *bool `json:"telemetry,omitempty"`

	// Redaction configures PII redaction behavior for transcripts and metadata.
	Redaction *RedactionSettings `json:"redaction,omitempty"`

	// Review maps agent name (e.g. "claude-code") to the review config for
	// that agent. When empty, `trace review` triggers the first-run picker.
	Review map[string]ReviewConfig `json:"review,omitempty"`

	// ReviewFixAgent is the default agent used when applying aggregate or
	// multi-agent review findings with `trace review --fix`.
	ReviewFixAgent string `json:"review_fix_agent,omitempty"`

	// CommitLinking controls how commits are linked to agent sessions.
	// "always" = auto-link without prompting, "prompt" = ask on each commit.
	// Defaults to "prompt" (preserves existing user behavior).
	CommitLinking string `json:"commit_linking,omitempty"`

	// ExternalAgents enables discovery and registration of external agent
	// plugins (trace-agent-* binaries on $PATH). Defaults to false.
	ExternalAgents bool `json:"external_agents,omitempty"`

	// SummaryGeneration stores provider preferences for explain --generate.
	// This is separate from strategy_options.summarize, which controls
	// checkpoint auto-summarize behavior.
	SummaryGeneration *SummaryGenerationSettings `json:"summary_generation,omitempty"`

	// Vercel indicates that the repository uses Vercel and the metadata branch
	// should include a vercel.json that disables deployments for Trace branches.
	Vercel bool `json:"vercel,omitempty"`

	// SummaryTimeoutSeconds is an optional hard deadline (in seconds) for
	// `trace explain --generate` summary generation. Zero or negative means
	// "unset" -- the caller picks the default. Not yet consumed by the
	// generate path; present so settings round-trip for a follow-up change
	// that wires it into the deadline selection.
	SummaryTimeoutSeconds int `json:"summary_timeout_seconds,omitempty"`

	// SignCheckpointCommits controls whether checkpoint commits are signed.
	// nil/true = sign (default), false = skip signing.
	SignCheckpointCommits *bool `json:"sign_checkpoint_commits,omitempty"`

	// Investigate holds configuration for `trace investigate`. Empty means
	// `trace investigate` triggers the first-run picker.
	Investigate *InvestigateConfig `json:"investigate,omitempty"`

	// Deprecated: no longer used. Exists to tolerate old settings files
	// that still contain "strategy": "auto-commit" or similar.
	Strategy string `json:"strategy,omitempty"`
}

TraceSettings represents the .trace/settings.json configuration

func Load

func Load(ctx context.Context) (*TraceSettings, error)

Load loads the Trace settings from .trace/settings.json, then applies any overrides from .trace/settings.local.json if it exists. Returns default settings if neither file exists. Works correctly from any subdirectory within the repository.

func LoadFromBytes

func LoadFromBytes(data []byte) (*TraceSettings, error)

LoadFromBytes parses settings from raw JSON bytes without merging local overrides. Use this when you have settings content from a non-file source (e.g., git show).

func LoadFromFile

func LoadFromFile(filePath string) (*TraceSettings, error)

LoadFromFile loads settings from a specific file path without merging local overrides. Returns default settings if the file doesn't exist. Use this when you need to display individual settings files separately.

func (*TraceSettings) CheckpointsVersion

func (s *TraceSettings) CheckpointsVersion() int

CheckpointsVersion returns the configured checkpoints format version from strategy_options.checkpoints_version. Returns 1 when unset, invalid, or unsupported. The currently supported versions are 1 and 2.

func (*TraceSettings) GetCheckpointRemote

func (s *TraceSettings) GetCheckpointRemote() *CheckpointRemoteConfig

GetCheckpointRemote returns the configured checkpoint remote. Expects a structured object: {"provider": "github", "repo": "org/repo"}. Returns nil if not configured, wrong type, or missing required fields.

func (*TraceSettings) GetCommitLinking

func (s *TraceSettings) GetCommitLinking() string

GetCommitLinking returns the effective commit linking mode. Returns the explicit value if set, otherwise defaults to "prompt" to preserve existing user behavior.

func (*TraceSettings) GetFullTranscriptGenerationRetentionDays

func (s *TraceSettings) GetFullTranscriptGenerationRetentionDays() int

GetFullTranscriptGenerationRetentionDays returns the retention window for archived checkpoints v2 /full/* generations. Invalid, missing, or non-positive values fall back to the documented default.

func (*TraceSettings) InvestigateConfigMethod

func (s *TraceSettings) InvestigateConfigMethod() *InvestigateConfig

InvestigateConfig returns the configured investigate config. Returns nil when no configuration is present; callers should check IsZero (or guard for nil) to decide whether configuration is present.

func (*TraceSettings) IsCheckpointsV2Enabled

func (s *TraceSettings) IsCheckpointsV2Enabled() bool

IsCheckpointsV2Enabled checks if checkpoints v2 is enabled. Returns true when either checkpoints_v2 is set or checkpoints_version is 2.

func (*TraceSettings) IsFilteredFetchesEnabled

func (s *TraceSettings) IsFilteredFetchesEnabled() bool

IsFilteredFetchesEnabled checks if fetches should use --filter=blob:none. When enabled, filtered fetches always use resolved URLs rather than remote names to avoid persisting promisor settings onto named remotes.

func (*TraceSettings) IsPushSessionsDisabled

func (s *TraceSettings) IsPushSessionsDisabled() bool

IsPushSessionsDisabled checks if push_sessions is disabled in settings. Returns true if push_sessions is explicitly set to false.

func (*TraceSettings) IsPushV2RefsEnabled

func (s *TraceSettings) IsPushV2RefsEnabled() bool

IsPushV2RefsEnabled checks if pushing v2 refs is enabled. checkpoints_version: 2 forces v2 ref pushes on, regardless of push_v2_refs.

func (*TraceSettings) IsSignCheckpointCommitsEnabled

func (s *TraceSettings) IsSignCheckpointCommitsEnabled() bool

IsSignCheckpointCommitsEnabled returns true if checkpoint commits should be signed. Defaults to true when the setting is not explicitly set.

func (*TraceSettings) IsSummarizeEnabled

func (s *TraceSettings) IsSummarizeEnabled() bool

IsSummarizeEnabled checks if auto-summarize is enabled in this settings instance.

func (*TraceSettings) ReviewConfigFor

func (s *TraceSettings) ReviewConfigFor(agentName string) ReviewConfig

ReviewConfigFor returns the configured review config for the given agent. Returns a zero-value config when the agent has no entry; callers should check IsZero (or the individual fields) to decide whether configuration is present.

func (*TraceSettings) SummaryTimeoutValue

func (s *TraceSettings) SummaryTimeoutValue() time.Duration

SummaryTimeoutValue returns the configured hard deadline for `trace explain --generate` summary generation. Zero means "unset" -- the caller picks the default. Negative values are treated as unset.

Jump to

Keyboard shortcuts

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