api

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 17 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 api is Smif's wire protocol: newline-delimited JSON-RPC 2.0 over a Unix socket (RFC 5.4), plus the request and response types of every method in RFC 7.1.

Index

Constants

View Source
const (
	CodeParse       = -32700
	CodeInvalid     = -32600
	CodeNoMethod    = -32601
	CodeParams      = -32602
	CodeInternal    = -32603
	CodeAuth        = -32001
	CodeForbidden   = -32002
	CodeRejected    = -32003
	CodeNotFound    = -32004
	CodeUnavailable = -32005
	CodeVersion     = -32006
	CodeRateLimited = -32007
)

Error codes. Negative numbers below -32000 are server-defined.

View Source
const (
	// CancelRejected: the item was queued, waiting or needs_human and is
	// rejected now (reason "cancelled").
	CancelRejected = "rejected"
	// CancelCancelling: the item is running; its worker is told to stop
	// and the item stays running until the run ends (read thread.get).
	CancelCancelling = "cancelling"
)

Values of CancelResult.State.

View Source
const MaxLine = 40 << 20

MaxLine caps one request or response line (a 25 MiB attachment in base64 plus framing).

View Source
const ProtocolVersion = "1.0"

ProtocolVersion is sent with every request; the major part must match.

Variables

This section is empty.

Functions

func IsCode

func IsCode(err error, code int) bool

IsCode reports whether err is an *Error with the given code.

func ShortSession

func ShortSession(id string) string

ShortSession is the first 8 characters of a Claude Code session id (a UUID), as `claude --resume` users know it.

Types

type AgentView

type AgentView struct {
	ID          string   `json:"id"`
	Repo        string   `json:"repo"`
	Intents     []string `json:"intents"`
	Queued      int      `json:"queued"`
	Running     int      `json:"running"`
	NeedsHuman  int      `json:"needs_human"`
	DeadLetters int      `json:"dead_letters"`
	BudgetUSD   float64  `json:"budget_usd,omitempty"`
	SpentUSD    float64  `json:"spent_usd_today"`
	TokensToday int64    `json:"tokens_today"`
	BudgetLeft  *float64 `json:"budget_left_usd,omitempty"`
	Interactive bool     `json:"interactive_session"`
}

AgentView is agent.list.

type AuditEvent

type AuditEvent struct {
	Seq       int64          `json:"seq"`
	TS        time.Time      `json:"ts"`
	Event     string         `json:"event"`
	Agent     string         `json:"agent,omitempty"`
	MessageID string         `json:"message_id,omitempty"`
	RunID     string         `json:"run_id,omitempty"`
	ThreadID  string         `json:"thread_id,omitempty"`
	Detail    map[string]any `json:"detail,omitempty"`
}

AuditEvent is one audit row (the same fields as the JSONL log).

type AuditPage

type AuditPage struct {
	Events []AuditEvent `json:"events"`
	// Cursor is the After of the next call.
	Cursor int64 `json:"cursor"`
	// Head is the newest seq in the table. Head < the caller's cursor
	// means a new database: start again with FromEnd.
	Head int64 `json:"head"`
	// More is true when rows after Cursor exist already.
	More bool `json:"more"`
}

AuditPage is the audit.since result.

type AuditParams

type AuditParams struct {
	// After is the cursor: rows with seq > After.
	After int64 `json:"after"`
	// Limit caps the rows (default 200, max 1000).
	Limit int `json:"limit,omitempty"`
	// FromEnd returns the newest Limit rows instead (Limit 0: none) and a
	// cursor at the head, so a follower starts at "now".
	FromEnd bool `json:"from_end,omitempty"`
}

AuditParams is audit.since: audit rows after a cursor (human only, ADR-0008).

type Auth

type Auth struct {
	Agent  string `json:"agent"`
	Token  string `json:"token"`
	Origin string `json:"origin,omitempty"`
}

Auth identifies the caller.

type AwaitParams

