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

bus

package
v0.2.11 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const HostIdentitySubject = "rysh.bus.host.identity"

HostIdentitySubject is answered by the daemon that OWNS an embedded NATS server, so a guest can tell whose store it is writing into.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bus

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

Bus wraps either an embedded NATS server or an external connection. It exposes a plain *nats.Conn, two JetStream KV buckets, a proto.actor ActorSystem, a CodecRegistry, and a NATSPublisher.

func New

func New(cfg Config) (*Bus, error)

New creates and starts a Bus according to cfg.

func (*Bus) ActorSystem

func (b *Bus) ActorSystem() *actor.ActorSystem

ActorSystem returns the proto.actor ActorSystem.

func (*Bus) AgentKV

func (b *Bus) AgentKV() nats.KeyValue

AgentKV returns the KV bucket for agent/humanoid persistence.

func (*Bus) BoardKV added in v0.2.4

func (b *Bus) BoardKV() nats.KeyValue

BoardKV returns the per-session agents-board history bucket. It may be nil when JetStream is unavailable, in which case the board is live-only: posts are delivered and rendered but do not survive a restart.

func (*Bus) ClientPort

func (b *Bus) ClientPort() int

ClientPort returns the TCP port external CLI clients can connect to. Returns 0 if no TCP listener is available (e.g. external NATS mode).

func (*Bus) Close

func (b *Bus) Close()

Close shuts down the ActorSystem, drains the connection, and shuts down the embedded server (if any).

func (*Bus) Codecs

func (b *Bus) Codecs() *msg.CodecRegistry

Codecs returns the CodecRegistry.

func (*Bus) Conn

func (b *Bus) Conn() *nats.Conn

Conn returns the underlying NATS connection.

func (*Bus) FleetKV added in v0.2.6

func (b *Bus) FleetKV() nats.KeyValue

FleetKV returns the per-session fleet registry bucket (design 028).

func (*Bus) GuestOf added in v0.2.11

func (b *Bus) GuestOf() (GuestOf, bool)

GuestOf returns what this Bus knows about the server it joined as a guest; ok is false (and the value empty) when the Bus owns its server or is an external client.

func (*Bus) JS

func (b *Bus) JS() nats.JetStreamContext

JS returns the JetStream context.

func (*Bus) PaneKV

func (b *Bus) PaneKV() nats.KeyValue

PaneKV returns the KV bucket for pane snapshots.

func (*Bus) PipelineKV

func (b *Bus) PipelineKV() nats.KeyValue

PipelineKV returns the KV bucket for pipeline prompt persistence.

func (*Bus) Publisher

func (b *Bus) Publisher() *msg.NATSPublisher

Publisher returns the NATSPublisher for sending typed messages.

func (*Bus) SecretKV

func (b *Bus) SecretKV() nats.KeyValue

SecretKV returns the per-session secret store bucket. It may be nil when JetStream is unavailable, in which case secret resolution falls back to config + environment only.

func (*Bus) VariableKV

func (b *Bus) VariableKV() nats.KeyValue

VariableKV returns the per-session variable store bucket. It may be nil when JetStream is unavailable, in which case variable resolution falls back to config + environment only.

func (*Bus) WorkspaceKV

func (b *Bus) WorkspaceKV() nats.KeyValue

WorkspaceKV returns the KV bucket for workspace state.

type Config

type Config struct {
	Mode        string // "embedded" or "external"
	URL         string // NATS URL, used when Mode == "external"
	DataDir     string // JetStream storage directory (empty = auto)
	SessionName string // used to isolate data dirs per session
	// Port is the TCP port for the embedded NATS server. 0 means
	// kernel-assigned: a private server on a free port, never a probe of an
	// existing one. The 24242 default belongs to config, not to this package —
	// defaulting here is what once sent `port: 0` test daemons into the
	// developer's live NATS.
	Port int
	// Attach marks a client of a session some other process owns — the TUI of
	// `rysh attach`. The owning daemon has already declared every bucket, so an
	// attaching Bus looks them up instead: one StreamInfo per bucket rather than
	// an AccountInfo plus a stream create. A slow shared server used to fail
	// attach outright at "create rysh-workspace-<session> KV: context deadline
	// exceeded" while the daemon itself was fine.
	Attach bool
	// Workspace is this daemon's project root (the session record's Path). A
	// guest compares it with the host's; an owner answers it on
	// HostIdentitySubject. Design 028 §9 limit 7.
	Workspace string
	// HostQueryTimeout bounds a guest's question to the host daemon (0 = 300ms).
	HostQueryTimeout time.Duration
	// Logger receives the guest/host identity lines (nil = slog.Default()).
	Logger *slog.Logger
}

Config holds the settings needed to initialise a Bus.

type GuestOf added in v0.2.11

type GuestOf struct {
	ServerID      string `json:"server_id"`
	ServerName    string `json:"server_name,omitempty"`
	Port          int    `json:"port"`
	HostSession   string `json:"host_session"`             // "unknown" when the host did not answer
	HostWorkspace string `json:"host_workspace,omitempty"` // likewise; omitted from the public view
	HostPID       int    `json:"host_pid,omitempty"`
	UnknownReason string `json:"unknown_reason,omitempty"`
	Pending       bool   `json:"pending,omitempty"` // the host query is still in flight
	// Mismatch is the WARN-worthy case: the host belongs to another WORKSPACE
	// (ORDER-13, root-0273). Warning is set with it, and only with it.
	Mismatch bool `json:"mismatch"`
	// SessionMismatch / WorkspaceMismatch say exactly what differs. A host that
	// is another session of the SAME workspace (the desktop sidecar's daemon
	// under its own session name) is recorded in Note, at INFO, not warned.
	SessionMismatch   bool   `json:"session_mismatch"`
	WorkspaceMismatch bool   `json:"workspace_mismatch"`
	Note              string `json:"note,omitempty"`
	Warning           string `json:"warning,omitempty"`
}

GuestOf describes the server a guest Bus joined. Its JSON field names are what /health and `##rysh status` show under "guest_of".

func (GuestOf) Public added in v0.2.11

func (g GuestOf) Public() GuestOf

Public is the subset safe for the unauthenticated /health endpoint: it drops the host's filesystem path and PID, and rewords the warning without either workspace path. `##rysh status` still shows all of it.

type HostIdentity added in v0.2.11

type HostIdentity struct {
	Session   string `json:"session"`
	Workspace string `json:"workspace"`
	PID       int    `json:"pid"`
}

HostIdentity is the owning daemon's answer on HostIdentitySubject.

Jump to

Keyboard shortcuts

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