config

package
v0.193.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 14 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 (
	AppUpdateAsk  = "ask"
	AppUpdateAuto = "auto"
)

The desktop app's update modes (config.json "app_update").

View Source
const (
	StatuslineFull  = "full"
	StatuslineShort = "short"
	// StatuslineHidden keeps Caprock's entry registered and its plan-window
	// relay running, and prints nothing: Claude Code then draws no status
	// line row (.ai/03-contracts.md § Statusline).
	StatuslineHidden = "hidden"
	StatuslineOff    = "off"
)

The status line modes (config.json "statusline_mode").

View Source
const (
	EndIdle2h    = "2h"
	EndIdle12h   = "12h"
	EndIdle24h   = "24h"
	EndIdleNever = "never"
)

The idle-end choices (config.json "end_idle_after").

View Source
const (
	LimitAsk  = "ask"
	LimitAuto = "auto"
	LimitWait = "wait"
)

The choices for Config.LimitAction.

View Source
const (
	QuickRepliesMax  = 10
	QuickLabelMax    = 24  // runes
	QuickTextMaxByte = 300 // bytes
)

The bounds of the list: a row of chips, not a prompt library — saved prompts (ADR-051) are that.

View Source
const (
	UpgradingBeat  = 2 * time.Second
	UpgradingStale = 10 * time.Second
)

The daemon touches upgrading.json every UpgradingBeat while it upgrades; a file older than UpgradingStale was left by one that died.

View Source
const EnvDataDir = "CAPROCK_DATA_DIR"

EnvDataDir overrides the resolved data directory when set.

Variables

View Source
var AppUpdateModes = []string{AppUpdateAsk, AppUpdateAuto}

AppUpdateModes lists the accepted values of AppUpdate.

View Source
var DefaultQuickReplies = []QuickReply{
	{Label: "Continue", Text: "Continue."},
	{Label: "Shorter", Text: "Shorter, please: say it in fewer words."},
	{Label: "Explain", Text: "Explain what you just did and why."},
	{Label: "Run tests", Text: "Run the tests and fix what fails."},
	{Label: "Commit", Text: "Commit the changes with a clear message."},
}

DefaultQuickReplies are the replies a new install has (owner, 2026-10-15: "Continue", "Shorter" and the like). Short on purpose.

EndIdleModes are the idle windows Settings offers, in its order.

StatuslineModes lists the accepted values of StatuslineMode.

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 CurrentPlanLabel added in v0.171.0

func CurrentPlanLabel(kind, label string, usd float64) string

CurrentPlanLabel is label under the plan's current name when it is exactly what an old preset of Caprock's picker wrote — that name, flat, at that price — and label unchanged otherwise. A name the user typed is their own words and is never rewritten.

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 EndIdleWindow added in v0.143.0

func EndIdleWindow(v string) time.Duration

EndIdleWindow is how long a session may sit idle under choice v; 0 for "never".

func EnsureDataDir

func EnsureDataDir() (string, error)

EnsureDataDir resolves and creates the data directory (0700).

func HookDebugLogPath

func HookDebugLogPath(dir string) string

func InboxDir added in v0.115.0

func InboxDir(dir string) string

InboxDir is where the Inbox keeps the photos and files saved with an item (03-contracts.md § Inbox): `inbox/<stamp>-<random>/<name>`, one directory per file. Apart from paste/ because it is kept until its item is deleted, while a pasted file goes after 30 days.

func LogPath

func LogPath(dir string) string

func MarkUpgrading added in v0.161.0

func MarkUpgrading(dir string) (done func())

MarkUpgrading writes upgrading.json and keeps it fresh until done is called, which removes it.

func NewSessionID

func NewSessionID() string

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

func NormalizeAppUpdate added in v0.120.0

func NormalizeAppUpdate(v string) string

NormalizeAppUpdate is the effective mode: anything unknown or unset is "ask", what every install did before the choice existed.

func NormalizeEndIdle added in v0.143.0

func NormalizeEndIdle(v string) string

NormalizeEndIdle is the effective choice: anything unknown or unset is "12h" (owner, 2026-10-21).

func NormalizeLimitAction added in v0.171.0

