Help us shape the future of Go! Take the 2026 Go Developer Survey

daemonthread

package
v0.239.0-rc.7 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrOffline = errors.New("lost the connection to infer daemon, reconnecting")

ErrOffline is what a request gets while the daemon connection is down.

Functions

func Marker

func Marker(frame []byte) string

Marker reports which connection marker a frame Next returned is, or "".

Types

type Agent

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

Agent is the chat TUI's agent in daemon mode: each turn runs on the thread's worker, wherever it runs, and comes back decoded into the chat events the TUI renders. The TUI's conversation is a mirror of the worker's, written as events arrive and reconciled from the worker when a turn ends.

func NewAgent

NewAgent builds the daemon-mode agent over thread, mirroring into repo.

func (*Agent) BuildSystemPrompt

func (a *Agent) BuildSystemPrompt() string

func (*Agent) CancelRequest

func (a *Agent) CancelRequest(string) error

CancelRequest interrupts the thread's open run.

func (*Agent) GetMetrics

func (a *Agent) GetMetrics(string) *agentdomain.ChatMetrics

func (*Agent) GetReasoningEffort

func (a *Agent) GetReasoningEffort() string

func (*Agent) RunWithStream

func (a *Agent) RunWithStream(ctx context.Context, req *agentdomain.AgentRequest) (<-chan agentdomain.ChatEvent, error)

RunWithStream sends the user's new messages to the thread, or with none follows the run another client started, and streams the run's events. The stream ends once the run finished and the conversation was reconciled.

func (*Agent) SetReasoningEffort

func (a *Agent) SetReasoningEffort(string) error

type Models

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

Models is the chat TUI's model service in daemon mode: the models the thread's worker can use, and the one its turns run on.

func NewModels

func NewModels(thread *Thread) *Models

NewModels builds the daemon-mode model service over thread.

func (*Models) GetCurrentModel

func (m *Models) GetCurrentModel() string

func (*Models) IsModelAvailable

func (m *Models) IsModelAvailable(modelID string) bool

IsModelAvailable reports whether the worker lists modelID. Before the first listing every model counts as available.

func (*Models) ListModels

func (m *Models) ListModels(ctx context.Context) ([]string, error)

ListModels asks the worker for its models, adopting its current one when the TUI has not picked one yet. Their context windows, prices and modalities, which the worker fetched from its gateway, are recorded here too, so the model picker shows them.

func (*Models) SelectModel

func (m *Models) SelectModel(modelID string) error

SelectModel switches the model the thread's next turns use. The worker learns it when the next turn starts, so a pick made offline is not lost.

func (*Models) ValidateModel

func (m *Models) ValidateModel(modelID string) error

type Options

type Options struct {
	ProjectDir string
}

Options name the project a daemon chat runs its threads in.

type Storage

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

Storage is the chat TUI's conversation storage in daemon mode: the thread's worker stores every conversation, and the TUI reads them over the binding. Writes are the worker's own, so saving here does nothing.

func NewStorage

func NewStorage(thread *Thread) *Storage

NewStorage builds the daemon-mode conversation storage over thread.

func (*Storage) Close

func (s *Storage) Close() error

func (*Storage) DeleteConversation

func (s *Storage) DeleteConversation(context.Context, string) error

func (*Storage) Health

func (s *Storage) Health(context.Context) error

Health reports whether the daemon connection is up.

func (*Storage) ListConversations

func (s *Storage) ListConversations(ctx context.Context, _ string, _, offset int) ([]convdomain.ConversationSummary, error)

ListConversations lists the conversations of the environment the session runs on, in the worker's project.

func (*Storage) ListConversationsNeedingTitles

func (s *Storage) ListConversationsNeedingTitles(context.Context, int) ([]convdomain.ConversationSummary, error)

func (*Storage) LoadConversation

func (s *Storage) LoadConversation(ctx context.Context, conversationID string) ([]convdomain.ConversationEntry, convdomain.ConversationMetadata, error)

LoadConversation follows the conversation's thread and reads the conversation as its worker stored it.

func (*Storage) UpdateConversationMetadata

func (s *Storage) UpdateConversationMetadata(context.Context, string, convdomain.ConversationMetadata) error

type Thread

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

Thread is the chat TUI's connection to the local daemon's binding and to the one thread it follows there. Frames never block the socket: run frames queue for the request that reads them, replies go to their waiters, and UI notifications leave through a queue of their own.

func New

func New(cfg *config.Config, opts Options, leases agentdomain.LeaseStore) *Thread

New builds the thread connection for a daemon chat in opts.ProjectDir. It reads the session's lease from leases to tell where it runs.

