config

package
v0.78.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 11 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 is the single loopback port shared by the API, WS, UI and
	// hook receiver on a fresh install. 22776 spells CAPRO on a phone keypad,
	// is unassigned by IANA, sits below common ephemeral ranges, and avoids
	// Vite Preview's default 4173.
	DefaultPort = 22776
	// LegacyDefaultPort preserves the origin and bookmarks of an existing
	// install that never wrote config.json. A port is part of a browser origin;
	// silently moving it would also strand LAN pairing tokens in localStorage.
	LegacyDefaultPort = 4173
)
View Source
const EnvDataDir = "CAPROCK_DATA_DIR"

EnvDataDir overrides the resolved data directory when set.

Variables

This section is empty.

Functions

func ChatsDir added in v0.28.0

func ChatsDir(dir string) string

ChatsDir is where quick chats live — sessions started to ask something rather than to work on a repository.

Under the data directory rather than a second `~/.caprock`: one place that holds Caprock's state is one place to back up, clean out and explain. A chat is state, not a user's project, and it has no business being somewhere the user has to discover separately.

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 PasteDir added in v0.33.0

func PasteDir(dir string) string

PasteDir is where a file pasted or dropped into the terminal is written.

A browser hands over an image's *bytes*, never its path — there is no path to hand over for something copied from a screenshot tool. Claude Code reads files by path, so the bytes have to become a file somewhere before its path can be typed into the session.

Under the data directory for the same reason chats are: it is Caprock's state, it is one place to back up and clear out, and it is not somewhere the user has to go looking for.

func PricingPath

func PricingPath(dir string) string

func ReadDevices added in v0.49.0

func ReadDevices(dir string) ([]pairing.Device, error)

ReadDevices restores the guest list. A missing file is the normal first-run case and returns nothing rather than an error.

func RemoveDevices added in v0.49.0

func RemoveDevices(dir string) error

RemoveDevices forgets every paired device.

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 ServiceLogPath added in v0.59.6

func ServiceLogPath(dir string) string

ServiceLogPath is where launchd and systemd send the daemon's output.

func ShimPath

func ShimPath(dir string) string

func WriteDevices added in v0.49.0

func WriteDevices(dir string, ds []pairing.Device) error

WriteDevices saves the paired devices. Called after every pairing and every revocation, so a restart does not send someone walking back to their tablet.

