Documentation
¶
Overview ¶
Package config resolves Caprock's data directory and the small on-disk files that live in it: config.json (user settings) and runtime.json (per-run port + token, read by the hook shim). See .ai/03-contracts.md and ADR-013.
Index ¶
- Constants
- func ConfigPath(dir string) string
- func DBPath(dir string) string
- func DataDir() (string, error)
- func EnsureDataDir() (string, error)
- func HookDebugLogPath(dir string) string
- func LogPath(dir string) string
- func NewSessionID() string
- func PricingPath(dir string) string
- func RemoveRuntime(dir string) error
- func RuntimePath(dir string) string
- func Save(dir string, cfg Config) error
- func ShimPath(dir string) string
- func WriteFileAtomic(path string, data []byte, perm os.FileMode) error
- func WriteRuntime(dir string, rt Runtime) error
- type Config
- type Runtime
Constants ¶
const DefaultPort = 4173
DefaultPort is the single loopback port shared by the API, WS, UI and hook receiver.
const EnvDataDir = "CAPROCK_DATA_DIR"
EnvDataDir overrides the resolved data directory when set.
Variables ¶
This section is empty.
Functions ¶
func DataDir ¶
DataDir resolves the data directory: $CAPROCK_DATA_DIR, else os.UserConfigDir()/caprock.
func EnsureDataDir ¶
EnsureDataDir resolves and creates the data directory (0700).
func HookDebugLogPath ¶
func NewSessionID ¶
func NewSessionID() string
NewSessionID returns a random RFC-4122-ish v4 UUID for `claude --session-id`.
func PricingPath ¶
func RemoveRuntime ¶
RemoveRuntime deletes runtime.json; a missing file is not an error.
func RuntimePath ¶
func WriteFileAtomic ¶
WriteFileAtomic writes to a temp file in the same directory and renames it into place, so readers never observe a partial file (the shim reads runtime.json while the daemon may be rewriting it).
func WriteRuntime ¶
WriteRuntime persists runtime.json with 0600 permissions, atomically.
Types ¶
type Config ¶
type Config struct {
Port int `json:"port"`
// Loop detector: >= K same-tool similar-input tool.pre events within T minutes.
LoopK int `json:"loop_k"`
LoopTMinutes int `json:"loop_t_minutes"`
// AutoPause applies to owned sessions only (Phase 1). Default off.
AutoPause bool `json:"auto_pause"`
// OpenBrowser controls whether `caprock up` opens the dashboard.
OpenBrowser bool `json:"open_browser"`
// RetentionDays prunes events older than this many days (0 = keep forever).
// The database grows ~1 KB per event; set this if you run Caprock constantly.
RetentionDays int `json:"retention_days"`
// Billing describes how the user actually pays for Claude Code, so the
// dashboard can say something true about what their usage is worth.
//
// Caprock cannot detect this and never guesses: Claude Code does not report
// the plan, and inferring one from usage would be an invented number
// (engineering rule 6). The user states it; we store it locally.
//
// PlanKind is one of:
// "" not stated — no comparison is shown
// "flat" a flat subscription (Pro/Max/Team seat): usage priced at
// API list is an equivalent, and comparing it to the fee is
// meaningful
// "metered" API key, Bedrock, Vertex, or Enterprise usage billed at
// API rates: the API-list figure IS approximately the bill,
// so it must never be framed as a saving
// PlanLabel is the user's own words for the plan ("Max", "Team seat").
// PlanUSDPerMonth is what they pay per month for one seat; 0 = not stated.
// UpdateChecks enables the one outbound call Caprock makes: asking GitHub
// for the latest release tag. Off by default and asked for once — see
// internal/update for why this is opt-in and why Caprock never installs
// the update itself.
UpdateChecks bool `json:"update_checks"`
PlanKind string `json:"plan_kind"`
PlanLabel string `json:"plan_label"`
PlanUSDPerMonth float64 `json:"plan_usd_per_month"`
}
Config is the user-editable configuration stored at <data_dir>/config.json. Every field has a default; a missing file means "all defaults".
type Runtime ¶
type Runtime struct {
Port int `json:"port"`
Token string `json:"token"`
PID int `json:"pid"`
StartedAt int64 `json:"started_at"` // unix ms
Version string `json:"version"`
}
Runtime is <data_dir>/runtime.json — written by the daemon on start, read by the shim on every invocation, removed on clean shutdown.
func NewRuntime ¶
NewRuntime creates a runtime record with a fresh random token.
func ReadRuntime ¶
ReadRuntime loads runtime.json. os.ErrNotExist means the daemon is not running.