serve

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BusServiceName     = "messaging"
	BusHealthCheckName = "messaging-subscriptions"
)

BusServiceName is the bus's name in the controller. The health check takes a different one: a Controller enforces uniqueness only in the health-check map, so a collision is silently accepted and the report carries two entries under one name (0019 D7).

View Source
const (
	SubscriberName        = "log"
	RespondSubscriberName = "respond"
)

Subscription names. The log subscriber is the composition slice's consumer and stays as the operator's view of what arrived; respond is the answering path (0018 D6).

View Source
const DiscordServiceName = "discord"

DiscordServiceName is the transport's name in the controller, which is also how the health endpoints and the exhaustion poll refer to it.

View Source
const MinRefreshInterval = time.Minute

MinRefreshInterval is the shortest accepted refresh interval.

Every refresh clones the repositories that moved. A minute would put the bot in a permanent clone loop against the forge, which is a denial of service aimed at the project's own infrastructure.

Variables

View Source
var (
	// ErrExhausted is returned by Run when the Discord transport has used up
	// its restart allowance. The process exits non-zero so an orchestrator and
	// a bare process converge on replacing it (0018 OQ9).
	ErrExhausted = errors.NewSentinel("serve.exhausted",
		"serve: the discord transport exhausted its restarts")
)

Errors the daemon can end on.

Functions

func NewBus added in v0.5.0

func NewBus(log *slog.Logger, respond Handler) (*messaging.Bus, error)

NewBus builds the bus the gateway publishes onto, with the answering path subscribed. A nil respond handler declares only the log subscriber, for a process that has no answering path to wire.

func NewBusWithMode added in v0.5.0

func NewBusWithMode(log *slog.Logger, respond Handler, mode messaging.DeliveryMode) (*messaging.Bus, error)

NewBusWithMode is NewBus with the delivery mode exposed, so a test can prove D16 by asking for one this backend refuses.

Not a knob. AtMostOnce is D5, and the design stays inside core NATS's intersection deliberately so that reaching a broker stays the wiring change the spike measured rather than a redesign.

func NewCmdServe

func NewCmdServe(props *props.Props) *setup.Command

func Recovering added in v0.5.0

func Recovering(log *slog.Logger, name string, probe func() error) func() (err error)

Recovering wraps a probe so a panic inside it is a failed probe rather than a crashed supervisor: the controller calls Status bare (services.go:145).

func Refresher

func Refresher(sess *session.Session, p *props.Props, log *slog.Logger, interval time.Duration) *indexer.Service

Refresher builds the scheduled index refresher.

It goes through the same session the `index` commands open, so the scheduled and manual routes run one code path and cannot drift into disagreeing about what is indexed or where the index lives.

A failure here fails startup, deliberately. Building the provider makes no network call, so it can only fail on a configuration an operator can fix in seconds — and this project already refuses a bad configuration before anything binds or connects. A forge that is merely unreachable is a different thing: it surfaces later as a failed refresh, and is degraded rather than fatal.

func Responder added in v0.5.0

func Responder(
	ctx context.Context, log *slog.Logger, cfg Config, db *store.DB,
	asker respond.Asker, posterFor PosterFunc,
) (*respond.Service, error)

Responder builds the answering path over an answerer: the recorder and threads over the store, one Poster per configured guild, and the budget if one is configured (0018 D6, 0019 D19).

The answerer is a parameter because building it needs a model provider and its credentials, and everything else here is testable without one.

Shadow mode is the shipping state and this does not lift it (0010 D6): the answer is composed and recorded, and nothing is posted until a person has read enough of them to agree they are worth posting.

func Run added in v0.5.0

func Run(ctx context.Context, d Deps) error

Run registers the services and runs the controller until the context ends or the transport exhausts its restarts.

func RunServe

func RunServe(ctx context.Context, p *props.Props, _ *ServeOptions, _ []string) error

RunServe runs the daemon until the context is cancelled.

The command owns wiring and nothing else: configuration in, services registered, controller started, shutdown awaited. Every decision worth testing lives in pkg/transport and pkg/ingest, where it can be exercised against a fake rather than a live gateway.

Types

type Config

type Config struct {
	ingest.Config

	Transport transport.Config
	Index     IndexConfig
	Respond   RespondConfig
}

Config is everything the daemon needs.

The ingest configuration is embedded rather than named, so the guilds and health sections keep reading as they did before the index arrived.

func ConfigFromStore

func ConfigFromStore(store *config.Store) (Config, error)

ConfigFromStore reads the configuration from the live store.

func LoadConfig

func LoadConfig(r io.Reader) (Config, error)

LoadConfig reads, defaults and validates the configuration.

Validation happens here rather than at first use so a misconfiguration is reported before anything connects or binds. An operator should see "the allowlist is empty", not a connection error three layers downstream of it.

type Deps added in v0.5.0

type Deps struct {
	Config Config
	Log    *slog.Logger

	// Discord is the transport to supervise. Built from Config by RunServe.
	Discord *transport.Transport

	// Bus carries messages from the gateway to its subscribers, or nil for
	// none. Nil is for tests that exercise the transport alone.
	Bus *messaging.Bus

	// Refresher is the index refresher, or nil for none.
	Refresher *indexer.Service

	// Health is nil to skip the health listener (tests that do not want a
	// port), otherwise the listener settings.
	Health *ingest.HealthConfig

	// Poll overrides how often the exhaustion poll runs; zero means the
	// health interval.
	Poll time.Duration
}

Deps is what Run needs, separated from how RunServe obtains it so a test and the swap scenario can inject a fake client, a fake transport or no refresher at all.

type Handler added in v0.5.0

type Handler = func(context.Context, messaging.Delivery) error

Handler is a bus subscription's handler.

type IndexConfig

type IndexConfig struct {
	// RefreshInterval is how often the corpus is re-read.
	RefreshInterval time.Duration
}

IndexConfig is the resolved index configuration.

Deliberately does not carry index.path. That key has one reader — session.DBPath — shared with the `index` commands, and a second reader here would be the drift this whole wiring exists to avoid: `serve` refreshing one database while `index status` reports another.

type PosterFunc added in v0.5.0

type PosterFunc func(space chatplatform.ID) (*transport.Poster, error)

PosterFunc hands out the write path for a space. transport.Transport.Poster is the one serve uses; a func so Responder can be built against a fake.

type RespondConfig added in v0.5.0

type RespondConfig struct {
	ThreadWindow time.Duration
	AnswerBudget int
}

RespondConfig is the resolved respond section.

type ServeOptions

type ServeOptions struct{}

Jump to

Keyboard shortcuts

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