type AwaitParams struct {
	Ticket string `json:"ticket"`
	WaitS  int    `json:"wait_s,omitempty"`
}

AwaitParams is message.await.

type AwaitResult

type AwaitResult struct {
	Ticket string     `json:"ticket"`
	Status string     `json:"status"` // pending | answered
	State  string     `json:"state"`
	Reply  *ReplyView `json:"reply,omitempty"`
}

AwaitResult carries the reply when it is in.

type BlobGetResult

type BlobGetResult struct {
	SHA256 string `json:"sha256"`
	Size   int64  `json:"size"`
	MIME   string `json:"mime"`
	Data   []byte `json:"data"`
}

BlobGetResult returns blob bytes.

type BlobPutParams

type BlobPutParams struct {
	Name string `json:"name"`
	MIME string `json:"mime,omitempty"`
	Data []byte `json:"data"` // base64 in JSON
}

BlobPutParams uploads an attachment.

type Caller

type Caller = auth.Principal

Caller is the authenticated principal of a request.

type CancelResult

type CancelResult struct {
	ID    string `json:"id"`
	State string `json:"state"`
}

CancelResult is the response of message.cancel: the state the item has after the call (ADR-0009).

type Client

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

Client is a connection to the daemon.

func Dial

func Dial(socket string, a Auth, timeout time.Duration) (*Client, error)

Dial connects with a timeout.

func (*Client) Call

func (c *Client) Call(method string, params, out any, timeout time.Duration) error

Call invokes method and decodes the result into out (if non-nil). timeout 0 means no deadline.

func (*Client) Close

func (c *Client) Close() error

Close closes the connection.

type Counts

type Counts struct {
	Agent            string `json:"agent,omitempty"`
	Running          int    `json:"running"`
	Queued           int    `json:"queued"`
	Handled          int    `json:"handled"`
	NeedsHuman       int    `json:"needs_human"`
	RepliesReady     int    `json:"replies_ready"`
	DirectLock       bool   `json:"direct_lock,omitempty"`
	GlobalNeedsHuman int    `json:"global_needs_human"`
	GlobalDLQ        int    `json:"global_dlq"`
	ClaudeOK         bool   `json:"claude_ok"`
	// The other live sessions that need the human (human callers only,
	// ADR-0014): the names of those that wait in their tab, and of those
	// with an answer the human has not seen (the UI's seen file).
	SessionsWaiting  []string `json:"sessions_waiting,omitempty"`
	SessionsAnswered []string `json:"sessions_answered,omitempty"`
}

Counts is inbox.counts and smif_status.

type CountsParams

type CountsParams struct {
	Cwd   string `json:"cwd,omitempty"`
	Agent string `json:"agent,omitempty"`
	// SessionID is the asking session (the status line): it is left out of
	// SessionsWaiting and SessionsAnswered.
	SessionID string `json:"session_id,omitempty"`
}

CountsParams is inbox.counts.

type DigestItem

type DigestItem struct {
	MessageID     string    `json:"message_id"`
	ThreadID      string    `json:"thread_id"`
	Agent         string    `json:"agent"`
	From          string    `json:"from"`
	Kind          string    `json:"kind"`
	Intent        string    `json:"intent"`
	Subject       string    `json:"subject"`
	State         string    `json:"state"`
	Summary       string    `json:"summary,omitempty"`
	HumanQuestion string    `json:"human_question,omitempty"`
	Coalesced     int       `json:"coalesced_count,omitempty"`
	Branch        string    `json:"branch,omitempty"`
	RunID         string    `json:"run_id,omitempty"`
	At            time.Time `json:"at"`
}

DigestItem is one handled item.

type DigestParams

type DigestParams struct {
	Agent   string `json:"agent,omitempty"`
	Cwd     string `json:"cwd,omitempty"`
	Since   string `json:"since,omitempty"` // "last" (default) or "all"
	Advance bool   `json:"advance"`
	Limit   int    `json:"limit,omitempty"`
	// Until, when above 0, keeps the items and the cursor advance at or
	// below this handled seq (a DigestResult.Cursor the caller already
	// showed), so items handled later are not marked read (ADR-0008).
	Until int64 `json:"until,omitempty"`
}

