Documentation
¶
Overview ¶
SPDX-License-Identifier: MIT
SPDX-License-Identifier: MIT Package config defines the tool's settings and the flexible time-window parsing used to bound a query. Loading and source precedence (config file, environment, flags) is handled by viper in the CLI layer; this package stays dependency-light so provider clients and renderers can rely on it.
SPDX-License-Identifier: MIT
Index ¶
Constants ¶
const DefaultMaxCommits = 100
DefaultMaxCommits bounds routine queries to the providers' maximum page size. Users can still set max_commits to 0 for an exhaustive scan.
Variables ¶
This section is empty.
Functions ¶
func Defaults ¶
Defaults are the built-in configuration values, keyed by their canonical config key. The CLI seeds viper with these so they participate uniformly in precedence resolution. It is derived from Default() so the map and struct representations of the built-in configuration stay in sync.
Types ¶
type ActivityRequest ¶ added in v1.1.0
type ActivityRequest struct {
Provider string // github only; empty uses the configured default
Repo string // "owner/name"
Ref string // branch or tag; empty means the default branch
Since string // RFC3339 or YYYY-MM-DD; empty uses Window
Until string // RFC3339 or YYYY-MM-DD; empty means now
Window string // look-back (e.g. "7d"); used only when Since is empty
Author string // optional narrowing filter on the commit listing
// IncludeDiffs overrides the default when non-nil.
IncludeDiffs *bool
// MaxDiffBytes overrides the default when non-nil.
MaxDiffBytes *int
// EnrichCommits overrides the default (0) when non-nil.
EnrichCommits *int
// MaxRequests overrides the default when non-nil. An explicit 0 is
// meaningful (uncapped), which is why this is a pointer.
MaxRequests *int
// EstimateOnly reports projected cost without gathering evidence.
EstimateOnly bool
}
ActivityRequest is the raw, mostly-string repository-activity input from a CLI invocation or an MCP tool call. It mirrors the Request pattern so the CLI and MCP share exactly one validation path and cannot drift in what they accept or how they phrase a rejection.
type Config ¶
type Config struct {
// DefaultProvider is used when a query omits a provider.
DefaultProvider model.Provider `mapstructure:"provider"`
// Token is the GitHub personal access token sting authenticates with. It is
// deliberately sting's own key (config-file "token" or env STING_TOKEN), kept
// separate from the ambient GITHUB_TOKEN so a dedicated read-only PAT can be
// the default without colliding with other tools' credentials.
Token string `mapstructure:"token"`
// BaseURL points at a GitHub Enterprise API root
// ("https://ghe.example.com/api/v3/"). Empty means public github.com.
BaseURL string `mapstructure:"base_url"`
// GitLabToken is the GitLab personal access token sting authenticates with.
// It is kept separate from both GITHUB_TOKEN and ambient GitLab env vars such
// as GITLAB_TOKEN.
GitLabToken string `mapstructure:"gitlab_token"`
// GitLabBaseURL points at a GitLab API v4 root
// ("https://gitlab.example.com/api/v4/"). Empty means GitLab.com.
GitLabBaseURL string `mapstructure:"gitlab_base_url"`
// DefaultScope is used when a query omits a scope.
DefaultScope model.Scope `mapstructure:"default_scope"`
// DefaultWindow is the look-back window when a query omits since/until.
DefaultWindow string `mapstructure:"default_window"`
// DefaultRepos seeds ScopeRepos queries that omit repos.
DefaultRepos []string `mapstructure:"default_repos"`
// DefaultOrg seeds ScopeOrg queries that omit org.
DefaultOrg string `mapstructure:"default_org"`
// DefaultFormat is the CLI render format ("markdown" or "json").
DefaultFormat string `mapstructure:"default_format"`
// PerPage is the API page size (1-100).
PerPage int `mapstructure:"per_page"`
// MaxCommits caps results per query (0 = unlimited).
MaxCommits int `mapstructure:"max_commits"`
// IncludeStats fetches per-commit line stats by default.
IncludeStats bool `mapstructure:"include_stats"`
// IncludeFiles fetches per-file change summaries by default.
IncludeFiles bool `mapstructure:"include_files"`
// IncludeDiffs fetches bounded patch text by default.
IncludeDiffs bool `mapstructure:"include_diffs"`
// MaxDiffBytes caps patch text per commit when diffs are requested.
MaxDiffBytes int `mapstructure:"max_diff_bytes"`
// IncludePullRequests augments repos/org discovery with open-PR branch
// commits by default (GitHub only).
IncludePullRequests bool `mapstructure:"include_prs"`
// MaxRequests caps the provider API requests a single query may consume
// (0 = no cap). It is a fixed default rather than one derived from
// remaining quota, so the same request cannot produce different results
// depending on unrelated prior activity.
MaxRequests int `mapstructure:"max_requests"`
}
Config holds all tunable settings. The mapstructure keys are the canonical configuration keys: they are the YAML/JSON config-file keys, the viper keys bound to flags, and (uppercased, STING_-prefixed) the environment variables.
func Default ¶
func Default() Config
Default returns the built-in configuration as a Config value. This is the single source of truth for default values; Defaults() derives its map representation from it so the two cannot drift apart.
Default is intentional public API consumed by the sibling wake project (see ADR 0004) in addition to Defaults(), which is what the sting CLI itself seeds viper with.
func (Config) Resolve ¶
Resolve turns a Request into a validated model.Query, applying defaults from cfg. The reference time now is injected for testability.
func (Config) ResolveActivity ¶ added in v1.1.0
func (cfg Config) ResolveActivity(req ActivityRequest, now time.Time) (model.ActivityQuery, error)
ResolveActivity validates and normalizes an ActivityRequest into an ActivityQuery, applying flags > env > file > defaults precedence.
It is the single place the activity window is normalized — once, to UTC — and the single place a non-GitHub provider is rejected, so the failure is identical whether the request arrived from the CLI or from MCP and is impossible to reach with a half-built client behind it. The reference time now is injected for testability.
type Request ¶
type Request struct {
Provider string // github|gitlab; empty uses default
Author string
Since string // RFC3339 or YYYY-MM-DD; empty uses Window
Until string // RFC3339 or YYYY-MM-DD; empty means now
Window string // look-back (e.g. "7d"); used only when Since is empty
Scope string // search|repos|org; empty uses default
Repos []string
Org string
// IncludeStats overrides the default when non-nil.
IncludeStats *bool
// IncludeFiles overrides the default when non-nil.
IncludeFiles *bool
// IncludeDiffs overrides the default when non-nil.
IncludeDiffs *bool
// MaxDiffBytes overrides the default when non-nil.
MaxDiffBytes *int
// MaxCommits overrides the default when non-nil.
MaxCommits *int
// MaxRequests overrides the default when non-nil. An explicit 0 is
// meaningful (uncapped), which is why this is a pointer.
MaxRequests *int
// IncludePullRequests overrides the default when non-nil.
IncludePullRequests *bool
}
Request is the raw, mostly-string input from a CLI invocation or an MCP tool call. Empty fields fall back to configuration defaults during Resolve.