daemon

package
v0.142.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 89 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 daemon wires every component into the running `caprock up` process: store, pricing, recorder, hookd, ingest, loop detector, API/WS server, the idle sweeper, and the runtime.json lifecycle.

Index

Constants

View Source
const (
	OrphanDaemon = "caprock_daemon" // another `caprock up --foreground`
	OrphanHolder = "caprock_holder" // a terminal holder no Caprock will reattach to
	// OrphanOldHolder is a holder this Caprock still lists, running from
	// another install's executable: a session that outlived a move between
	// installs (Homebrew to the app). Something runs in it; never ticked.
	OrphanOldHolder    = "caprock_old_holder"
	OrphanCaprockOther = "caprock_other" // any other caprock command whose parent is gone
	OrphanClaude       = "claude"        // a claude whose session ended or whose parent is gone
	OrphanCodex        = "codex"         // a codex CLI whose session ended or whose parent is gone
	OrphanMCP          = "mcp_server"    // an MCP server whose parent is gone
	OrphanClaudeChild  = "claude_child"  // started from a Claude Code session, parent gone
)

Orphan kinds, in the order the list shows them.

View Source
const EnvTelegramAPI = "CAPROCK_TELEGRAM_API"

EnvTelegramAPI replaces the Telegram API host, for testing against a stub.

View Source
const LockFileName = "caprock.lock"

LockFileName is the lock's file in the data directory.

View Source
const PprofEnv = "CAPROCK_PPROF"

PprofEnv names the opt-in profiling listener. Unset (the default) means no listener at all. Set to a loopback address — "127.0.0.1:6061" — it serves Go's net/http/pprof handlers there, on a listener of its own, never on the API port: that port can be reachable from a paired phone, and a profile carries memory contents. Anything that is not a loopback address is refused and logged, so a typo cannot open it to the network.

Variables

This section is empty.

Functions

func Age added in v0.116.0

func Age(d time.Duration) string

Age is a duration for a person: 40s, 12m, 3h, 7d (days from 48 hours).

func Bytes added in v0.113.0

func Bytes(n uint64) string