DigestParams is digest.get.

type DigestResult

type DigestResult struct {
	Agents []string     `json:"agents"`
	Items  []DigestItem `json:"items"`
	Cursor int64        `json:"cursor"`
}

DigestResult is digest.get.

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

Error is a JSON-RPC error object.

func Errf

func Errf(code int, format string, a ...any) *Error

Errf builds an *Error.

func (*Error) Error

func (e *Error) Error() string

type GCResult

type GCResult struct {
	Messages    int `json:"messages_deleted"`
	Runs        int `json:"runs_deleted"`
	Transcripts int `json:"transcripts_deleted"`
	Blobs       int `json:"blobs_deleted"`
	Branches    int `json:"branches_deleted"`
	AuditFiles  int `json:"audit_files_compressed"`
	Logs        int `json:"logs_deleted"`
}

GCResult reports admin.gc.

type Handler

type Handler func(ctx context.Context, c Caller, params json.RawMessage) (any, error)

Handler serves one method.

type HealthView

type HealthView struct {
	OK             bool     `json:"ok"`
	Version        string   `json:"version"`
	SchemaVersion  int      `json:"schema_version"`
	DB             string   `json:"db"`
	ClaudeVersion  string   `json:"claude_version"`
	ClaudeOK       bool     `json:"claude_ok"`
	ClaudeProblems []string `json:"claude_problems,omitempty"`
	FlagProbe      []string `json:"flag_probe,omitempty"`
	// Sessions checks the Claude Code files the session view reads (session
	// files, transcripts; not a documented interface, ADR-0012): "ok",
	// "none" (no files: hooks only) or "changed" with the detail.
	Sessions       string `json:"sessions"`
	SessionsDetail string `json:"sessions_detail,omitempty"`
	// Providers has one line per harness provider for smif doctor.
	Providers  []ProviderCheck `json:"providers,omitempty"`
	ConfigPath string          `json:"config_path"`
	StartedAt  time.Time       `json:"started_at"`
	PID        int             `json:"pid"`
}

HealthView is admin.health.

type HumanReplyParams

type HumanReplyParams struct {
	MessageID string          `json:"message_id"`
	Text      string          `json:"text"`
	Data      json.RawMessage `json:"data,omitempty"`
}

HumanReplyParams is message.reply.

type IDParams

type IDParams struct {
	ID string `json:"id"`
}

IDParams carries one message, run or thread id.

type ListParams

type ListParams struct {
	Agent     string `json:"agent,omitempty"`
	State     string `json:"state,omitempty"`
	MessageID string `json:"message_id,omitempty"`
	Limit     int    `json:"limit,omitempty"`
}

ListParams filters thread.list and run.list.

type MessageView

type MessageView struct {
	ID            string                `json:"id"`
	ThreadID      string                `json:"thread_id"`
	ParentID      string                `json:"parent_id,omitempty"`
	From          envelope.From         `json:"from"`
	To            string                `json:"to"`
	Kind          string                `json:"kind"`
	Intent        string                `json:"intent"`
	Priority      string                `json:"priority"`
	Subject       string                `json:"subject"`
	Body          string                `json:"body,omitempty"`
	Data          json.RawMessage       `json:"data,omitempty"`
	Attachments   []envelope.Attachment `json:"attachments,omitempty"`
	State         string                `json:"state"`
	Hop           int                   `json:"hop"`
	Coalesced     int                   `json:"coalesced_count"`
	Recurrence    bool                  `json:"recurrence,omitempty"`
	Attempt       int                   `json:"attempt"`
	Handler       string                `json:"handler,omitempty"`
	RuleID        string                `json:"rule_id,omitempty"`
	Summary       string                `json:"summary,omitempty"`
	Reason        string                `json:"reason,omitempty"`
	HoldReason    string                `json:"hold_reason,omitempty"`
	HumanQuestion string                `json:"human_question,omitempty"`
	ReplyStatus   string                `json:"reply_status,omitempty"`
	CreatedAt     time.Time             `json:"created_at"`
	UpdatedAt     time.Time             `json:"updated_at"`
}

