config

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const DefaultPort = 4173

DefaultPort is the single loopback port shared by the API, WS, UI and hook receiver.

View Source
const EnvDataDir = "CAPROCK_DATA_DIR"

EnvDataDir overrides the resolved data directory when set.

Variables

This section is empty.

Functions

func ConfigPath

func ConfigPath(dir string) string

Paths inside the data dir.

func DBPath

func DBPath(dir string) string

func DataDir

func DataDir() (string, error)

DataDir resolves the data directory: $CAPROCK_DATA_DIR, else os.UserConfigDir()/caprock.

func EnsureDataDir

func EnsureDataDir() (string, error)

EnsureDataDir resolves and creates the data directory (0700).

func HookDebugLogPath

func HookDebugLogPath(dir string) string

func LogPath

func LogPath(dir string) string

func NewSessionID

func NewSessionID() string

NewSessionID returns a random RFC-4122-ish v4 UUID for `claude --session-id`.

func PricingPath

func PricingPath(dir string) string

func RemoveRuntime

func RemoveRuntime(dir string) error

RemoveRuntime deletes runtime.json; a missing file is not an error.

func RuntimePath

func RuntimePath(dir string) string

func Save

func Save(dir string, cfg Config) error

Save writes config.json atomically.

func ShimPath

func ShimPath(dir string) string

func WriteFileAtomic

func WriteFileAtomic(path string, data []byte, perm os.FileMode) error

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

func WriteRuntime(dir string, rt Runtime) error

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"`
}

Config is the user-editable configuration stored at <data_dir>/config.json. Every field has a default; a missing file means "all defaults".

func Defaults

func Defaults() Config

Defaults returns the built-in configuration (spec: K=5, T=3, port 4173).

func Load

func Load(dir string) (Config, error)

Load reads config.json, layering it over Defaults(). Unknown fields are ignored.

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

func NewRuntime(port int, version string) (Runtime, error)

NewRuntime creates a runtime record with a fresh random token.

func ReadRuntime

func ReadRuntime(dir string) (Runtime, error)

ReadRuntime loads runtime.json. os.ErrNotExist means the daemon is not running.

Jump to

Keyboard shortcuts

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