func NormalizeLimitAction(v string) string

NormalizeLimitAction is v when it is one of the choices, else "ask".

func NormalizeStatusline added in v0.112.2

func NormalizeStatusline(v string) string

NormalizeStatusline is the effective mode: anything unknown or unset is "full", the line everyone had before the setting existed.

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 ReadStatuslineMode added in v0.112.2

func ReadStatuslineMode(dir string) string

ReadStatuslineMode is the status line command's read of its one setting, made on every render: a small file read and a decode of a single field. Every failure — no data dir, no config.json, a file that does not parse — is "full", so the line a session sees never depends on this succeeding.

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 StatuslineRegistered added in v0.114.0

func StatuslineRegistered(v string) bool

StatuslineRegistered reports whether Caprock's statusLine entry belongs in Claude Code's settings under mode v: every mode but Off. Hidden keeps it — the entry is what relays the plan windows, even when it prints nothing.

func UpgradingPath added in v0.161.0

func UpgradingPath(dir string) string

UpgradingPath is <data_dir>/upgrading.json: there while the daemon upgrades its database, before it listens (03-contracts.md § Runtime file).

func ValidAppUpdate added in v0.120.0

func ValidAppUpdate(v string) bool

ValidAppUpdate reports whether v is one of AppUpdateModes.

func ValidEndIdle added in v0.143.0

func ValidEndIdle(v string) bool

ValidEndIdle reports whether v is one of EndIdleModes.

func ValidStatuslineMode added in v0.112.2

func ValidStatuslineMode(v string) bool

ValidStatuslineMode reports whether v is one of StatuslineModes.

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 BrainConfig added in v0.117.2

type BrainConfig struct {
	// Auto is whether finished sessions are read into the brain. nil until
	// the user answers; it never runs before a yes, because each read sends
	// a session's prose through the user's own claude login.
	Auto *bool `json:"auto,omitempty"`
	// Since is when Auto was last turned on, unix ms: sessions active before
	// it are read only through a backfill.
	Since int64 `json:"since,omitempty"`
	// BackfillSince, unix ms, widens what is read back to then (the "Build
	// from my last 30 days" button). 0 is no backfill.
	BackfillSince int64 `json:"backfill_since,omitempty"`
	// DailyTokens caps what the extraction spends in a rolling day, input and
	// output as claude reports them. 0 is the default (brain.DefaultDailyTokens).
	DailyTokens int `json:"daily_tokens,omitempty"`
	// Model is passed to claude --model; "" is brain.DefaultModel.
	Model string `json:"model,omitempty"`
	// Reader is the agent the reads go through (ADR-103): "" or "auto" picks
	// one by itself, else claude, codex, cursor or gemini.
	Reader string `json:"reader,omitempty"`
	// Models is the model per reader other than claude (whose is Model);
	// a reader missing here uses its CLI's own default.
	Models map[string]string `json:"models,omitempty"`
	// DailyReads caps the calls in a rolling day whose agent reports no
	// tokens (Cursor). 0 is the default (brain.DefaultDailyReads).
	DailyReads int `json:"daily_reads,omitempty"`
	// Exclude is the folders whose sessions Second Brain never reads
	// (absolute, in the store's path form): a session whose working
	// directory or repository root is one of them or under it is skipped,
	// and their projects are left out of the handoff, search and the graph
	// unless opened by name. Empty by default.
	Exclude []string `json:"exclude,omitempty"`
}