MessageView is a message summary (bodies only for the human).

type Metrics

type Metrics struct {
	QueueDepth   int                `json:"queue_depth"`
	Running      int                `json:"running"`
	SuccessRate  float64            `json:"success_rate_24h"`
	P50Seconds   float64            `json:"run_p50_s"`
	P95Seconds   float64            `json:"run_p95_s"`
	CostToday    map[string]float64 `json:"cost_usd_today"`
	TokensToday  map[string]int64   `json:"tokens_today"`
	DLQ          int                `json:"dlq"`
	BudgetLeft   map[string]float64 `json:"budget_left_usd"`
	RunsLast24h  int                `json:"runs_24h"`
	Coalesced24h int                `json:"coalesced_24h"`
}

Metrics are the RFC 8.3 counters.

type PresenceParams

type PresenceParams struct {
	// Event is start | heartbeat | end, or busy (a prompt was submitted)
	// and idle (the turn ended) from the hooks (ADR-0012).
	Event     string `json:"event"`
	Cwd       string `json:"cwd"`
	SessionID string `json:"session_id"`
	// Agent, when set ($SMIF_AGENT in the session), wins over Cwd.
	Agent string `json:"agent,omitempty"`
	// Where the session runs, from the hook: its terminal device, the
	// claude process and $TERM_PROGRAM ("tmux" inside tmux, "herdr" in a
	// herdr pane).
	TTY  string `json:"tty,omitempty"`
	PID  int    `json:"pid,omitempty"`
	Term string `json:"term,omitempty"`
	// Title is the session's name (claude --name, /rename) and LastPrompt
	// the human's last prompt (shortened), from the transcript.
	Title      string `json:"title,omitempty"`
	LastPrompt string `json:"last_prompt,omitempty"`
}

PresenceParams is presence.update.

type ProviderCheck

type ProviderCheck struct {
	Name     string `json:"name"`
	Verified bool   `json:"verified"`
	State    string `json:"state"`
	Detail   string `json:"detail,omitempty"`
}

ProviderCheck is one provider's format check (ADR-0019). State is ok, none or changed for a verified provider, and unchecked for one that no real session checked.

type ReplyView

type ReplyView struct {
	ID          string                `json:"id"`
	From        string                `json:"from"`
	Status      string                `json:"status"`
	Text        string                `json:"text"`
	Data        json.RawMessage       `json:"data,omitempty"`
	Attachments []envelope.Attachment `json:"attachments,omitempty"`
	CreatedAt   time.Time             `json:"created_at"`
}

ReplyView is a reply as returned to its asker.

type Request

type Request struct {
	JSONRPC         string          `json:"jsonrpc"`
	ID              int64           `json:"id"`
	Method          string          `json:"method"`
	Params          json.RawMessage `json:"params,omitempty"`
	Auth            Auth            `json:"auth"`
	ProtocolVersion string          `json:"protocol_version"`
}

Request is a JSON-RPC request with Smif's auth and version members.

type Response

type Response struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      int64           `json:"id"`
	Result  json.RawMessage `json:"result,omitempty"`
	Error   *Error          `json:"error,omitempty"`
}

Response is a JSON-RPC response.

type RunView