What does *not* survive a restart is the decision to listen on the network at all: that is a run flag, so a laptop opened in a coworking space cannot carry a choice made at home. Devices are the guest list; the listener is the open door.

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"`
	// Memory decides whether a session opening a folder is told what the last
	// one left there. On by default: 79% of sessions open somewhere work
	// already happened, so it helps more often than it intrudes — and a
	// feature that acts before you type is one nobody discovers if it ships
	// off. Stored, unlike LAN access, because this is a working habit rather
	// than a door left open.
	Memory *bool `json:"memory,omitempty"`
	// MemoryHoldoutPct holds the handoff back from this share of the new
	// sessions that could have had one, so there is something to compare the
	// ones that got it against. 0 — the default — holds nothing back: nobody's
	// sessions get worse unless they asked to measure it.
	MemoryHoldoutPct int `json:"memory_holdout_pct,omitempty"`
	// 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"`

	// LicenseKey unlocks the paid features. Checked locally against its own
	// embedded expiry — no network call, no signature (ADR-022). Empty is the
	// normal state: the free product is the whole product for one person.
	LicenseKey string `json:"license_key,omitempty"`
	// CapUSDPerDay is the daily spend ceiling. Zero is off, which is the
	// default: a threshold nobody chose would eventually stop work for a
	// reason its owner could not explain. See internal/cap.
	CapUSDPerDay float64 `json:"cap_usd_per_day,omitempty"`
	// ReportBotToken and ReportChatID configure the weekly report's delivery to
	// the user's own Telegram bot.
	//
	// The token is stored here, unlike the Gemini key, and ADR-024 is where
	// that difference is argued: a bot token drives a bot the user made for
	// this, with no billing attached, while an AI Studio key spends money.
	// Putting it in the environment instead would mean editing a launchd plist
	// to turn on a feature sold as two minutes of setup. The file is 0600
	// inside a 0700 data dir, and the token is never returned over HTTP.
	ReportBotToken string `json:"report_bot_token,omitempty"`
	ReportChatID   string `json:"report_chat_id,omitempty"`
	// AlertApproval and AlertFinished switch the phone alerts sent through
	// the same bot: a session waiting for approval, a session that finished
	// (ADR-036). "Never set" means off: a bot set up for the weekly report
	// does not start sending alerts on its own. Free, unlike the weekly
	// report.
	AlertApproval *bool `json:"alert_approval,omitempty"`
	AlertFinished *bool `json:"alert_finished,omitempty"`
	// AlertReply puts the first line of the agent's final reply in a
	// finished alert. On unless switched off, like the two above; Telegram
	// reads it, which the Settings line says.
	AlertReply *bool `json:"alert_reply,omitempty"`
	// NotifyApproval and NotifyFinished switch the desktop app's OS
	// notifications (WP-09), apart from Telegram's: a notification stays on
	// the machine. Approval is on unless switched off — a blocked agent is
	// what the app exists to report; finished is off unless switched on.
	NotifyApproval *bool `json:"notify_approval,omitempty"`
	NotifyFinished *bool `json:"notify_finished,omitempty"`
	// GeminiAPIKey is the user's Google AI Studio key, entered in the dashboard.
	// GEMINI_API_KEY in the environment takes precedence when both exist, so a
	// machine already configured that way is untouched (ADR-025). Stored under
	// the same 0600/0700 posture as everything else here, and never returned
	// over HTTP.
	GeminiAPIKey string `json:"gemini_api_key,omitempty"`
	// BrowseRoot is where the folder picker may look. Empty means $HOME.
	BrowseRoot string `json:"browse_root,omitempty"`
	// Terminal is the terminal application "Open in my terminal" uses
	// ("ghostty", "iterm2", ...; internal/nativeterm). Empty means the first
	// one installed.
	Terminal string `json:"terminal,omitempty"`
	// Editor is the editor "Open in editor" uses ("vscode", "zed", ...;
	// internal/editor). Empty means the first one installed.
	Editor string `json:"editor,omitempty"`
	// GitHubSource is where the GitHub token comes from (internal/github,
	// ADR-039): "gh" (the GitHub CLI's login), "token" (pasted), "oauth"
	// (device flow), or empty — not connected, and nothing goes to GitHub.
	// The token itself is never in this file.
	GitHubSource string `json:"github_source,omitempty"`
	// GitHubClientID is a GitHub OAuth app's client id; with one, Settings
	// offers "Sign in with GitHub" (the device flow). Public, not a secret.
	GitHubClientID string `json:"github_client_id,omitempty"`
	// GitHubNotify raises an OS notification when a followed pull request's
	// CI starts failing or a review lands. On unless switched off.
	GitHubNotify *bool `json:"github_notify,omitempty"`
}

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 for a fresh install.

func Load

func Load(dir string) (Config, error)

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

func (Config) AlertApprovalOn added in v0.72.0

func (c Config) AlertApprovalOn() bool

AlertApprovalOn reports whether a session waiting for approval is sent to the phone. Off unless switched on: a bot set up for the weekly report must not start sending alerts nobody asked for (owner, 2026-10-05).

func (Config) AlertFinishedOn added in v0.72.0

func (c Config) AlertFinishedOn() bool

AlertFinishedOn reports whether a finished session is sent to the phone. Off unless switched on, like AlertApprovalOn.

func (Config) AlertReplyOn added in v0.74.0

func (c Config) AlertReplyOn() bool

AlertReplyOn reports whether a finished alert carries the first line of the final reply. On unless switched off.

func (Config) GitHubNotifyOn added in v0.78.0

func (c Config) GitHubNotifyOn() bool

GitHubNotifyOn reports whether CI and review notifications are on.

func (Config) MemoryOn added in v0.52.0

func (c Config) MemoryOn() bool

MemoryOn reports whether a session should be told what the last one left in the same folder.

A pointer in the struct so that "never set" is distinguishable from "set to false": a config written before this existed must get the feature, and a config where someone turned it off must keep it off. Reading a bare bool would have silently re-enabled it for everyone who had said no.

func (Config) NotifyApprovalOn added in v0.76.0

func (c Config) NotifyApprovalOn() bool

NotifyApprovalOn reports whether a session waiting for approval raises an OS notification in the desktop app. On unless switched off.

func (Config) NotifyFinishedOn added in v0.76.0

func (c Config) NotifyFinishedOn() bool

NotifyFinishedOn reports whether a finished session raises an OS notification. Off unless switched on.

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"`
	// APILevel is the daemon's API level (version.APILevel), so a client that
	// reads this file knows before any request whether the daemon is new
	// enough for it. Zero means a daemon from before the field existed.
	APILevel int `json:"api_level"`
	// Exe is the absolute path of the running daemon binary. The desktop app
	// uses it to tell a daemon it installed (and may update) from one a
	// package manager owns (which it must not touch). Empty when unknown.
	Exe string `json:"exe,omitempty"`
}

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