Bytes is a byte count for a person: 1.2 GB, 340 MB, 12 KB (powers of 1024, named the way the OS's own tools name them).

func PhoneLinkMessage added in v0.119.0

func PhoneLinkMessage(app string) string

PhoneLinkMessage is the one message "Send the link to my phone" sends: the phone's page, plain. No code, no key, no token — a phone that is already paired keeps its own token, and one that is not is told so by the page.

func Run

func Run(ctx context.Context, opt Options) error

Run starts the daemon and blocks until ctx is cancelled or a fatal error occurs.

Types

type AlreadyRunningError added in v0.113.0

type AlreadyRunningError struct {
	DataDir string
	PID     int // 0 when neither runtime.json nor the lock file names it
}

AlreadyRunningError is a second daemon refusing to start.

func (*AlreadyRunningError) Error added in v0.113.0

func (e *AlreadyRunningError) Error() string

type CaprockProc added in v0.113.0

type CaprockProc struct {
	PID int32  `json:"pid"`
	Exe string `json:"exe,omitempty"`
	// DataDir is the data directory a daemon was started with, from its
	// --data-dir or CAPROCK_DATA_DIR; "" when it used the default (or the
	// environment cannot be read).
	DataDir   string `json:"data_dir,omitempty"`
	MemBytes  uint64 `json:"mem_bytes"`
	StartedAt int64  `json:"started_at,omitempty"`
}

CaprockProc is one Caprock process the footprint names.

type CaprockResources added in v0.101.0

type CaprockResources struct {
	Daemon ProcUsage `json:"daemon"`
	// App is the desktop app's own process, when it is running.
	App *ProcUsage `json:"app,omitempty"`
	// Webview is the processes that draw the app's window: on macOS the
	// WebKit helpers (WebContent, GPU, Networking) macOS holds the app
	// responsible for — launchd's children, not the app's — and elsewhere
	// the app's own child processes (WebView2, WebKitGTK). Absent when the
	// app is not running or none is found.
	Webview *ProcGroup    `json:"webview,omitempty"`
	Hosts   HostResources `json:"hosts"`
}

CaprockResources is Caprock's own cost.

type Daemon

type Daemon struct {
	// contains filtered or unexported fields
}

Daemon is a running instance.

func (*Daemon) DisableLAN added in v0.50.0

func (d *Daemon) DisableLAN() error

DisableLAN closes the second listener. Paired devices are kept — they are the guest list, not the open door — so turning it back on does not mean walking to the tablet again.

func (*Daemon) EnableLAN added in v0.50.0

func (d *Daemon) EnableLAN() (string, error)

EnableLAN opens the second listener on this machine's private address, so a device on the same network can reach the dashboard after pairing.

Callable while the daemon runs, because the dashboard is where a person is when they decide they want this — and the alternative was "restart it from a terminal", which on a machine you are reading from a tablet is advice to give up. `caprock up --lan` still works and does the same thing at startup.

Not remembered across a restart unless the owner ticks *Keep on after Caprock restarts* (LANKeepOn, ADR-060): a laptop opened somewhere you do not trust should not carry a decision made at home without being asked.

func (*Daemon) LANKeepOn added in v0.116.0

func (d *Daemon) LANKeepOn() bool

LANKeepOn reports whether phone access is turned back on at start (ADR-060).

func (*Daemon) PhoneLinkReady added in v0.119.0

func (d *Daemon) PhoneLinkReady() bool

PhoneLinkReady implements api.PhoneLinkSender: a Telegram bot and chat are set up, so "Send the link to my phone" has somewhere to go.

func (*Daemon) RemoteState added in v0.116.0

func (d *Daemon) RemoteState(code string) api.RemoteState

RemoteState implements api.RemoteControl.

func (*Daemon) SendAlertCheck added in v0.72.0

func (d *Daemon) SendAlertCheck(ctx context.Context) error

SendAlertCheck sends a test alert now, so whoever set up the bot sees what an alert looks like without waiting for a session to need them.

func (d *Daemon) SendPhoneLink(ctx context.Context, app string) error

SendPhoneLink sends PhoneLinkMessage(app) to the owner's Telegram chat, through the bridge when it runs, else straight to the bot as the alerts do. The destination is the one the owner set up (ADR-047); nothing new leaves the machine.

func (*Daemon) SendReportNow added in v0.46.0

func (d *Daemon) SendReportNow(ctx context.Context) error

weeklyLoop sends the report when a week has gone by, not when a timer fires.

A ticker set for Monday 09:00 sends to nobody: the laptop is closed at the weekend, macOS does not fire missed ticks on wake, and the next tick is a week later. So this asks a question instead — is the ISO week of the last report we sent behind the current one, and is it past the send hour — and answers it every hour. A machine opened on Wednesday gets Monday's report on Wednesday, labelled with the week it covers, which is the honest outcome.

The marker is in the store rather than in memory, or a restart would send a second copy. SendReportNow builds this week's report and sends it immediately.

Without this the only way to find out whether a bot token and chat id are right is to wait for Monday. Somebody pastes two values, presses save, and has no way to tell a working setup from a typo until a week has passed — at which point nothing arrives and there is still nothing to look at, because the failure mode of this feature is silence.

It deliberately does not touch the week marker: a test send must not make the real report skip its week.

func (*Daemon) SetLANKeepOn added in v0.116.0

func (d *Daemon) SetLANKeepOn(on bool) error

SetLANKeepOn stores whether phone access is turned back on at start.

func (*Daemon) SetRemote added in v0.116.0

func (d *Daemon) SetRemote(on bool, relay, app string) error

SetRemote implements api.RemoteControl.

func (*Daemon) URL

func (d *Daemon) URL() string

URL returns the bound base URL (after start).

type ExeCount added in v0.113.0

type ExeCount struct {
	Exe   string `json:"exe"`
	Count int    `json:"count"`
}

ExeCount is how many holders run one executable.

type FileSize added in v0.64.0

type FileSize struct {
	Name  string `json:"name"`
	Bytes int64  `json:"bytes"`
	Dir   bool   `json:"dir,omitempty"`
}

FileSize is one top-level entry of the data directory; a directory is the sum of the files under it.

type FootprintAction added in v0.113.0

type FootprintAction struct {
	At   int64  `json:"at"` // unix ms
	What string `json:"what"`
}

FootprintAction is one thing the daemon did on its own.

type FootprintDisk added in v0.113.0

type FootprintDisk struct {
	TotalBytes int64 `json:"total_bytes"`
	// DatabaseBytes is caprock.db with its -wal and -shm; WALBytes is the
	// -wal alone.
	DatabaseBytes int64 `json:"database_bytes"`
	WALBytes      int64 `json:"wal_bytes"`
	PastesBytes   int64 `json:"pastes_bytes"`
	LogsBytes     int64 `json:"logs_bytes"`
	// BinariesBytes is the app's daemon copy (bin/) and the hook shim.
	BinariesBytes int64 `json:"binaries_bytes"`
	OtherBytes    int64 `json:"other_bytes"`
}

FootprintDisk is the data directory on disk, split by what it holds.

type FootprintDiskIO added in v0.113.0

type FootprintDiskIO struct {
	IntervalS int `json:"interval_s"`
	Samples   int `json:"samples"`
	// LastMinute is between the two newest readings; LastHour between the
	// oldest kept and the newest (shorter while the daemon is younger than
	// an hour, and Seconds says how long). Both are absent until there are
	// two readings.
	LastMinute *IOWindow `json:"last_minute,omitempty"`
	LastHour   *IOWindow `json:"last_hour,omitempty"`
	// SinceStart is the counters at the newest reading: everything the
	// daemon has read and written since it started.
	SinceStart *IOWindow `json:"since_start,omitempty"`
	Error      string    `json:"error,omitempty"`
}

FootprintDiskIO is the daemon's own reads and writes.

type FootprintDuplicates added in v0.113.0

type FootprintDuplicates struct {
	// Daemons is every other `caprock up --foreground` of this user.
	Daemons []CaprockProc `json:"daemons"`
	// Apps is every desktop app process; more than one is a duplicate.
	Apps []CaprockProc `json:"apps"`
	// OtherInstallHolders is the terminal holders running from an
	// executable outside this install.
	OtherInstallHolders OtherInstallHolders `json:"other_install_holders"`
}

FootprintDuplicates is what runs that should not.

type FootprintMemory added in v0.113.0

type FootprintMemory struct {
	Daemon  *ProcUsage  `json:"daemon,omitempty"`
	App     *ProcUsage  `json:"app,omitempty"`
	Webview *ProcGroup  `json:"webview,omitempty"`
	Hosts   HostSummary `json:"hosts"`
	// OtherDaemons is the memory of every daemon besides this one
	// (Duplicates.Daemons).
	OtherDaemonsMemBytes uint64 `json:"other_daemons_mem_bytes"`
	// Totals are all of the above.
	TotalMemBytes uint64  `json:"total_mem_bytes"`
	TotalCPUPct   float64 `json:"total_cpu_pct"`
}

FootprintMemory is the memory and CPU of every Caprock process.

type FootprintReport added in v0.113.0

type FootprintReport struct {
	At int64 `json:"at"`
	// DaemonRunning is false only in `caprock doctor`'s own report, made when
	// no daemon answered: then there is no daemon line and no disk I/O.
	DaemonRunning bool                `json:"daemon_running"`
	DataDir       string              `json:"data_dir"`
	Exe           string              `json:"exe,omitempty"`
	Memory        FootprintMemory     `json:"memory"`
	Disk          FootprintDisk       `json:"disk"`
	DiskIO        *FootprintDiskIO    `json:"disk_io,omitempty"`
	Duplicates    FootprintDuplicates `json:"duplicates"`
	// Orphans is the processes that look abandoned (orphans.go): the list
	// when it was asked for, the last scan's counts otherwise. Absent from a
	// daemon that predates it.
	Orphans  *OrphanReport      `json:"orphans,omitempty"`
	Verdicts []FootprintVerdict `json:"verdicts"`
	// Actions is what the daemon did about its own footprint without being
	// asked, oldest first: the last 50, since it started. Empty offline.
	Actions []FootprintAction `json:"actions"`
	Error   string            `json:"error,omitempty"`
	// SchemaNewer is set only in `caprock doctor`'s own report: the
	// database was migrated by a newer Caprock and this one refuses to open
	// it (store.SchemaTooNewError, ADR-082). The text is that error's.
	SchemaNewer string `json:"schema_newer,omitempty"`
}

FootprintReport is GET /v1/footprint.

func OfflineFootprint added in v0.113.0

func OfflineFootprint(ctx context.Context, dataDir string, running int32) *FootprintReport

OfflineFootprint is what `caprock doctor` can say without the daemon's own report: the Caprock processes in the process table (daemons, apps, holders and what each costs) and the data directory's size; no disk I/O, and no CPU — one sample has no rate. running is the pid of a daemon that answers for dataDir but predates GET /v1/footprint, 0 when none answers. The calling process is excluded from every list.

func (*FootprintReport) SetOrphans added in v0.116.0

func (f *FootprintReport) SetOrphans(o OrphanReport)

SetOrphans puts an orphan scan into a report that came without one (a daemon that predates the scan) and reaches the verdicts again.

func (*FootprintReport) Warns added in v0.113.0

func (f *FootprintReport) Warns() bool

Warns reports whether any verdict is a warning.

type FootprintVerdict added in v0.113.0

type FootprintVerdict struct {
	Level string `json:"level"`
	Code  string `json:"code"`
	Text  string `json:"text"`
}

FootprintVerdict is one finding. Level is "ok" or "warn".

type HostResources added in v0.101.0

type HostResources struct {
	HostSummary
	List []ptyhost.Verdict `json:"list"`
}

HostResources is the pty-hosts on this machine, with the verdict on each.

type HostSummary added in v0.113.0

type HostSummary struct {
	Count    int     `json:"count"`
	MemBytes uint64  `json:"mem_bytes"`
	CPUPct   float64 `json:"cpu_pct"`
	// Orphans are holders no daemon will attach to again; Reapable is the
	// part of them a reap stops (dead, or an idle shell). The rest run an
	// agent or a command and are left alone.
	Orphans  int `json:"orphans"`
	Reapable int `json:"reapable"`
}

HostSummary is the pty-hosts on this machine, counted.

type IOWindow added in v0.113.0

type IOWindow struct {
	ReadBytes  uint64 `json:"read_bytes"`
	WriteBytes uint64 `json:"write_bytes"`
	Seconds    int64  `json:"seconds"`
}

IOWindow is the bytes read and written over Seconds.

type Interrupted added in v0.60.0

type Interrupted struct {
	// StoppedAt is the last heartbeat of the run that stopped, unix ms: when
	// it stopped, to within a minute.
	StoppedAt int64    `json:"stopped_at"`
	IDs       []string `json:"ids"`
}

Interrupted is the sessions that were running when Caprock last stopped and were gone when it came back — a reboot, an OS update, the laptop lid. Somebody coming back to the machine wants exactly these, and they were scattered among every other ended session with nothing to tell them apart (FB-038).

type MachineResources added in v0.133.0

type MachineResources struct {
	CPUs int `json:"cpus"`
	// Load1 is the one-minute load average; nil where the OS keeps none
	// (Windows).
	Load1        *float64 `json:"load1,omitempty"`
	MemTotal     uint64   `json:"mem_total"`
	MemAvailable uint64   `json:"mem_available"`
}

MachineResources is the machine-wide part of GET /v1/resources.

type MemoryStatus added in v0.51.0

type MemoryStatus struct {
	// Repos and Since describe the handoff: how many folders it can speak for,
	// and the oldest passage recent enough to be handed over.
	Repos int    `json:"repos"`
	Since string `json:"since,omitempty"`
	// Held is when the oldest passage Caprock still has was written — the whole
	// corpus, not the fortnight the handoff reaches. The search screen spans
	// all of it, and using the handoff's date there would understate what is
	// searchable by a month.
	Held string `json:"held,omitempty"`
	// HoldoutPct is the share of handoffs held back to measure them, and
	// Served / Withheld how each group has done so far: how many sessions,
	// how many reached a first edit, and the median minutes and tool calls to
	// get there. Absent until a session has been counted in either group.
	HoldoutPct int                 `json:"holdout_pct,omitempty"`
	Served     *store.HandoffGroup `json:"served,omitempty"`
	Withheld   *store.HandoffGroup `json:"withheld,omitempty"`
}

MemoryStatus is what the handoff can do on this machine: how many repositories it could speak for, and since when.

type Options

type Options struct {
	DataDir        string
	Config         config.Config
	Version        string
	Log            *slog.Logger
	TranscriptRoot string // "" ⇒ ~/.claude/projects
	// Listener overrides the port (tests pass a pre-bound 127.0.0.1:0 listener).
	Listener net.Listener
	// LAN also serves the machine's private network address, so a tablet or
	// phone on the same network can reach the dashboard after pairing.
	//
	// A run flag rather than a stored setting, deliberately. Loopback-only is
	// what the product promises, and a promise that quietly survives a restart
	// is one nobody re-consents to: a laptop opened in a coworking space would
	// carry a decision made at home on a trusted network. Turning it on is an
	// act, every time — unless the owner ticked *Keep on after Caprock
	// restarts* (Config.LANKeepOn, ADR-060).
	LAN bool
	// DisableIngest turns transcript tailing off (tests, or hooks-only mode).
	DisableIngest bool
	// OpenCodeURL overrides where OpenCode's headless server is expected.
	// Empty means the documented default; tests point it at a stub.
	OpenCodeURL string
	// OpenCodeDB overrides where OpenCode's database is looked for. Empty means
	// discover it; "off" disables the reader entirely. Tests must set one or
	// the other, or a developer's own OpenCode sessions leak into a temporary
	// store and make assertions about session counts fail on their machine and
	// pass in CI.
	OpenCodeDB string
	// CodexDir overrides where Codex's rollout transcripts are looked for.
	// Empty means the default (sessions/ and archived_sessions/ under
	// $CODEX_HOME, else ~/.codex); "off" disables the import.
	CodexDir string
	// DeepseekDir overrides where DeepSeek Harness session transcripts are
	// looked for. Empty means the default (~/.dsh/sessions); "off" disables it.
	DeepseekDir string
	// HermesDB overrides where Hermes Agent's state database is looked for.
	// Empty means Hermes's own (state.db under $HERMES_HOME, else ~/.hermes);
	// "off" disables the import (ADR-069).
	HermesDB string
	// IdleAfter is the silence threshold before a session is marked idle.
	IdleAfter time.Duration
	// EndAfter is the silence threshold before a session is marked ended
	// (default 1h). It is a backstop, not the main path: SessionEnd ends a
	// session the moment the user leaves it. What this catches is the session
	// whose hook never fired — kill -9, a closed terminal, a crashed host.
	EndAfter time.Duration
	// HiveDir enables Phase 2 orchestration (tasks board + Stop-loop) at this path.
	// Empty ⇒ orchestration off (task endpoints return 501).
	HiveDir string
	// RepoCwd is the repo the orchestrator + workers operate on (default: cwd).
	RepoCwd string
	// HolderExe is the Caprock binary that runs `pty-host`, the process that
	// keeps an owned session's terminal alive across daemon restarts
	// (ADR-033). Empty runs sessions inside the daemon, as before: tests that
	// run the daemon in-process have no such binary to offer.
	HolderExe string
	// OnReady is called once the server is listening (with the bound URL).
	OnReady func(url string)
	// KeepAwake holds the computer awake while agents work (ADR-049).
	// cmd/caprock passes keepawake.NewOS(); nil — tests, the smoke run —
	// reports the feature unavailable and never touches the OS.
	KeepAwake keepawake.Holder
	// Secrets is where the DeepSeek key and the Telegram bot token are kept.
	// nil is internal/secret's choice for this OS; tests pass a fake, so no
	// test ever touches a keychain.
	Secrets func(secret.Item) secret.Store
}

Options configure a daemon run.

type Orphan added in v0.116.0

type Orphan struct {
	PID       int32  `json:"pid"`
	StartedAt int64  `json:"started_at"`
	Kind      string `json:"kind"`
	// Label is the program and, for Caprock, its subcommand: "caprock
	// pty-host", "claude", "node server-github".
	Label string `json:"label"`
	// Cmd is the command line, cut to cmdMax characters, the program by its
	// base name and the value of anything that names a token, key, secret or
	// password hidden (cmdLine). Empty when argv cannot be read.
	Cmd string `json:"cmd,omitempty"`
	Exe string `json:"exe,omitempty"`
	// DataDir is the Caprock data directory a daemon or holder belongs to,
	// when it can be told; DataDirGone is set when it no longer exists.
	DataDir     string `json:"data_dir,omitempty"`
	DataDirGone bool   `json:"data_dir_gone,omitempty"`
	// CPUPct is absent until there are two samples of it.
	CPUPct   *float64 `json:"cpu_pct,omitempty"`
	MemBytes uint64   `json:"mem_bytes"`
	// Why is the reason it is listed, in a sentence.
	Why string `json:"why"`
	// Auto is set on a holder the daemon stops on its own (the sweep).
	Auto bool `json:"auto,omitempty"`
}

Orphan is one process that looks abandoned. PID and StartedAt together name it: a stop names both, and a pid whose start has changed is another process and is not signalled.

type OrphanReport added in v0.116.0

type OrphanReport struct {
	// Scanned is true when List was taken for this answer. Otherwise the
	// counts are the last scan's (the 10-minute sweep, or the doctor's last
	// look) and List is empty.
	Scanned bool `json:"scanned"`
	// At is when the counted scan ran, unix ms.
	At     int64          `json:"at"`
	Count  int            `json:"count"`
	ByKind map[string]int `json:"by_kind"`
	// MemBytes is the memory of every listed process together: the strip's
	// "orphans 3 · 410 MB".
	MemBytes uint64   `json:"mem_bytes"`
	List     []Orphan `json:"list"`
	// Note says what this scan could not look at.
	Note string `json:"note,omitempty"`
}

OrphanReport is the footprint's `orphans`.

func OfflineOrphans added in v0.116.0

func OfflineOrphans(ctx context.Context, dataDir string, running int32) OrphanReport

OfflineOrphans is the orphan list `caprock doctor` takes itself when no daemon answers (or the one that answers predates the scan). Without the daemon's store there are no sessions to check: a claude is judged by its parent alone. running is the daemon that answers for dataDir but predates the scan, 0 when none answers; it and the doctor itself are never listed.

type OrphanStopResult added in v0.116.0

type OrphanStopResult struct {
	Stopped []Orphan `json:"stopped"`
	// Running got its signal and was still there when the grace ran out.
	// Nothing more was sent: a SIGKILL is the user's second click (force).
	Running []Orphan      `json:"running"`
	Failed  []ReapFailure `json:"failed"`
}

OrphanStopResult is POST /v1/footprint/orphans/stop.

func StopOrphansOffline added in v0.116.0

func StopOrphansOffline(ctx context.Context, dataDir string, targets []OrphanTarget, running int32, force bool) OrphanStopResult

StopOrphansOffline is `caprock doctor --stop` with no daemon to ask: the same rule, against the doctor's own scan.

type OrphanTarget added in v0.116.0

type OrphanTarget = api.OrphanTarget

OrphanTarget names one listed process to stop: its pid and the start time the list gave.

type OtherInstallHolders added in v0.113.0

type OtherInstallHolders struct {
	Count int `json:"count"`
	// Orphans is how many of them no daemon will reattach to.
	Orphans int        `json:"orphans"`
	Exes    []ExeCount `json:"exes"`
}

OtherInstallHolders counts holders by the executable they run from.

type PricingStatus

type PricingStatus struct {
	Version      string `json:"version"`
	Source       string `json:"source"`
	FetchedAt    string `json:"fetched_at"`
	UserOverride bool   `json:"user_override"`
	Models       int    `json:"models"`
}

PricingStatus summarizes the table in force.

type ProcGroup added in v0.113.0

type ProcGroup struct {
	Count    int         `json:"count"`
	CPUPct   float64     `json:"cpu_pct"`
	MemBytes uint64      `json:"mem_bytes"`
	Procs    []ProcUsage `json:"procs"`
}

ProcGroup is several processes counted as one: the app's web view.

type ProcUsage added in v0.101.0

type ProcUsage struct {
	PID      int32   `json:"pid"`
	Name     string  `json:"name"`
	CPUPct   float64 `json:"cpu_pct"`
	MemBytes uint64  `json:"mem_bytes"`
}

ProcUsage is one process's figures.

type ReapFailure added in v0.101.0

type ReapFailure struct {
	PID   int32  `json:"pid"`
	Error string `json:"error"`
}

ReapFailure is a holder a reap could not stop.

type ReapResult added in v0.101.0

type ReapResult struct {
	Reaped []ptyhost.Verdict `json:"reaped"`
	// Failed are the ones that would not stop, with why.
	Failed []ReapFailure `json:"failed,omitempty"`
	// Kept are the orphans left running: an agent or a command is still
	// running in them.
	Kept []ptyhost.Verdict `json:"kept"`
}

ReapResult is POST /v1/resources/reap.

type ResourceHistory added in v0.120.0

type ResourceHistory struct {
	IntervalS int                `json:"interval_s"`
	Capacity  int                `json:"capacity"`
	At        []int64            `json:"at"`
	Caprock   Series             `json:"caprock"`
	All       Series             `json:"all"`
	Sessions  map[string]*Series `json:"sessions"`
}

ResourceHistory is GET /v1/resources/history.

type ResourceReport added in v0.101.0

type ResourceReport struct {
	At         int64              `json:"at"`
	Sessions   []SessionResources `json:"sessions"`
	Caprock    CaprockResources   `json:"caprock"`
	Thresholds ResourceThresholds `json:"thresholds"`
	// Machine is the machine as a whole (ADR-067): what another computer
	// reads through /v1/m/{id}/v1/resources to say which one has room.
	// Absent when the OS gave none of it.
	Machine *MachineResources `json:"machine,omitempty"`
	Error   string            `json:"error,omitempty"`
	// contains filtered or unexported fields
}

ResourceReport is GET /v1/resources and the data of a "resources" frame.

type ResourceThresholds added in v0.101.0

type ResourceThresholds struct {
	CPUPct      float64 `json:"cpu_pct"`
	MemBytes    uint64  `json:"mem_bytes"`
	AfterS      int     `json:"after_s"`
	IntervalSec int     `json:"interval_s"`
}

ResourceThresholds are the "hot" limits, so a client can say what they are.

type Series added in v0.120.0

type Series struct {
	CPU []*float64 `json:"cpu"`
	Mem []*uint64  `json:"mem"`
}

Series is one line of the history: values aligned with ResourceHistory.At, null where there is no figure — a session not running then, or a CPU before its first rate.

type SessionResources added in v0.101.0

type SessionResources struct {
	SessionID string `json:"session_id"`
	PID       int32  `json:"pid"`
	// CPUPct is summed over the tree: 250 is two and a half cores.
	CPUPct   float64 `json:"cpu_pct"`
	MemBytes uint64  `json:"mem_bytes"`
	Procs    int     `json:"procs"`
	// Warm is false on a tree's first sample, before there is a CPU rate.
	Warm bool        `json:"warm"`
	Top  []ProcUsage `json:"top"`
	Hot  bool        `json:"hot"`
	// OverSince is when the tree last went over a limit (unix ms), 0 while
	// it is under both; Hot follows hotAfter later.
	OverSince int64 `json:"over_since,omitempty"`
}

SessionResources is one live session's process tree.

type Status

type Status struct {
	Version string `json:"version"`
	// APILevel is version.APILevel: what a client compares against the
	// minimum it needs, instead of parsing Version.
	APILevel int `json:"api_level"`
	// Platform is GOOS/GOARCH — the first thing a bug report needs and the
	// last thing anyone remembers to include.
	Platform  string `json:"platform"`
	PID       int    `json:"pid"`
	StartedAt int64  `json:"started_at"`
	UptimeS   int64  `json:"uptime_s"`
	URL       string `json:"url"`
	DataDir   string `json:"data_dir"`
	// Executable is the caprock binary this daemon runs from, in the form
	// that survives an upgrade (stableExecutable): what Settings → Use
	// Caprock from your agents puts in the MCP command when `caprock` is not
	// on the PATH (ADR-078).
	Executable string        `json:"executable,omitempty"`
	Pricing    PricingStatus `json:"pricing"`
	Ingest     *ingest.Stats `json:"ingest,omitempty"`
	// IngestError is the terminal error that stopped transcript ingest, when
	// one happened (a read-only ~/.claude, a vanished transcript root). Empty
	// while ingest is running. Without it the daemon looked healthy while
	// capturing nothing, and the dashboard told the user to start `claude` and
	// wait for sessions that could never arrive.
	IngestError string        `json:"ingest_error,omitempty"`
	Hooks       *hooks.Status `json:"hooks,omitempty"`
	// ClaudeBypassAccepted says the user accepted Claude Code's one-time
	// bypass warning, so a bypass session starts without it (ADR-041).
	ClaudeBypassAccepted bool `json:"claude_bypass_accepted"`
	UIBuilt              bool `json:"ui_built"`
	ClaudeAvailable      bool `json:"claude_available"`
	// ShellEnv says whether sessions Caprock starts get the user's login-shell
	// environment or, because it could not be read, the daemon's own — the
	// difference between a spawned session finding gcloud and not (FB-033).
	ShellEnv userenv.State `json:"shell_env"`
	// GeminiAvailable says the Gemini CLI is on PATH, so the new-session
	// dialog offers an agent the machine actually has rather than a choice
	// that fails on click.
	GeminiAvailable bool `json:"gemini_available"`
	// CodexAvailable and OpenCodeAvailable say the same of those CLIs, found on
	// the login shell's PATH or where their installers put them.
	CodexAvailable    bool `json:"codex_available"`
	OpenCodeAvailable bool `json:"opencode_available"`
	// GrokAvailable says the same of xAI's Grok Build CLI (ADR-046).
	GrokAvailable bool `json:"grok_available"`
	// OpenCodeVersion is the version of the OpenCode a new session would
	// start ("2.0.26"), absent while unknown. OpenCode 1 and 2 take different
	// flags, and the New session dialog words a mode by what it becomes.
	OpenCodeVersion string `json:"opencode_version,omitempty"`
	// OpenCode reports what the second agent's reader is doing, or is absent
	// when OpenCode is not installed. Without it there was no way to tell
	// whether a machine that runs OpenCode was having those sessions read:
	// the dashboard shows them mixed in with Claude Code's, so their absence
	// looks the same as having none.
	OpenCode *opencode.Stats `json:"opencode,omitempty"`
	// Codex reports the third agent's reader on the same terms, and is absent
	// when the machine has no Codex transcripts.
	Codex *codex.Stats `json:"codex,omitempty"`
	// Deepseek reports the DeepSeek Harness reader on the same terms, and is
	// absent when the machine has no DSH transcripts.
	Deepseek *deepseek.Stats `json:"deepseek,omitempty"`
	// Hermes reports the Hermes Agent reader on the same terms, and is absent
	// when the machine has no Hermes database (ADR-069).
	Hermes *hermes.Stats `json:"hermes,omitempty"`
	// HermesAvailable says the hermes CLI is installed, so New agent offers it.
	HermesAvailable bool `json:"hermes_available"`
	OwnedActive     int  `json:"owned_active"`
	Orchestration   bool `json:"orchestration"`
	// Memory reports how many repositories have enough history to hand a new
	// session what was left there. A feature that acts before you type is one
	// nobody can see working, so the status screen says whether it can.
	Memory MemoryStatus `json:"memory"`
	// Hive is the orchestration directory in force, and Repo the checkout its
	// workers operate on. Both empty when orchestration is off. Without them
	// there was no way — CLI, API or log — to ask which hive a running daemon
	// had been started with.
	Hive string `json:"hive,omitempty"`
	Repo string `json:"repo,omitempty"`
	// SuggestedHive and SuggestedRepo are what POST /v1/hive would use if it were
	// called with no body — the defaults the dashboard shows for confirmation
	// before turning the runner on. Present only while orchestration is off.
	SuggestedHive string `json:"suggested_hive,omitempty"`
	SuggestedRepo string `json:"suggested_repo,omitempty"`
	LoopK         int    `json:"loop_k"`
	LoopTMin      int    `json:"loop_t_minutes"`
	ActiveLoops   int    `json:"active_loops"`
	Events        int64  `json:"events"`
	RetentionDays int    `json:"retention_days"`
	// Interrupted is the sessions the last stop of Caprock (or of the
	// machine) cut off and nobody has continued yet. Absent when there are
	// none (FB-038).
	Interrupted *Interrupted `json:"interrupted,omitempty"`
	// Desktop is the Claude desktop app's own plan usage, when it has any on
	// this machine. Omitted entirely otherwise — most people do not use it.
	Desktop *desktop.Reading `json:"desktop,omitempty"`
}

Status is /v1/status.

type StorageReport added in v0.64.0

type StorageReport struct {
	DataDir string `json:"data_dir"`
	// TotalBytes is every file under the data directory, the database
	// included; Files splits it by top-level entry, largest first.
	TotalBytes int64      `json:"total_bytes"`
	Files      []FileSize `json:"files"`
	// Database is the cached composition, absent until it has been measured
	// once; MeasuredAt and MeasureMs say when and how long it took.
	Database   *store.Storage `json:"database,omitempty"`
	MeasuredAt int64          `json:"measured_at,omitempty"`
	MeasureMs  int64          `json:"measure_ms,omitempty"`
	Error      string         `json:"error,omitempty"`
	// Measuring is true while a measurement runs in the background; the
	// figures above are the previous one's until it finishes.
	Measuring bool `json:"measuring,omitempty"`
	// ReclaimableBytes is the database's free pages: what a VACUUM would hand
	// back to the disk. Zero until measured.
	ReclaimableBytes int64 `json:"reclaimable_bytes"`
	// ReturnsFreeSpace is true when the database is in incremental
	// auto-vacuum mode: free pages go back to the disk on their own while
	// the daemon is idle (compact.go). False until the one VACUUM that
	// switches an older database over has run.
	ReturnsFreeSpace bool `json:"returns_free_space"`
	// GrowthBytesPerDayEst is an estimate, and named as one: the bytes of
	// event payload recorded over the last 30 days, per day, scaled by how
	// many bytes on disk each payload byte has cost so far (the events table
	// and its indexes over the payload they hold). Zero when there is too
	// little to scale by.
	GrowthBytesPerDayEst int64 `json:"growth_bytes_per_day_est"`
	RetentionDays        int   `json:"retention_days"`
}

StorageReport is what GET /v1/storage returns. See 03-contracts.md § Storage.

Jump to

Keyboard shortcuts

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