type RunView struct {
	ID              string          `json:"id"`
	MessageID       string          `json:"message_id"`
	Agent           string          `json:"agent"`
	Handler         string          `json:"handler"`
	Profile         string          `json:"profile,omitempty"`
	Attempt         int             `json:"attempt"`
	State           string          `json:"state"`
	PID             int             `json:"pid,omitempty"`
	SessionID       string          `json:"session_id,omitempty"`
	ArchivedSession string          `json:"archived_session,omitempty"`
	Workspace       string          `json:"workspace,omitempty"`
	Branch          string          `json:"branch,omitempty"`
	HeadSHA         string          `json:"head_sha,omitempty"`
	Diffstat        string          `json:"diffstat,omitempty"`
	Result          json.RawMessage `json:"result,omitempty"`
	CostUSD         float64         `json:"cost_usd"`
	InputTokens     int64           `json:"input_tokens"`
	OutputTokens    int64           `json:"output_tokens"`
	Error           string          `json:"error,omitempty"`
	Transcript      string          `json:"transcript,omitempty"`
	Stderr          string          `json:"stderr,omitempty"`
	StartedAt       time.Time       `json:"started_at"`
	EndedAt         *time.Time      `json:"ended_at,omitempty"`
}

RunView is a run record.

type SavedPrompt

type SavedPrompt struct {
	Name string `json:"name"`
	Text string `json:"text"`
}

SavedPrompt is one of the human's saved prompts (prompts.list, ADR-0015).

type SendParams

type SendParams struct {
	envelope.Draft
	// WaitS lets message.ask wait for the reply (max 600).
	WaitS int `json:"wait_s,omitempty"`
}

SendParams is message.send / message.ask / message.emit.

type SendResult

type SendResult struct {
	ID            string     `json:"id"`
	ThreadID      string     `json:"thread_id"`
	State         string     `json:"state"`
	Coalesced     bool       `json:"coalesced,omitempty"`
	CoalescedInto string     `json:"coalesced_into,omitempty"`
	Reply         *ReplyView `json:"reply,omitempty"`
	Ticket        string     `json:"ticket,omitempty"`
}

SendResult acknowledges a persisted message.

type Server

type Server struct {
	Auth     func(a Auth) (Caller, error)
	OnDenied func(method string, a Auth, err error)
	Log      *slog.Logger
	// contains filtered or unexported fields
}

Server serves JSON-RPC over a Unix socket.

func NewServer

func NewServer() *Server

NewServer returns a server with no methods.

func (*Server) Close

func (s *Server) Close()

Close stops accepting, cancels in-flight calls and closes connections.

func (*Server) Handle

func (s *Server) Handle(method string, h Handler)

Handle registers a method.

func (*Server) Listen

func (s *Server) Listen(path string) error

Listen binds the socket with mode 0600 inside a 0700 directory.

func (*Server) Methods

func (s *Server) Methods() []string

Methods lists registered method names.

func (*Server) Serve

func (s *Server) Serve() error

Serve accepts connections until Close.

type SessionActivity

type SessionActivity struct {
	Prompt   string        `json:"prompt,omitempty"`
	PromptAt time.Time     `json:"prompt_at,omitzero"`
	Tools    int           `json:"tools"`
	Steps    []SessionStep `json:"steps,omitempty"`
	Now      *SessionStep  `json:"now,omitempty"`
	WroteAt  time.Time     `json:"wrote_at,omitzero"`
}

SessionActivity is the newest exchange of a session: the human's prompt it answers, its tool calls so far (the last few, oldest first) and Now, the call without a result yet: the tool that runs, or the permission or question a waiting session shows in its tab. WroteAt is when the transcript last changed: a busy session that has not written for minutes may be stuck.

type SessionFocusParams

type SessionFocusParams struct {
	SessionID string `json:"session_id"`
}

SessionFocusParams is session.focus: bring the session's terminal tab to the front.

type SessionNewParams

type SessionNewParams struct {
	Dir  string `json:"dir"`
	Name string `json:"name,omitempty"`
	Term string `json:"term,omitempty"`
}

