Documentation
¶
Index ¶
- Constants
- Variables
- func NewBus(log *slog.Logger, respond, feedback Handler) (*messaging.Bus, error)
- func NewBusWithMode(log *slog.Logger, respond, feedback Handler, mode messaging.DeliveryMode) (*messaging.Bus, error)
- func NewCmdServe(props *props.Props) *setup.Command
- func Purger(ctx context.Context, log *slog.Logger, db *store.DB) (*respond.Purger, error)
- func Recovering(log *slog.Logger, name string, probe func() error) func() (err error)
- func Refresher(sess *session.Session, p *props.Props, log *slog.Logger, ...) *indexer.Service
- func ReloadGuilds(log *slog.Logger, target GuildReloader) func(config.Observed) error
- func Responder(ctx context.Context, log *slog.Logger, cfg Config, db *store.DB, ...) (*respond.Service, error)
- func Run(ctx context.Context, d Deps) error
- func RunServe(ctx context.Context, p *props.Props, _ *ServeOptions, _ []string) error
- func ServerAskers(ctx context.Context, guilds []ingest.GuildConfig, db *store.DB, ...) ([]respond.Option, error)
- func WatchGuilds(store *config.Store, log *slog.Logger, target GuildReloader)
- type ClientFunc
- type Config
- type Deps
- type GuildReloader
- type Handler
- type IndexConfig
- type PosterFunc
- type RespondConfig
- type ServeOptions
Constants ¶
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).
const ( RespondSubscriberName = "respond" FeedbackSubscriberName = "feedback" )
Subscription names. There is no log subscriber: a line per message would keep what people wrote outside the policy's retention (spec 0028).
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.
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 ¶
var ( // ErrGaveUp is returned by Run when a required service fails for good: it // exhausts its restarts, fails to start with no restart policy, or dies // after a clean start. The process exits non-zero so an orchestrator and a // bare process converge on replacing it (0018 OQ9). ErrGaveUp = errors.NewSentinel("serve.gave_up", "serve: a required service gave up") )
Errors the daemon can end on.
var ErrNoSubscribers = errors.NewSentinel("serve.no_subscribers",
"serve: the message bus has no subscribers")
ErrNoSubscribers refuses a bus nothing would consume from. go/messaging accepts one since v0.2.1, for publish-only processes; serve is not one.
Functions ¶
func NewBus ¶ added in v0.5.0
NewBus builds the bus the gateway publishes onto, with the answering path subscribed to messages and feedback to votes (spec 0027). A nil handler declares no subscription; the bus refuses to be built with none.
func NewBusWithMode ¶ added in v0.5.0
func NewBusWithMode(log *slog.Logger, respond, feedback 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 Purger ¶ added in v0.6.0
Purger builds the scheduled question purge over the store the answering path records into, so the retention the policy publishes is enforced rather than promised (0010 D5a).
func Recovering ¶ added in v0.5.0
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 ReloadGuilds ¶ added in v0.10.1
ReloadGuilds is the observer WatchGuilds registers. A change that does not validate is refused whole, so the running configuration stays, and the log says why. It never returns an error: the refusal is reported here, where its reason is known.
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, extra ...respond.Option, ) (*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 default (0010 D6): the answer is composed and recorded, and nothing is posted, except in a server whose post_answers is set (0025).
func Run ¶ added in v0.5.0
Run registers the services and runs the controller until the context ends or a required service gives up.
func RunServe ¶
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.
func ServerAskers ¶ added in v0.11.0
func ServerAskers( ctx context.Context, guilds []ingest.GuildConfig, db *store.DB, shared chat.ChatClient, clientFor ClientFunc, ) ([]respond.Option, error)
ServerAskers gives each server with its own corpus or AI settings its own answering service (spec 0029 D5, D7, D9). A server with neither uses the process-wide asker, so it gets no option here. A server that keeps the process-wide provider and model shares its client.
func WatchGuilds ¶ added in v0.10.1
func WatchGuilds(store *config.Store, log *slog.Logger, target GuildReloader)
WatchGuilds hands each configuration change made while serve runs to target (issue 13). The store's watch is started by go-tool-base for every command.
Types ¶
type ClientFunc ¶ added in v0.11.0
ClientFunc builds a chat client for a provider and model, each empty for the process-wide ai.* value. ask.NewClientFor is the production one.
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 ¶
ConfigFromStore reads the configuration from the live store.
func LoadConfig ¶
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
// Purger enforces question retention, or nil for none.
Purger *respond.Purger
// Health is nil to skip the health listener (tests that do not want a
// port), otherwise the listener settings.
Health *ingest.HealthConfig
}
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 GuildReloader ¶ added in v0.10.1
GuildReloader takes a changed configuration. The transport is one: it applies what can change live and warns about what cannot.
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
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
RespondConfig is the resolved respond section.
type ServeOptions ¶
type ServeOptions struct{}