Documentation
¶
Overview ¶
Package opencodehost is muster-mirror's side of opencode v2's local server (docs/design/opencode.md): the pair token muster-mirror holds, the one client that reads the server's REST API and event stream with it, and the pairing step that mints the token in the first place.
🔴 ITS WRITES ARE ENUMERATED, BY CONSTRUCTION. Every request this package makes is a GET (Client.get, Client.stream), except: the two calls that mint a token — POST /api/pair and the unauthenticated GET /auth/connect/{code} — which only Pair and Credentials.Renew make (Client.mint); the answer to an ask (Client.reply); the API send (Client.prompt, from Prompt only); and the launcher's session create (Client.createSession, from CreateSession only). A test in this package reads its source and fails when any other request is spelled (TestTheClientMakesOnlyGETsExceptTheMintTheRepliesAndTheSend), and another drives every path against a fake server and fails on any request outside that set.
🔴 THE TOKEN AND THE SERVER PASSWORD ARE NEVER PRINTED OR LOGGED. What a person reads names a token by Fingerprint only.
Index ¶
- Constants
- Variables
- func CheckLocal(raw string) error
- func ContextLimit(models []Model, provider, id string) int64
- func DefaultRegistrationPaths(getenv func(string) string) []string
- func Expiry(token string) (time.Time, bool)
- func Fingerprint(token string) string
- func KeepReloaded(ctx context.Context, c *Credentials, logger *log.Logger, every time.Duration)
- func KeepRenewed(ctx context.Context, c *Credentials, logger *log.Logger, every time.Duration, ...)
- func LaunchDirDefault(home string) string
- func LaunchPath(dir, socket, pane string) (string, error)
- func MajorVersion(v string) (int, bool)
- func NewMessageID(now time.Time) string
- func NewSessionID(now time.Time) string
- func NormalizeVersion(v string) string
- func RemoveLaunch(dir string, r LaunchRecord) error
- func ValidFormID(id string) bool
- func ValidMessageID(id string) bool
- func ValidRequestID(id string) bool
- func ValidSessionID(id string) bool
- func WriteLaunch(dir string, r LaunchRecord) error
- func WriteTokenFile(path string, tf TokenFile) error
- type Admitted
- type Ask
- type AskKind
- type Client
- func (c *Client) AllSessions(ctx context.Context) (list []Session, complete bool, err error)
- func (c *Client) Commands(ctx context.Context, directory string) ([]Command, error)
- func (c *Client) CreateSession(ctx context.Context, id, directory string, model *ModelRef) (Session, error)
- func (c *Client) Events(ctx context.Context, connected func(), fn func(Event)) error
- func (c *Client) GetSession(ctx context.Context, id string) (Session, error)
- func (c *Client) Info(ctx context.Context) (string, error)
- func (c *Client) MCPStatus(ctx context.Context, directory string) (map[string]MCPServerStatus, error)
- func (c *Client) Messages(ctx context.Context, id string, limit int) ([]Message, error)
- func (c *Client) Models(ctx context.Context) ([]Model, error)
- func (c *Client) PendingAsks(ctx context.Context, id string) ([]Ask, error)
- func (c *Client) Prompt(ctx context.Context, session, messageID, text string) (Admitted, error)
- func (c *Client) RemoveSession(ctx context.Context, id string) error
- func (c *Client) ReplyForm(ctx context.Context, session, formID string, answer map[string]any) error
- func (c *Client) ReplyPermission(ctx context.Context, session, requestID string, decision PermissionReply) error
- func (c *Client) Running(ctx context.Context) (map[string]bool, error)
- func (c *Client) Sessions(ctx context.Context) ([]Session, error)
- func (c *Client) URL() string
- type Command
- type Content
- type Context
- type Credentials
- func (c *Credentials) Client() (*Client, error)
- func (c *Credentials) Expires() time.Time
- func (c *Credentials) Fingerprint() string
- func (c *Credentials) Health(now time.Time) string
- func (c *Credentials) HealthState(now time.Time) string
- func (c *Credentials) Loaded() bool
- func (c *Credentials) Reload() (changed bool, err error)
- func (c *Credentials) Renew(ctx context.Context, now time.Time) (renewed bool, err error)
- func (c *Credentials) URL() string
- type Event
- type Field
- type Keyed
- type LaunchRecord
- type MCPServerStatus
- type Match
- type Message
- type MessageModel
- type Model
- type ModelRef
- type PairResult
- type PermissionReply
- type Session
- type StatusError
- type TokenFile
- type Tokens
- type ToolState
Constants ¶
const EventSkipped = "muster.skipped"
EventSkipped is the Type of the frame Events hands fn in place of an event it could not read whole (a line over maxEventLine): the stream goes on, and the reader knows something was missed.
const LaunchVersion = 1
LaunchVersion is the record format this package writes and reads.
const MinMajorVersion = 2
MinMajorVersion is the oldest opencode major version muster works with: the one with the background service and the v2 server API muster pairs with.
const ReloadEvery = time.Minute
ReloadEvery is how often KeepReloaded re-reads the token file.
const RenewBefore = 10 * 24 * time.Hour
RenewBefore is how long before its expiry a token is replaced (Credentials.Renew): a third of its life, so a host that is off for a week still renews in time.
const RenewEvery = time.Hour
RenewEvery is how often KeepRenewed checks the token.
const TitlePrefix = "OC | "
TitlePrefix starts the pane title of a TUI showing a session.
const TokenTTL = 30 * 24 * time.Hour
TokenTTL is a pairing token's lifetime upstream (SESSION_TTL_SECONDS in packages/server/src/auth.ts at 6ec5682): 30 days.
const User = "opencode"
User is the HTTP Basic user every opencode credential goes with.
const WarnBefore = 3 * 24 * time.Hour
WarnBefore is how close to its expiry a token is reported to the person (Health) even while no renewal has failed: renewal starts at RenewBefore, so a token this close has not been renewed for a week.
Variables ¶
var ( // ErrSessionNotFound: the server has no such session (404). ErrSessionNotFound = errors.New("opencode has no such session (404)") // ErrPromptConflict: the message id names another session's message (409). ErrPromptConflict = errors.New("opencode refused the message id: it names a message of another session (409)") // ErrPromptRefused: the server refused the message (400). ErrPromptRefused = errors.New("opencode refused the message (400)") // ErrNotAdmitted: a 200 that does not name the message sent. ErrNotAdmitted = errors.New("opencode answered without admitting the message") )
Errors of a send. Each is the cause of what the host replies, so muster says which happened.
var ErrAnswerRefused = errors.New("opencode refused the answer")
ErrAnswerRefused: the server refused the answer itself (400): the field cannot take it. Nothing was answered.
var ErrAskSettled = errors.New("opencode: the ask is no longer pending")
ErrAskSettled: the server says the ask is no longer pending (404 for a permission request, 404 or 409 for a form): it was answered, rejected or cancelled elsewhere. Nothing was answered.
var ErrNoLaunch = errors.New("no launcher record for this pane")
ErrNoLaunch: there is no record for the pane.
var ErrNoRegistration = errors.New("no opencode service registration file")
ErrNoRegistration is Pair's error when none of the registration files exists: opencode's background service (opencode 2 or later) writes one when it runs, and opencode 1 has no such service. The caller says which case it is (it can run `opencode --version`; MinMajorVersion, MajorVersion).
var ErrNotRenewable = errors.New("this opencode token has no token file, so it is not renewed: pair the host (muster-mirror opencode-pair)")
ErrNotRenewable: a fixed token (EnvCredentials) has no file to keep a new one in.
ErrUnauthorized: the server refused the credential (401). For a pair token: it expired, or the server's password was rotated (which revokes every token at once).
var RegistrationNames = []string{"service-prod.json", "service.json"}
RegistrationNames are the registration file's names Pair looks for, in order: the Nix build's channel, then the default channels'.
Functions ¶
func CheckLocal ¶
CheckLocal refuses a server URL that is not http://<loopback>:<port>.
func ContextLimit ¶ added in v0.189.0
ContextLimit is the context window of model id of provider in models (GET /api/model's limit.context), 0 when the list does not name it or names no limit.
func DefaultRegistrationPaths ¶
DefaultRegistrationPaths is where the registration file can be: each of RegistrationNames under $XDG_STATE_HOME/opencode, else ~/.local/state/opencode. nil when neither base is known.
func Expiry ¶
Expiry is when token stops being accepted: its "<expires>." prefix, Unix seconds (the upstream token is "<expires>.<base64url HMAC>"). false when token is not of that shape.
func Fingerprint ¶
Fingerprint names a token for a person without revealing it: the first 8 hex digits of its SHA-256. The only thing about a token any output of muster-mirror prints.
func KeepReloaded ¶ added in v0.135.0
KeepReloaded re-reads c's file (Reload) every `every` until ctx ends, logging each change by fingerprint only. It never renews the token. A file that appears after the start (c a PendingCredentials: the host was paired since) is picked up the same way as a renewed or re-paired one. A failure is logged when it first happens and again only when it changes, so a file that does not exist yet is not logged every `every`.
func KeepRenewed ¶
func KeepRenewed(ctx context.Context, c *Credentials, logger *log.Logger, every time.Duration, now func() time.Time)
KeepRenewed renews c (Renew) now and every RenewEvery until ctx ends, logging each renewal and each failure by fingerprint only. It returns at once for a token that cannot be renewed (logging so).
func LaunchDirDefault ¶ added in v0.160.0
LaunchDirDefault is the records' directory under home.
func LaunchPath ¶ added in v0.160.0
LaunchPath is the record file of pane on the tmux server at socket.
func MajorVersion ¶ added in v0.232.0
MajorVersion is the major version in `opencode --version`'s output ("opencode v2.0.32+6ec5682", "1.19.5"), and false when there is none.
func NewMessageID ¶ added in v0.160.0
NewMessageID is a fresh message id in upstream's format: "msg_", 12 hex digits of the (time-ascending) millisecond counter, 14 random characters.
func NewSessionID ¶ added in v0.160.0
NewSessionID is a fresh session id in upstream's own format: "ses_", 12 hex digits of the bit-inverted (time-DESCENDING) millisecond counter, 14 random characters — so a launcher-made session sorts among the TUI's own.
func NormalizeVersion ¶ added in v0.172.0
NormalizeVersion is v without "opencode " and a leading "v": `opencode --version` says "opencode v2.0.32+6ec5682", GET /api/info "2.0.32+6ec5682" (both measured on that build). THE one rule the launcher (`muster-mirror opencode`) and the host spawn compare a TUI's version and the service's by.
func RemoveLaunch ¶ added in v0.160.0
func RemoveLaunch(dir string, r LaunchRecord) error
RemoveLaunch deletes pane's record, if it is still the one named by session and pid (a newer launch in the pane is left alone).
func ValidFormID ¶ added in v0.138.0
ValidFormID reports whether id is a form id ("frm_…", Form.ID's pattern).
func ValidMessageID ¶ added in v0.160.0
ValidMessageID reports whether id is a message id muster posts: "msg_" and up to 64 more bytes of [0-9A-Za-z] (upstream's pattern is "^msg_").
func ValidRequestID ¶ added in v0.138.0
ValidRequestID reports whether id is a permission request id ("per…", Permission.ID's pattern "^per").
func ValidSessionID ¶
ValidSessionID reports whether id is a session id this client asks about: "ses" and up to 125 more bytes of [0-9A-Za-z_-] (Session.ID's pattern is "^ses"; muster's wire bound is 128).
func WriteLaunch ¶ added in v0.160.0
func WriteLaunch(dir string, r LaunchRecord) error
WriteLaunch writes r as its pane's record under dir.
func WriteTokenFile ¶
WriteTokenFile replaces the token file at path with tf, whole and 0600 (atomicfile), creating its directory 0700 when missing.
Types ¶
type Admitted ¶ added in v0.160.0
type Admitted struct {
ID string `json:"id"`
SessionID string `json:"sessionID"`
Delivery string `json:"delivery"`
Payload struct {
Text string `json:"text"`
} `json:"payload"`
}
Admitted is a prompt the server admitted (Session.Inbox.User).
type Ask ¶ added in v0.138.0
type Ask struct {
Kind AskKind
// ID is the request's ("per…") or form's ("frm_…") id; Session the session
// that asks (a subagent's child session, possibly).
ID, Session string
// A permission request's action ("bash", "edit", …) and resources (the
// command, the paths).
Action string
Resources []string
// A form's title and fields.
Title string
Fields []Field
}
Ask is one pending permission request or form of a session.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client reads one opencode server.
func NewClient ¶
NewClient is a client of the server at base (CheckLocal), authenticating with secret() — a pair token, or (Pair only) the server password — read at each request, so a renewed token is used from the next request on.
func (*Client) AllSessions ¶ added in v0.189.0
AllSessions is every session the server knows, ROOTS AND CHILDREN (a subagent's: ParentID set) — GET /api/session with no parentID filter, measured to list both — newest first, at most maxSessionPages pages. complete is false when the bound cut the list short (its last page still named a next one): what it holds is then NOT every session.
func (*Client) Commands ¶ added in v0.160.0
Commands is the server's slash commands for directory. 🔴 The list depends on it (measured: without one the server answered none; with the session's, its built-ins).
func (*Client) CreateSession ¶ added in v0.160.0
func (c *Client) CreateSession(ctx context.Context, id, directory string, model *ModelRef) (Session, error)
CreateSession creates a root session with id in directory (an absolute path), on model when it is not nil (the session's first turn runs on it: measured on v2.0.32+6ec5682, an OpenRouter model's assistant messages name it). 🔴 ONE OF THE PACKAGE'S WRITES (ledger_test.go). Its callers are the launcher (`muster-mirror opencode`, no model) and the host spawn (internal/mirrorhost, with one), and no other: a caller ledger pins the two. It runs nothing. 🔴 opencode does NOT check the model (measured: an unknown one is created all the same), so a caller checks it against Models first.
func (*Client) Events ¶
Events reads the server's event stream until ctx ends or the stream does, calling fn for each frame in order; connected is called once the server has accepted the request (before any frame). It returns ErrUnauthorized for a refused credential, and otherwise the reason the stream ended.
A line longer than maxEventLine does NOT end the stream: it is discarded as it is read (never held whole), its event is dropped, and fn is called with an Event of Type EventSkipped instead.
func (*Client) GetSession ¶ added in v0.160.0
GetSession is GET /api/session/{id}: ErrSessionNotFound when there is none.
func (*Client) Info ¶
Info is GET /api/info: the server's version (the one call that proves a credential without reading any session).
func (*Client) MCPStatus ¶ added in v0.287.0
func (c *Client) MCPStatus(ctx context.Context, directory string) (map[string]MCPServerStatus, error)
MCPStatus is GET /api/mcp for directory: each configured MCP server's state, by name. Measured on v2.3.2: the list is empty until a session in that directory exists (its servers start then), then {name, status: {status, error?}}.
func (*Client) Messages ¶
Messages is session id's newest limit messages, OLDEST FIRST (GET /api/session/{id}/message, order=desc, reversed).
func (*Client) Models ¶ added in v0.172.0
Models is GET /api/model: every model the server can run now. ⚠ Upstream calls the answer a snapshot that "may precede initial plugin settlement"; measured on v2.0.32+6ec5682 (three restarts), the first answer after a restart already listed every OpenRouter model, and a server with no OpenRouter credential lists none at all.
func (*Client) PendingAsks ¶ added in v0.138.0
PendingAsks is session id's pending permission requests and forms (GET /api/session/{id}/permission and /form), requests first.
func (*Client) Prompt ¶ added in v0.160.0
Prompt posts text to session under messageID, delivery "queue", and returns the admitted record: the one stored first, when messageID was posted before. 🔴 ONE OF THE PACKAGE'S WRITES (ledger_test.go): only the host's gated send calls it.
func (*Client) RemoveSession ¶ added in v0.172.0
RemoveSession deletes session id (DELETE /api/session/{id}, session.remove): measured, 204, then 404 for the same id again, which is reported as ErrSessionNotFound. 🔴 ONE OF THE PACKAGE'S WRITES (ledger_test.go): only the host spawn calls it, for the session IT created when the spawn fails before its first prompt — nothing has run in it.
func (*Client) ReplyForm ¶ added in v0.138.0
func (c *Client) ReplyForm(ctx context.Context, session, formID string, answer map[string]any) error
ReplyForm answers form formID of session with answer: each field's key to its value (a label, or labels for a multiselect).
func (*Client) ReplyPermission ¶ added in v0.138.0
func (c *Client) ReplyPermission(ctx context.Context, session, requestID string, decision PermissionReply) error
ReplyPermission answers permission request requestID of session with decision: once or reject. "always" widens the session's rules past this one call, so muster never sends it — refused here, before a byte is sent.
type Content ¶
type Content struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
// ID and Name: a tool call's.
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
State ToolState `json:"state,omitempty"`
}
Content is one item of an assistant message's content: text, reasoning or tool.
type Context ¶ added in v0.189.0
Context is a session's context fill: Tokens of the model ModelID (of ProviderID) — the newest assistant message's that reported usage.
type Credentials ¶
type Credentials struct {
// Path is the token file; "" only for a test's fixed token
// (EnvCredentials), which cannot be renewed.
Path string
// contains filtered or unexported fields
}
Credentials is the pair token muster-mirror reads opencode with, and the file it lives in. Renew replaces it before it expires — a token can mint its own replacement (POST /api/pair is accepted with a token wherever the password is) — and writes the new one to the same file, 0600.
func EnvCredentials ¶
func EnvCredentials(base, token string) (*Credentials, error)
EnvCredentials is a fixed token for the server at base (CheckLocal), never renewed. 🔴 FOR TESTS AND THE BROWSER SUITE'S FAKE HOST (cmd/muster-mirror's e2emirror build) ONLY: the daemon takes its token from the token file alone, because a token it cannot renew stops working, silently, 30 days on.
func LoadCredentials ¶
func LoadCredentials(path string) (*Credentials, error)
LoadCredentials reads the token file at path (ReadTokenFile).
func PendingCredentials ¶ added in v0.135.0
func PendingCredentials(path string) *Credentials
PendingCredentials is a READER's credential for a token file that cannot be read yet (not paired, say): it holds no token (Loaded is false) until Reload finds a usable file at path. Only for a muster-mirror that never renews (-opencode-read-only): KeepReloaded then picks up the file tenant default's daemon or `muster-mirror opencode-pair` writes later.
func (*Credentials) Client ¶
func (c *Credentials) Client() (*Client, error)
Client is a client of the token's server that authenticates with the current token at each request, and reports what each authenticated read says about the token to Health (observe).
func (*Credentials) Expires ¶
func (c *Credentials) Expires() time.Time
Expires is when the current token stops being accepted.
func (*Credentials) Fingerprint ¶
func (c *Credentials) Fingerprint() string
Fingerprint names the current token for a person (the package's Fingerprint).
func (*Credentials) Health ¶
func (c *Credentials) Health(now time.Time) string
Health is what the person must be told about the token at now, "" when nothing: that it EXPIRED; that it expires soon while renewal is FAILING (and why); or that it expires within WarnBefore. 🔴 THE ONE SPELLING: the rendered view of an opencode window shows it, and `-list -opencode` prints it, so a renewal that keeps failing is seen in muster, not only in a log.
func (*Credentials) HealthState ¶
func (c *Credentials) HealthState(now time.Time) string
HealthState is Health's STATE, without the countdown: "" for nothing, else "expired", "refused", "unreachable: <why>", "failing: <why>" or "soon". It changes only when what the person must do changes, so a view redraws on it rather than on every tick of "expires in …".
func (*Credentials) Loaded ¶ added in v0.135.0
func (c *Credentials) Loaded() bool
Loaded reports whether c holds a token: false only for a PendingCredentials whose file has not yet been read.
func (*Credentials) Reload ¶ added in v0.135.0
func (c *Credentials) Reload() (changed bool, err error)
Reload re-reads the token file and, when it holds a different token, uses that one from now on. It never mints: it is how a READER of the file (a muster-mirror run with -opencode-read-only) follows the renewals another daemon writes. changed is false, with no error, when the file is unchanged. A file that cannot be read leaves the current token in use.
func (*Credentials) Renew ¶
Renew replaces the token when it expires within RenewBefore of now: it mints a new one with the current token, checks it outlives the old one, writes it to the token file (0600, whole) and only then uses it. renewed is false, with no error, when the token is not yet due.
🔴 THE FILE IS WRITTEN BEFORE THE NEW TOKEN IS USED: a muster-mirror that dies between the two restarts on the new token, never on one it has already replaced. Both tokens stay valid until their own expiry (tokens are stateless upstream), so the order costs nothing.
func (*Credentials) URL ¶
func (c *Credentials) URL() string
URL is the server the token was minted by (a loopback url, not a secret).
type Event ¶
type Event struct {
ID string `json:"id"`
Type string `json:"type"`
Data json.RawMessage `json:"data"`
}
Event is one frame of the event stream (GET /api/event).
func (Event) AskEvent ¶ added in v0.138.0
AskEvent is what an event says about an ask: one raised (Raised), or one settled (Settled names it, by its id) — answered, rejected or cancelled, in the terminal or anywhere else. ok false: the event is about no ask.
func (Event) ParentOf ¶ added in v0.138.0
ParentOf is the parent a session.created event names for its session: "" for a root session, or any other event.
func (Event) Status ¶
Status is the status an event says its session has now: a session.status event's type (idle, busy, retry) — and, because the v2 server at 6ec5682 never publishes session.status (only its schema declares it; measured against a real `opencode serve`, testdata/abort-v2.0.32.sse), the turn's own lifecycle: session.execution.started is busy, and its one terminal event (succeeded, failed, interrupted; packages/core/src/session/ execution.ts) idle. "" for any other event.
type Field ¶ added in v0.138.0
type Field struct {
Key string `json:"key"`
Type string `json:"type"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Options []struct {
Value string `json:"value"`
Label string `json:"label"`
} `json:"options,omitempty"`
Custom bool `json:"custom,omitempty"`
}
Field is one question of a form, as much of it as muster reads.
type Keyed ¶
type Keyed struct {
Key string
Event cctranscript.Event
}
Keyed is one event of a message and its key within the message.
type LaunchRecord ¶ added in v0.160.0
type LaunchRecord struct {
V int `json:"v"`
Socket string `json:"socket"`
Pane string `json:"pane"`
PID int `json:"pid"`
PIDStart string `json:"pidStart"`
Session string `json:"session"`
Server string `json:"server"`
Directory string `json:"directory"`
Created int64 `json:"created"`
}
LaunchRecord is one launch: the TUI running in Pane of the tmux server at Socket, whose process is PID (started at PIDStart, /proc/<pid>/stat field 22, so a reused pid does not match), shows Session of the opencode server at Server.
func ReadLaunch ¶ added in v0.160.0
func ReadLaunch(dir, socket, pane string) (LaunchRecord, error)
ReadLaunch is pane's record on the tmux server at socket: ErrNoLaunch when there is none, an error when it cannot be read or is not a record — or names another pane or tmux server than the path it was found at.
type MCPServerStatus ¶ added in v0.287.0
MCPServerStatus is one MCP server's state as GET /api/mcp reports it: Status "connected", "failed" (with Error), or another state on the way.
type Match ¶
type Match struct {
// Session is the one root session the title names; "" for none.
Session string
// Title is the title as the pane shows it (prefix stripped).
Title string
// Truncated: the pane's title was cut ("…"), so it was a prefix match.
Truncated bool
// Why says why there is no session; "" when there is one.
Why string
}
Match is how a pane title resolved: the session, or why none.
func MatchTitle ¶
MatchTitle resolves pane title paneTitle against sessions (the server's root sessions; a child, should one be passed, is never matched).
type Message ¶
type Message struct {
ID string `json:"id"`
Type string `json:"type"`
Time struct {
Created float64 `json:"created"`
Completed float64 `json:"completed,omitempty"`
} `json:"time"`
// Text: user, synthetic, system, skill.
Text string `json:"text,omitempty"`
// Description: synthetic, system.
Description string `json:"description,omitempty"`
// Content, Finish and Error: assistant (Error also idle).
Content []Content `json:"content,omitempty"`
Finish string `json:"finish,omitempty"`
Error json.RawMessage `json:"error,omitempty"`
// Outcome: idle (succeeded, failed, interrupted).
Outcome string `json:"outcome,omitempty"`
// Name: skill. Command, Status: shell.
Name string `json:"name,omitempty"`
Command string `json:"command,omitempty"`
Status string `json:"status,omitempty"`
// Model and Tokens: assistant (usage.go). Tokens is nil until the step
// has reported its usage (a step still streaming has none).
Model *MessageModel `json:"model,omitempty"`
Tokens *Tokens `json:"tokens,omitempty"`
}
Message is one entry of a session's messages (Session.Message.Info, a union keyed by Type), as much of it as muster reads. The union's members share their field names, so one struct holds every one of them.
type MessageModel ¶ added in v0.189.0
MessageModel is the model an assistant message ran on.
type Model ¶ added in v0.172.0
type Model struct {
ID string `json:"id"`
ModelID string `json:"modelID,omitempty"`
ProviderID string `json:"providerID"`
Status string `json:"status,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
// Limit is the model's token limits (Model.Info.limit): Context, its
// context window, is the readout's denominator (usage.go).
Limit struct {
Context int64 `json:"context"`
} `json:"limit"`
}
Model is one model the server lists (GET /api/model, Model.Info), as much of it as muster reads.
type ModelRef ¶ added in v0.172.0
ModelRef is opencode's Model.Ref (packages/schema/src/model.ts at 6ec5682): a model by its provider and its id within that provider.
type PairResult ¶
type PairResult struct {
Registration string
URL string
TokenFile string
Fingerprint string
Expires time.Time
// Replaced is the fingerprint of the token the file held before, "" for
// none.
Replaced string
}
PairResult is what Pair did, for a person: nothing in it is a secret.
type PermissionReply ¶ added in v0.138.0
type PermissionReply string
PermissionReply is a permission request's answer as upstream spells it.
const ( PermissionOnce PermissionReply = "once" PermissionAlways PermissionReply = "always" PermissionReject PermissionReply = "reject" )
type Session ¶
type Session struct {
ID string `json:"id"`
ParentID string `json:"parentID,omitempty"`
Title string `json:"title,omitempty"`
// Location is where the session runs (its directory): the slash
// commands it can run depend on it.
Location struct {
Directory string `json:"directory,omitempty"`
} `json:"location"`
Time struct {
Created float64 `json:"created"`
Updated float64 `json:"updated"`
} `json:"time"`
}
Session is one opencode session (Session.Info), as much of it as muster reads.
type StatusError ¶ added in v0.160.0
StatusError is an answer other than 200 (and 401, ErrUnauthorized) to a read.
func (*StatusError) Error ¶ added in v0.160.0
func (e *StatusError) Error() string
type TokenFile ¶
TokenFile is what the token file holds: the server it was minted by and the token itself. JSON, mode 0600, written whole (atomicfile).
The URL is written by Pair from the server's own registration file, so the daemon finds the server without ever reading that file (which also holds the server password).
func ReadTokenFile ¶
ReadTokenFile reads the token file at path. It refuses a symlink, anything that is not a regular file, and a file group or others can read: the token reaches the whole opencode API.
type Tokens ¶ added in v0.189.0
type Tokens struct {
Input int64 `json:"input"`
Output int64 `json:"output"`
Reasoning int64 `json:"reasoning"`
Cache struct {
Read int64 `json:"read"`
Write int64 `json:"write"`
} `json:"cache"`
}
Tokens is an assistant message's token counts, as opencode reports them (Session.Message.Assistant.tokens at 6ec5682).
type ToolState ¶
type ToolState struct {
Status string `json:"status,omitempty"`
Input json.RawMessage `json:"input,omitempty"`
}
ToolState is a tool call's state: streaming (Input is the raw text so far), running, completed or error (Input an object).
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package opencodetest is a FAKE opencode v2 server for muster's tests and browser suite: the routes muster-mirror reads (shaped from upstream's packages/protocol/openapi.json at 6ec5682), HTTP Basic auth with user "opencode", and pair tokens signed the way upstream signs them (packages/server/src/auth.ts), so a token it issues has the real shape and lifetime.
|
Package opencodetest is a FAKE opencode v2 server for muster's tests and browser suite: the routes muster-mirror reads (shaped from upstream's packages/protocol/openapi.json at 6ec5682), HTTP Basic auth with user "opencode", and pair tokens signed the way upstream signs them (packages/server/src/auth.ts), so a token it issues has the real shape and lifetime. |