BrainConfig is Second Brain's automatic extraction (ADR-063).

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"`
	// LANKeepOn turns phone access (LAN access) back on when the daemon
	// starts, as if `caprock up --lan` had been given. Off unless the user
	// ticks *Keep on after Caprock restarts* (ADR-060, amending ADR-029):
	// only paired devices get in either way, so what it keeps open is the
	// pairing page on a named address, not the data. Turning phone access off
	// clears it.
	LANKeepOn bool `json:"lan_keep_on,omitempty"`
	// Brain is Second Brain's automatic extraction (ADR-063): whether it
	// runs, how much of the user's own claude it may spend a day, and how far
	// back it reads. Empty until the user answers the offer to turn it on.
	Brain BrainConfig `json:"brain,omitzero"`
	// 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"`
	// CompressToolOutput stores tool calls and their results older than a
	// day zstd-compressed, done while idle (ADR-093). Off unless turned on;
	// turning it off restores the rows while idle.
	CompressToolOutput *bool `json:"compress_tool_output,omitempty"`
	// 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"`
	// AdminKey is a signed CRA1 key naming the private modules this machine
	// may install and open (ADR-076, internal/modules). Separate from the
	// licence: neither grants the other. Empty is the ordinary state.
	AdminKey string `json:"admin_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"`
	// WindowStopPct is the share of a Claude plan window (five-hour or
	// weekly) at which Premium pauses the Claude Code sessions Caprock started,
	// until the window resets. Off until chosen, like the daily cap: a pause
	// nobody asked for would stop work for a reason its owner could not
	// explain. 0 or nil is off. See internal/cap/window.go.
	WindowStopPct *int `json:"window_stop_pct,omitempty"`
	// ReportBotToken and ReportChatID configure the weekly report's delivery to
	// the user's own Telegram bot.
	//
	// The token is never written here (ADR-024 as amended): it lives in the
	// macOS login keychain, or a 0600 file in the data directory where there
	// is none (internal/secret). The field is the daemon's in-memory copy, read
	// from that store at start; ReportBotStored records that one is kept, so a
	// daemon that never stored one never asks the Keychain.
	// LegacyReportBotToken is what releases before the move wrote to
	// config.json: read once at start, moved to the store, then removed.
	ReportBotToken       string `json:"-"`
	ReportBotStored      bool   `json:"report_bot_stored,omitempty"`
	LegacyReportBotToken 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"`
	// AlertDone sends a turn that asked nothing (Done, § Needs you and Done)
	// as a finished alert, like a turn that asked something. On unless
	// switched off: a "Finished" message is how the owner hears work is over
	// while away (owner, 2026-10-21). The desktop app never shows one.
	AlertDone *bool `json:"alert_done,omitempty"`
	// TelegramChat lets the paired Telegram chat talk back (ADR-047): a reply
	// types into a session Caprock started, /sessions, /new and /stop work,
	// and Approve and Deny appear under a question. Premium, and off until
	// switched on even with a licence: it is control from outside the
	// machine. TelegramCode sends a reply's code blocks to that chat instead
	// of a one-line note; off unless switched on.
	TelegramChat *bool `json:"telegram_chat,omitempty"`
	TelegramCode *bool `json:"telegram_code,omitempty"`
	// MorningSummary sends one Telegram message each morning through the
	// same bot (ADR-092): important mail by sender and subject, the sessions
	// that finished per project, and what waits for the owner. Off unless
	// switched on. MorningSummaryAt is when, local "HH:MM"; empty is 08:00.
	MorningSummary   *bool  `json:"morning_summary,omitempty"`
	MorningSummaryAt string `json:"morning_summary_at,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, and since 2026-10-21 it covers every
	// "Needs you" (NotifyApprovalOn). NotifyFinished no longer decides
	// anything: a Done turn raises no OS notification (NotifyFinishedOn).
	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"`
	// DeepSeekAPIKey is the user's DeepSeek platform key, entered in Settings →
	// Subscriptions. Set, it offers "DeepSeek" beside the Claude Code sign-ins:
	// a session started on it gets the key in its own environment as
	// ANTHROPIC_AUTH_TOKEN and talks to DeepSeek's Anthropic-compatible API
	// (internal/agents/provider.go). Caprock itself sends nothing with it.
	//
	// Never written here: it lives where the GitHub token does — the macOS
	// login keychain, or a 0600 file in the data directory (internal/secret) —
	// and is read from there when a session starts. The field is the daemon's
	// in-memory copy; DeepSeekKeyStored records that one is kept. Never
	// returned over HTTP (only whether one is set and a masked hint), never
	// logged; clearing it deletes it from the store. LegacyDeepSeekAPIKey is
	// what releases before the move wrote to config.json: read once at start,
	// moved to the store, then removed.
	DeepSeekAPIKey       string `json:"-"`
	DeepSeekKeyStored    bool   `json:"deepseek_key_stored,omitempty"`
	LegacyDeepSeekAPIKey string `json:"deepseek_api_key,omitempty"`
	// KimiAPIKey is the user's Kimi platform key, kept exactly as the
	// DeepSeek key is (never in this file; KimiKeyStored records that the
	// secret store holds one). Set, it offers "Kimi" beside the Claude Code
	// sign-ins (internal/agents/provider.go).
	KimiAPIKey    string `json:"-"`
	KimiKeyStored bool   `json:"kimi_key_stored,omitempty"`
	// LimitAction is what Caprock does when a Claude Code session it started
	// hits its plan's usage limit (ADR-090): "ask" (the default; the session
	// shows the limit and the choices), "auto" (continue it on the first of
	// LimitFallbacks that is available), or "wait" (leave it until the
	// window resets). LimitFallbacks is the order "auto" tries, as
	// subscription ids ("default", an added sign-in's id, "deepseek",
	// "kimi", "codex"); one that is not available is skipped.
	// LimitReturnAfterReset continues an automatically moved session back on
	// the sign-in it left once that sign-in's window has reset.
	LimitAction           string   `json:"limit_action,omitempty"`
	LimitFallbacks        []string `json:"limit_fallbacks,omitempty"`
	LimitReturnAfterReset bool     `json:"limit_return_after_reset,omitempty"`
	// CustomAgents are coding agents the user added by command (ADR-046), a
	// paid feature: kept whatever the licence says, offered and started only
	// while it is active. Edited through PUT /v1/agents/custom, which
	// validates them; see internal/agentcat.
	CustomAgents []CustomAgent `json:"custom_agents,omitempty"`
	// Subscriptions are the sign-ins added in Settings → Subscriptions
	// (ADR-048), each in its own configuration directory under the data dir.
	// The Default one is the user's normal sign-in and is not listed here.
	Subscriptions []Subscription `json:"subscriptions,omitempty"`
	// DefaultSubscription is, per agent ("claude", "codex"), the subscription
	// a new session starts on when none is picked — Make default in Settings →
	// Subscriptions. Absent means the user's own sign-in, as before. It is
	// Caprock's choice of directory for the sessions it starts: ~/.claude and
	// its credentials are never moved or rewritten.
	DefaultSubscription map[string]string `json:"default_subscription,omitempty"`
	// OwnLabels names the user's own sign-in per agent, when renamed.
	OwnLabels map[string]string `json:"own_labels,omitempty"`
	// Prompts records when each of the dashboard's own offers was last
	// answered — the GitHub star strip, the Premium and Teams nudges, the
	// share prompt — keyed by prompt id, in Unix ms. Kept here rather than in
	// the browser so an answer given in the desktop app holds in a browser
	// tab too, and the other way round. See .ai/04-ui.md, "Product-led
	// surfaces".
	Prompts map[string]int64 `json:"prompts,omitempty"`
	// BrowseRoot is where the folder picker may look. Empty means $HOME.
	BrowseRoot string `json:"browse_root,omitempty"`
	// DefaultFolder is where the Add project sheet starts: its folder field,
	// a new project's parent, a clone's destination and the folder browser.
	// Empty means the home folder. A leading ~ is the home folder.
	DefaultFolder string `json:"default_folder,omitempty"`
	// SetupAgents are the setup checklist's switches, by agent id (ADR-099
	// amendment, 2026-11-20): which agents this computer is set up for. An
	// agent with no entry follows the default (readiness.AgentOn: on when
	// installed, Claude Code on). Kept here, not in a browser, so the laptop
	// reading this computer's readiness and `caprock setup` see the same.
	SetupAgents map[string]bool `json:"setup_agents,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"`
	// SpawnPermissionMode is the mode new sessions start in when nothing more
	// specific says one: the new-session dialogs open on it, and a start
	// request with no mode (and no session to carry one from) gets it. In
	// Claude Code's words (agents.PermissionModes); empty means not set.
	SpawnPermissionMode string `json:"spawn_permission_mode,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"`
	// GitHubAutoRerun lets the daemon re-run, once per run, the jobs GitHub
	// never gave a machine (internal/github/autorerun.go): a write to the
	// user's repositories with the user's token that no click asked for, so
	// off unless turned on.
	GitHubAutoRerun bool `json:"github_auto_rerun,omitempty"`
	// KeepAwake is when the daemon keeps the computer from idle-sleeping
	// (internal/keepawake, ADR-049): "off", "working" (while an agent
	// works) or "always" (while Caprock runs). Empty means never chosen,
	// which is "working".
	KeepAwake string `json:"keep_awake,omitempty"`
	// WorktreeCleanup is what happens to finished copies — Caprock's
	// worktrees that are merged, pushed, clean and idle: "off", "ask" or
	// "auto"; empty is "ask" (projects/cleanup.go). Written only once
	// chosen.
	WorktreeCleanup string `json:"worktree_cleanup,omitempty"`
	// EndIdleAfter is how long an agent session Caprock started, with no
	// tab, may sit idle before Caprock ends its process (daemon/endidle.go):
	// "2h", "12h", "24h" or "never"; empty is "12h". Written only once
	// chosen.
	EndIdleAfter string `json:"end_idle_after,omitempty"`
	// StatuslineMode is what Caprock's Claude Code status line shows:
	// "full", "short", "hidden" or "off" (StatuslineModes). Empty is
	// "full". The status line command reads it at render time
	// (ReadStatuslineMode); "hidden" prints nothing but still forwards the
	// plan windows to the daemon; "off" also removes Caprock's own statusLine entry from Claude Code's
	// settings, and choosing again puts it back. Written only once chosen.
	StatuslineMode string `json:"statusline_mode,omitempty"`
	// QuickReplies are the one-click replies under a session Caprock started
	// (quickreply.go). Absent means DefaultQuickReplies; an empty list means
	// the user removed every one. Written only once changed.
	QuickReplies *[]QuickReply `json:"quick_replies,omitempty"`
	// AppUpdate is what the desktop app does when the release check finds a
	// newer version (ADR-042, amended 2026-10-15): "ask" shows the update
	// card, "auto" downloads the signed bundle in the background and installs
	// it once no agent is busy and the user is away. Empty is "ask". Only the
	// app's page acts on it; the daemon never installs anything itself.
	// Written only once chosen.
	AppUpdate string `json:"app_update,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) AlertDoneOn added in v0.146.0

func (c Config) AlertDoneOn() bool

AlertDoneOn reports whether a finished alert is sent for a turn that asked nothing (Done). On unless switched off.

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) CompressToolOutputOn added in v0.173.0

func (c Config) CompressToolOutputOn() bool

CompressToolOutputOn reports whether older tool payloads are compressed while idle; off unless turned on (ADR-093).

func (Config) DefaultSubscriptionFor added in v0.112.0

func (c Config) DefaultSubscriptionFor(agent string) string

DefaultSubscriptionFor is the subscription a new session of agent starts on when the request names none: an id from Subscriptions, or "" for the user's own sign-in — also when the chosen one has since been removed.

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) MorningSummaryOn added in v0.172.0

func (c Config) MorningSummaryOn() bool

MorningSummaryOn reports whether the Morning summary is switched on; off unless turned on (ADR-092).

func (Config) NotifyApprovalOn added in v0.76.0

func (c Config) NotifyApprovalOn() bool

NotifyApprovalOn reports whether a session that needs you raises an OS notification in the desktop app: a permission dialog, a question or a plan at once, and a turn that ended on a question or an error after its quiet minute. On unless switched off.

func (Config) NotifyFinishedOn added in v0.76.0

func (c Config) NotifyFinishedOn() bool

NotifyFinishedOn reports the old "finished" OS notification switch. Since 2026-10-21 it decides nothing: a Done turn raises no OS notification, and a turn that ended needing you is NotifyApprovalOn's. Kept so a config that set it still reads, and GET /v1/settings still answers it.

func (Config) OwnLabel added in v0.112.0

func (c Config) OwnLabel(agent string) string

OwnLabel is the name of the user's own sign-in to agent: what they renamed it to, or "Own sign-in".

func (Config) TelegramChatOn added in v0.101.0

func (c Config) TelegramChatOn() bool

TelegramChatOn reports whether the two-way Telegram chat is switched on. It works only with an active licence as well, which the bridge checks.

func (Config) TelegramCodeOn added in v0.101.0

func (c Config) TelegramCodeOn() bool

TelegramCodeOn reports whether replies sent to Telegram keep their code.

func (Config) WindowStop added in v0.92.0

func (c Config) WindowStop() int

WindowStop is the plan-window stop's share in percent, 0 when off; never chosen (nil) is off.

type CustomAgent added in v0.99.0

type CustomAgent struct {
	// ID is the agent's key, `custom:<id>` in a spawn request and on its
	// sessions: lowercase letters, digits and dashes.
	ID      string   `json:"id"`
	Name    string   `json:"name"`
	Command string   `json:"command"`
	Args    []string `json:"args,omitempty"`
	// Models are offered in the model pickers; empty offers the agent's own
	// default only.
	Models []string `json:"models,omitempty"`
}

CustomAgent is a coding agent the user added by its command (ADR-046).

Args is a template: `{prompt}` and `{model}` are replaced when the agent starts, and an argument whose placeholder has no value is left out, along with a flag right before it ("-m", "{model}" with no model chosen leaves both out). See agentcat.Argv.

type Plan added in v0.112.0

type Plan struct {
	// Kind is "flat" (Pro, Max, a Team seat) or "metered" (API, Bedrock).
	Kind string `json:"kind"`
	// Label is the user's own words for it ("Ultra").
	Label string `json:"label,omitempty"`
	// USDPerMonth is what one seat costs a month; 0 = not stated.
	USDPerMonth float64 `json:"usd_per_month,omitempty"`
}

Plan is how one sign-in is paid for: the same three facts as Config's PlanKind, PlanLabel and PlanUSDPerMonth, which stay the plan of the user's own sign-in and of every session no other plan is known for. Caprock never infers one (rule 6); the user states it.

type QuickReply added in v0.120.0

type QuickReply struct {
	Label string `json:"label"`
	Text  string `json:"text"`
}

QuickReply is one of the one-click replies drawn under a session Caprock started (.ai/04-ui.md § Quick replies): Label is the chip, Text is what is typed into the session, through the message queue (ADR-053), when the chip is pressed. Never into a session Caprock did not start (rule 7).

func EffectiveQuickReplies added in v0.120.0

func EffectiveQuickReplies(stored *[]QuickReply) []QuickReply

EffectiveQuickReplies is the list in use: the stored one, else the defaults.

func NormalizeQuickReplies added in v0.120.0

func NormalizeQuickReplies(in []QuickReply) ([]QuickReply, error)

NormalizeQuickReplies trims every label and text and checks the bounds: at most QuickRepliesMax, each label 1..QuickLabelMax runes on one line, each text 1..QuickTextMaxByte bytes with no control character but a newline.

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.

type Subscription added in v0.101.0

type Subscription struct {
	// ID names the subscription on a session (sessions.subscription) and its
	// directory, `<data dir>/profiles/<id>/`: lowercase letters and digits.
	ID string `json:"id"`
	// Label is what the user calls it ("Work Max", "Personal").
	Label string `json:"label"`
	// Agent is "claude" or "codex".
	Agent string `json:"agent"`
	// CreatedAt is when it was added, in Unix ms.
	CreatedAt int64 `json:"created_at"`
	// Plan is how this sign-in is paid for, stated by the user in Settings →
	// Plan & licence; nil means the main plan (PlanKind and its two fields)
	// stands for it too.
	Plan *Plan `json:"plan,omitempty"`
}

Subscription is a second (third, …) sign-in to Claude Code or Codex that Caprock keeps in a configuration directory of its own (ADR-048).

The user's normal sign-in — the one `claude` or `codex` uses with no environment variable — is the Default subscription. It is not stored here: it always exists, and nothing about it is Caprock's to keep.

type Upgrading added in v0.161.0

type Upgrading struct {
	PID       int   `json:"pid"`
	StartedAt int64 `json:"started_at"` // unix ms
}

func ReadUpgrading added in v0.161.0

func ReadUpgrading(dir string) (u Upgrading, ok bool)

Jump to

Keyboard shortcuts

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