SessionNewParams is session.new: open a new terminal tab that runs claude in Dir, named Name (ADR-0015). Term picks the terminal ("Apple_Terminal", "iTerm.app", "tmux", "herdr"; "" = the daemon's default).

type SessionPromptParams

type SessionPromptParams struct {
	SessionID string `json:"session_id,omitempty"`
	Agent     string `json:"agent,omitempty"`
	// Name picks the session by its name (claude --name, /rename; case
	// does not matter); with no session of that name, it is an agent.
	Name string `json:"name,omitempty"`
	Text string `json:"text"`
	// Async returns once the session is checked: the text is typed in the
	// background and a session that took no turn shows Unsent.
	Async bool `json:"async,omitempty"`
}

SessionPromptParams is session.prompt: the human's text typed into an idle session. SessionID wins; with Agent alone, that agent must have exactly one idle session.

type SessionPromptResult

type SessionPromptResult struct {
	Agent     string `json:"agent"`
	SessionID string `json:"session_id"`
}

SessionPromptResult names the session that got the prompt.

type SessionSendParams

type SessionSendParams struct {
	SessionID string `json:"session_id,omitempty"`
	Name      string `json:"name,omitempty"`
	Text      string `json:"text"`
	Async     bool   `json:"async,omitempty"` // as in SessionPromptParams
}

SessionSendParams is session.send: the human writes to a session. An idle session gets the text typed in (session.prompt); a busy or waiting one sends it to a worker that resumes a fork of the session (ADR-0013).

type SessionSendResult

type SessionSendResult struct {
	Mode      string `json:"mode"`
	Agent     string `json:"agent"`
	SessionID string `json:"session_id"`
	MessageID string `json:"message_id,omitempty"`
}

SessionSendResult says where the text went: "typed" into the session or to a "worker" (MessageID is its ask).

type SessionStats

type SessionStats struct {
	Typed      int `json:"typed"`
	WorkerAsks int `json:"worker_asks"`
	AgentAsks  int `json:"agent_asks"`
	Focus      int `json:"focus"`
}

SessionStats counts what the human did with sessions: prompts typed into idle ones, asks a fork of a busy one answered (from the human, from agents), and tabs brought to the front.

type SessionStep

type SessionStep struct {
	Tool   string    `json:"tool"`
	Target string    `json:"target,omitempty"`
	At     time.Time `json:"at"`
	Done   bool      `json:"done"`
}

SessionStep is one tool call: the tool, what it works on (a command, a file, a question), when, and whether its result came back.

type SessionTail

type SessionTail struct {
	SessionID string        `json:"session_id"`
	Turns     []SessionTurn `json:"turns"`
}

SessionTail is the conversation of one interactive session, for the human only (it never goes into a session or to an agent).

type SessionTailParams

type SessionTailParams struct {
	SessionID string `json:"session_id"`
	Limit     int    `json:"limit,omitempty"` // default 20, at most 100
}

SessionTailParams is session.tail: the last turns of one session.

type SessionTurn

type SessionTurn struct {
	Role  string    `json:"role"`
	Text  string    `json:"text"`
	At    time.Time `json:"at"`
	Tools int       `json:"tools,omitempty"`
	From  string    `json:"from,omitempty"`
	State string    `json:"state,omitempty"`
}

SessionTurn is one prompt ("you") or answer ("claude") from a session's transcript, or a question to a fork of the session ("ask", From the asker) and its answer ("worker", with the ask's State) (ADR-0013). An answer counts its tool calls.

type SessionView

type SessionView struct {
	Agent   string `json:"agent"`
	Harness string `json:"harness"` // the coding agent: claude, codex (ADR-0019)
	Level   string `json:"level"`   // the support level: full | herdr | listed (ADR-0019)
	// Unverified marks a session whose provider no real session checked
	// (ADR-0019): read only, no typing and no fork.
	Unverified bool      `json:"unverified,omitempty"`
	SessionID  string    `json:"session_id"`
	Repo       string    `json:"repo"`
	Turn       string    `json:"turn"` // idle | busy | waiting | unknown
	TurnAt     time.Time `json:"turn_at,omitzero"`
	LastSeen   time.Time `json:"last_seen"`
	TTY        string    `json:"tty,omitempty"`
	Term       string    `json:"term,omitempty"`
	Title      string    `json:"title,omitempty"`
	LastPrompt string    `json:"last_prompt,omitempty"`
	// LastAnswer is the final message of the session's newest answer (its
	// text after the last tool call), from the transcript; LastAnswerAt is
	// when it came. Empty while the first answer is still working.
	LastAnswer   string    `json:"last_answer,omitempty"`
	LastAnswerAt time.Time `json:"last_answer_at,omitzero"`
	// CanPrompt is true when session.prompt would type into it now; Why
	// says what is missing otherwise.
	CanPrompt bool   `json:"can_prompt"`
	Why       string `json:"why,omitempty"`
	// Unsent says why the last prompt typed in the background started no
	// turn (since UnsentAt; cleared by the session's next turn).
	Unsent   string    `json:"unsent,omitempty"`
	UnsentAt time.Time `json:"unsent_at,omitzero"`
	// Activity is what the newest exchange does now, from the transcript
	// (nil when there is none).
	Activity *SessionActivity `json:"activity,omitempty"`
}

