Documentation
¶
Overview ¶
Package integrations is the daemon's integration event bus: it turns the project's append-only event log -- the same source the SSE endpoint streams -- into a small vocabulary of typed domain events, and delivers them to subscribers (Slack, Linear) through a persistent outbox.
The engine never calls into this package. Every state change already appends an event in the same SQLite transaction as the change itself (store.Apply), so the bus only has to TAIL that log: a slow or down Slack can delay a notification but can never hold a workflow transaction open, fail an apply, or lose an event the engine committed. Delivery is at-least-once per (subscriber, event), made effectively-once by a unique idempotency key on the outbox row; see Dispatcher.
Index ¶
- Variables
- func IsPermanent(err error) bool
- func Permanent(err error) error
- func RetryAfter(err error) (time.Duration, bool)
- type ActionError
- type Actions
- type Dispatcher
- type Doc
- type Event
- type InitiativeSummary
- type Kind
- type Lookup
- type NewInitiative
- type Options
- type PermanentError
- type RetryAfterError
- type Subscriber
Constants ¶
This section is empty.
Variables ¶
var AllKinds = []Kind{ KindInitiativeCreated, KindNeedsJudgment, KindPRDApproved, KindPlanApproved, KindChangeSetCreated, KindChangeSetReady, KindChangeSetApproved, KindChangeSetRejected, KindChangeSetApplied, KindChangeSetReverted, KindVerifyPassed, KindVerifyFailed, KindRunFailed, KindTaskStatusChanged, KindOutcomeDrifted, KindBudgetExceeded, KindEvalRegressed, }
AllKinds lists every Kind, in the order config.IntegrationEventKinds does.
Functions ¶
func IsPermanent ¶
IsPermanent reports whether err is, or wraps, a PermanentError.
Types ¶
type ActionError ¶
ActionError is a refusal from the daemon's handler: the HTTP status and the handler's own message, which is what an integration shows its user.
func (*ActionError) Error ¶
func (e *ActionError) Error() string
type Actions ¶
type Actions interface {
ReviewChangeSet(ctx context.Context, projectID, changeSetID, verdict string) error
AcceptRecommendations(ctx context.Context, projectID, initiativeID string) (resolved []string, err error)
AnswerQuestion(ctx context.Context, projectID, questionID, answer string) error
CreateInitiative(ctx context.Context, projectID string, in NewInitiative) (initiativeID string, err error)
ListInitiatives(ctx context.Context, projectID string) ([]InitiativeSummary, error)
// Operate actions (slash commands): the same gates as the CLI.
ApproveInitiative(ctx context.Context, projectID, initiativeID string) error
AdvanceInitiative(ctx context.Context, projectID, initiativeID string) error
ExecuteInitiative(ctx context.Context, projectID, initiativeID string) error
ApplyChangeSet(ctx context.Context, projectID, changeSetID string) error
}
Actions is everything an integration may DO to a project, as opposed to observe. The daemon implements it by sending each call through its own authenticated HTTP handler (internal/daemon/integrations.go) -- the same handler, preconditions and gates `idea review`, `idea answer`, `idea new` and `idea accept-recommendations` reach -- so an integration has no path to a state change the CLI does not, and no way around a gate the CLI cannot get around. Approving a change set with open blocking findings from Slack is refused for exactly the reason, and with exactly the message, it is refused at the terminal.
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher tails one project's event log and delivers typed events to its subscribers through the persistent outbox.
Per subscriber, in order:
- ingest: read events past the subscriber's cursor, Translate, filter by Wants, and insert outbox rows + advance the cursor in ONE transaction.
- deliver: send the oldest pending row; on success mark it delivered, on failure schedule a retry with exponential backoff, or dead-letter it.
Delivery is strictly in event order per subscriber -- a pending head row in backoff holds back the rows behind it -- because order is part of the meaning (a Slack thread reply must not land before the message it replies to; a Linear issue must exist before its state can be synced). Dead rows release the queue. Different subscribers never block each other.
func NewDispatcher ¶
func NewDispatcher(db *store.DB, projectID string, subs []Subscriber, log *slog.Logger, opts Options) *Dispatcher
NewDispatcher builds a dispatcher. It does nothing until Run.
func (*Dispatcher) IngestError ¶
func (d *Dispatcher) IngestError(subscriber string) string
IngestError returns the most recent ingest failure for a subscriber ("" if the last ingest succeeded).
func (*Dispatcher) Init ¶
func (d *Dispatcher) Init(ctx context.Context) error
Init gives every subscriber seen for the first time a cursor at the current end of the log. Turning Slack on for a project with a year of history must not post a year of history; a subscriber starts with the first event after it was configured. Subscribers that already have a cursor -- every one after a restart -- are left where they were, which is what makes a restart resume rather than skip or replay.
func (*Dispatcher) Run ¶
func (d *Dispatcher) Run(ctx context.Context)
Run tails and delivers until ctx is cancelled.
func (*Dispatcher) Subscribers ¶
func (d *Dispatcher) Subscribers() []Subscriber
Subscribers returns the dispatcher's subscribers.
func (*Dispatcher) Tick ¶
func (d *Dispatcher) Tick(ctx context.Context)
Tick runs one ingest+deliver pass for every subscriber.
func (*Dispatcher) Wake ¶
func (d *Dispatcher) Wake()
Wake asks Run for an immediate tick. Never blocks.
type Doc ¶
Doc is a context document attached at creation. Context documents enter every model prompt at the external_untrusted trust level, framed as data (internal/context): that, and not the initiative's own description, is where text written by someone outside this machine belongs.
type Event ¶
type Event struct {
// Seq and SourceEventID identify the event-log row this was derived from.
Seq int64 `json:"seq"`
SourceEventID string `json:"source_event_id"`
Kind Kind `json:"kind"`
ProjectID string `json:"project_id"`
Actor string `json:"actor,omitempty"`
At time.Time `json:"at"`
InitiativeID string `json:"initiative_id,omitempty"`
InitiativeTitle string `json:"initiative_title,omitempty"`
// Reason is the judgment reason (needs_judgment), the failure reason
// (run.failed), or the evidence note (verify.failed).
Reason string `json:"reason,omitempty"`
ChangeSetID string `json:"change_set_id,omitempty"`
ChangeSetRef string `json:"change_set_ref,omitempty"` // CHG-n
TaskID string `json:"task_id,omitempty"`
TaskCode string `json:"task_code,omitempty"`
TaskTitle string `json:"task_title,omitempty"`
// Status is the new task status (task.status_changed), or the metric's
// new drift status (outcome.drifted).
Status string `json:"status,omitempty"`
RequirementCode string `json:"requirement_code,omitempty"`
// MetricCode/MetricName/ObjectiveCode name the drifting metric
// (outcome.drifted); Status is its new drift status.
MetricCode string `json:"metric_code,omitempty"`
MetricName string `json:"metric_name,omitempty"`
ObjectiveCode string `json:"objective_code,omitempty"`
}
Event is one typed domain event. It is a SNAPSHOT taken when the bus ingested the underlying log row and is persisted as the outbox payload, so a delivery retried an hour later still describes the moment it happened rather than whatever the initiative looks like now.
func Translate ¶
func Translate(ctx context.Context, lk Lookup, projectID string, row store.EventRow) ([]Event, error)
Translate maps one event-log row to zero or more typed domain events.
It is deliberately a pure function of the log plus point lookups: the log row carries the fact (its Operation is the new status, written in the same transaction as the change), and the lookups only add display context (titles, CHG-n). A lookup that finds nothing -- the row was deleted since, e.g. a task removed by a plan revision -- yields no event rather than an error, because there is nothing left to describe and a hard error would wedge the cursor on that row forever.
func (Event) IdempotencyKey ¶
IdempotencyKey is the outbox key for delivering ev to subscriber. The source event id is a ULID unique across the log, and one log row can yield more than one Kind, so both are part of the key.
type InitiativeSummary ¶
type InitiativeSummary struct {
ID string `json:"id"`
Title string `json:"title"`
ShortTitle string `json:"short_title,omitempty"`
Status string `json:"status"`
JudgmentReason string `json:"judgment_reason,omitempty"`
}
InitiativeSummary is one row of a project's initiative list.
type Kind ¶
type Kind string
Kind is one domain event type the bus publishes. The vocabulary is pinned to config.IntegrationEventKinds (what harness.yaml may name) by a test.
const ( KindInitiativeCreated Kind = "initiative.created" KindNeedsJudgment Kind = "initiative.needs_judgment" KindPRDApproved Kind = "review.prd_approved" KindPlanApproved Kind = "review.plan_approved" KindChangeSetCreated Kind = "change_set.created" KindChangeSetReady Kind = "change_set.ready_for_review" KindChangeSetApproved Kind = "change_set.approved" KindChangeSetRejected Kind = "change_set.rejected" KindChangeSetApplied Kind = "change_set.applied" KindChangeSetReverted Kind = "change_set.reverted" KindVerifyPassed Kind = "verify.passed" KindVerifyFailed Kind = "verify.failed" KindRunFailed Kind = "run.failed" KindTaskStatusChanged Kind = "task.status_changed" // KindOutcomeDrifted: an observation moved an outcome metric into // off_track or regressed (Status carries which). KindOutcomeDrifted Kind = "outcome.drifted" // KindBudgetExceeded: an initiative reached its spending cap and the // engine stopped before the next model or agent call (Reason carries // "$spent of $cap (before <call>)"). It is published instead of the // needs_judgment event the same stop produces, not as well. KindBudgetExceeded Kind = "initiative.budget_exceeded" // KindEvalRegressed: a scheduled `idea eval` run regressed against its // baseline (Reason summarizes the regressions). Project-level: no // initiative. KindEvalRegressed Kind = "eval.regressed" )
type Lookup ¶
type Lookup interface {
GetInitiative(ctx context.Context, initiativeID string) (domain.Initiative, error)
GetChangeSet(ctx context.Context, changeSetID string) (*domain.ChangeSet, error)
GetTask(ctx context.Context, taskID string) (*domain.Task, error)
PreviousInitiativeStatus(ctx context.Context, initiativeID string, beforeSeq int64, skipRunning bool) (string, error)
GetVerificationEvidenceRef(ctx context.Context, evidenceID string) (*store.VerificationEvidenceRef, error)
GetMetricRef(ctx context.Context, metricID string) (*store.MetricRef, error)
}
Lookup is the read access the translator needs to enrich a bare log row. *store.DB satisfies it.
type NewInitiative ¶
NewInitiative is a request to start an initiative.
type Options ¶
type Options struct {
// PollInterval is how often the event log is tailed. Default 1s, the same
// cadence the SSE endpoint polls the same log at.
PollInterval time.Duration
// MaxAttempts bounds retries before a row is dead-lettered. Default 8,
// which with the default backoff spans roughly ten minutes -- long enough
// to ride out a Slack incident or a laptop waking from sleep, short
// enough that a revoked token surfaces in `idea integrations status`
// instead of retrying for a day.
MaxAttempts int
// BaseBackoff doubles per attempt up to MaxBackoff. Defaults 2s and 5m.
BaseBackoff time.Duration
MaxBackoff time.Duration
// DeliveryTimeout bounds one Deliver call. Default 30s.
DeliveryTimeout time.Duration
// Now is the clock (tests).
Now func() time.Time
}
Options tunes a Dispatcher. Zero values take the defaults noted.
type PermanentError ¶
type PermanentError struct{ Err error }
PermanentError marks a delivery failure retrying cannot fix (a revoked token, a channel the bot is not in, a malformed request).
func (*PermanentError) Error ¶
func (e *PermanentError) Error() string
func (*PermanentError) Unwrap ¶
func (e *PermanentError) Unwrap() error
type RetryAfterError ¶
RetryAfterError carries a server's own backoff hint (an HTTP 429's Retry-After, Linear's rate-limit reset).
func (*RetryAfterError) Error ¶
func (e *RetryAfterError) Error() string
func (*RetryAfterError) Unwrap ¶
func (e *RetryAfterError) Unwrap() error
type Subscriber ¶
type Subscriber interface {
// Name is stable across restarts: it keys the cursor and the outbox.
Name() string
// Wants filters at ingest time; an unwanted event is never queued.
Wants(Event) bool
// Deliver sends one event. A nil error marks it delivered. A
// PermanentError dead-letters it at once; anything else is retried with
// backoff, honouring a RetryAfter hint when the error carries one.
Deliver(ctx context.Context, ev Event) error
}
Subscriber receives domain events. Deliver is called from the dispatcher's own goroutine, one event at a time per subscriber, in event-log order.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package email is the outbound email notifier: a bus Subscriber that sends each wanted domain event as a plain-text message over SMTP.
|
Package email is the outbound email notifier: a bus Subscriber that sends each wanted domain event as a plain-text message over SMTP. |
|
Package linear is the two-way Linear integration: outbound, an approved execution plan becomes one Linear issue per task under a parent issue per initiative, kept in sync as tasks and change sets move; inbound, a poll for issues carrying a label turns each into an initiative.
|
Package linear is the two-way Linear integration: outbound, an approved execution plan becomes one Linear issue per task under a parent issue per initiative, kept in sync as tasks and change sets move; inbound, a poll for issues carrying a label turns each into an initiative. |
|
Package push delivers integration-bus events to browsers as Web Push notifications (RFC 8030 delivery, RFC 8291 encryption, RFC 8292 VAPID; the wire work is internal/webpush).
|
Package push delivers integration-bus events to browsers as Web Push notifications (RFC 8030 delivery, RFC 8291 encryption, RFC 8292 VAPID; the wire work is internal/webpush). |
|
Package slack is the Slack integration: an outbound notifier (a bus Subscriber posting Block Kit messages via chat.postMessage, threaded per initiative) and an inbound Socket Mode client (buttons and the /idea slash command) that routes every action through the daemon's own HTTP handlers, gated by a per-project allowlist of Slack user IDs.
|
Package slack is the Slack integration: an outbound notifier (a bus Subscriber posting Block Kit messages via chat.postMessage, threaded per initiative) and an inbound Socket Mode client (buttons and the /idea slash command) that routes every action through the daemon's own HTTP handlers, gated by a per-project allowlist of Slack user IDs. |