func (*Thread) Attach

func (t *Thread) Attach(*agui.Conn)

func (*Thread) CancelTeleport

func (t *Thread) CancelTeleport() error

CancelTeleport stops the running teleport, which leaves the session here.

func (*Thread) Close

func (t *Thread) Close()

Close stops reconnecting and hangs up.

func (*Thread) Connect

func (t *Thread) Connect(ctx context.Context) error

Connect dials the local daemon, starting it when nothing listens on the binding, and fails fast when the binding cannot authenticate the TUI.

func (*Thread) Consume

func (t *Thread) Consume() func()

Consume marks a request as the reader of the run frames until the returned release runs, so a run it started does not ask the TUI to follow it. A run that started while the request was finishing, as an accepted plan's does, asks once the release runs. A request may start before the last one's release ran, so only the last release does.

func (*Thread) Detach

func (t *Thread) Detach(conn *agui.Conn)

Detach notes the dropped connection: waiting requests fail, the request reading run frames learns of it, and reconnecting starts.

func (*Thread) DiscardSettled

func (t *Thread) DiscardSettled()

DiscardSettled drops queued frames of runs that already ended, which the reconcile of the next turn's history covers, so a new turn reads only what is still to come.

func (*Thread) Follow

func (t *Thread) Follow(ctx context.Context, id string, opts sessionsdomain.ThreadOptions) error

Follow makes the connection follow the conversation id, creating it on the worker when it does not exist yet. opts apply when the daemon starts the thread's worker, and a session that runs remotely is followed there.

func (*Thread) Follows

func (t *Thread) Follows(id string) bool

Follows reports whether the connection follows the conversation id, which it also does once a rollover or an accepted plan moved the thread on to id.

func (*Thread) Generation

func (t *Thread) Generation() int

Generation counts the connections to the daemon, since a daemon that restarted meanwhile runs a fresh worker behind the same thread.

func (*Thread) Handle

func (t *Thread) Handle(_ *agui.Conn, data []byte)

Handle routes one daemon frame without blocking the socket.

func (*Thread) ListEnvironments

func (t *Thread) ListEnvironments(ctx context.Context) ([]agentdomain.EnvironmentStatus, error)

ListEnvironments asks the daemon for every environment it knows, the local one first, with whether each is reachable.

func (*Thread) Live

func (t *Thread) Live() string

Live is the conversation the followed thread holds now.

func (*Thread) MoveTo

func (t *Thread) MoveTo(projectDir string)

MoveTo makes this a daemon chat in projectDir. It is for attaching, before the thread follows a session, since every request names the project dir.

func (*Thread) Next

func (t *Thread) Next(ctx context.Context) ([]byte, error)

Next returns the next run frame, waiting for one.

func (*Thread) Pending

func (t *Thread) Pending() bool

Pending reports whether run frames wait to be read.

func (*Thread) Placement

func (t *Thread) Placement() tui.SessionPlacement

Placement is where the followed session runs.

func (*Thread) Request

func (t *Thread) Request(ctx context.Context, frame any, replyType string) ([]byte, error)

Request sends frame and returns the first reply of replyType, or the error a RUN_ERROR without a run carries in its place.

func (*Thread) Running

func (t *Thread) Running() bool

Running reports whether the followed thread has an open run.

func (*Thread) Send

func (t *Thread) Send(frame any) error

Send writes one frame to the daemon.

func (*Thread) SessionProject

func (t *Thread) SessionProject(ctx context.Context, id string) string

SessionProject is the project dir of a session this machine's daemon runs, from its lease, or "" when another environment runs it or no lease names one.

func (*Thread) SetNotifier

func (t *Thread) SetNotifier(notifier agentdomain.UINotifier)

SetNotifier hands the thread the UI it reports to once the TUI runs.

func (*Thread) SetSynced

func (t *Thread) SetSynced(id string, n int)

SetSynced records that the worker has the first n entries of id.

func (*Thread) Synced

func (t *Thread) Synced(id string) int

Synced is how many entries of conversation id the worker already has, so a turn sends only the user's new messages.

func (*Thread) Teleport

func (t *Thread) Teleport(target string, files []string) error

Teleport starts teleporting the followed session to target. Progress arrives as TeleportProgressEvent, and the teleport as a SessionPlacementChangedEvent.

func (*Thread) Unfollowed

func (t *Thread) Unfollowed() bool

Unfollowed reports whether a run started, or one suspended on a prompt was replayed, with no turn reading the thread since, or a run is under way. A chat that attached before its UI could take the follow request still owes it.

Jump to

Keyboard shortcuts

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