SessionView is one live interactive session (session.list, ADR-0012).

type StatsParams

type StatsParams struct {
	// Since is the start of the window (default: 14 days ago).
	Since time.Time `json:"since,omitempty"`
}

StatsParams is stats.get (human only, ADR-0011): counts over a window.

type StatsResult

type StatsResult struct {
	Since   time.Time  `json:"since"`
	Until   time.Time  `json:"until"`
	Total   StatsRow   `json:"total"`
	Agents  []StatsRow `json:"agents"`
	Days    []StatsRow `json:"days"`
	Replies int        `json:"replies"`
	// Sessions counts the session cockpit in the window (ADR-0012, 0013).
	Sessions SessionStats `json:"sessions"`
	// KeptFrom is where the retention window starts: older data is gone.
	KeptFrom time.Time `json:"kept_from"`
}

StatsResult is stats.get.

type StatsRow

type StatsRow struct {
	Key             string         `json:"key"`
	Inbound         int            `json:"inbound"`
	Auto            int            `json:"auto"`
	AutoBy          map[string]int `json:"auto_by,omitempty"` // handler → count
	NeededYou       int            `json:"needed_you"`
	Answered        int            `json:"answered"`
	Waiting         int            `json:"waiting"`
	CancelledNeeded int            `json:"cancelled_needed"`
	Cancelled       int            `json:"cancelled"`
	Dead            int            `json:"dead"`
	Rejected        int            `json:"rejected"`
	Expired         int            `json:"expired"`
	InProgress      int            `json:"in_progress"`
	Merged          int            `json:"merged"` // repeats coalesced into an existing message
	Runs            int            `json:"runs"`
	WorkerRuns      int            `json:"worker_runs"`
	CommandRuns     int            `json:"command_runs"`
	FailedRuns      int            `json:"failed_runs"`
	InputTokens     int64          `json:"input_tokens"` // incl. cache reads and writes
	OutputTokens    int64          `json:"output_tokens"`
	CostUSD         float64        `json:"cost_usd"` // as claude reports it
}

StatsRow counts one slice of the window: all, one agent or one day. Inbound = asks, tells and events created in the window (replies are counted apart). Each inbound message lands in exactly one outcome: Auto (done, never needs_human), Answered/Waiting/CancelledNeeded (it needed the human), Cancelled (rejected by the human without needing them), Dead, Rejected (by a guard or rule), Expired or InProgress.

type StatusView

type StatusView struct {
	Daemon  HealthView  `json:"daemon"`
	Agents  []AgentView `json:"agents"`
	Running []RunView   `json:"running"`
	DLQ     int         `json:"dlq"`
	Metrics Metrics     `json:"metrics"`
}

StatusView is agent.status (global when no agent is given).

type ThreadView

type ThreadView struct {
	ThreadID     string        `json:"thread_id"`
	Frozen       bool          `json:"frozen"`
	FrozenReason string        `json:"frozen_reason,omitempty"`
	Messages     []MessageView `json:"messages"`
	Runs         []RunView     `json:"runs"`
}

ThreadView is thread.get.

Jump to

Keyboard shortcuts

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