outbox

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package outbox keeps the drafts the loop proposes and publishes the ones the user, or their approval policy, approved.

Index

Constants

View Source
const NotConfirmed = "not confirmed after a restart"

NotConfirmed is the Error of a draft Recover found in sending and Verify could not confirm.

Variables

View Source
var (
	ErrNotFound     = errors.New("no such draft")
	ErrConflict     = errors.New("the draft changed state")
	ErrDisabled     = errors.New("the draft's plugin is disabled or has no publisher")
	ErrDuplicate    = errors.New("an open draft of the same rule and key exists")
	ErrNeedsConfirm = errors.New("the draft may have been posted; retry needs confirm")
	ErrInvalid      = errors.New("invalid draft")
)
View Source
var ErrUnknownOrigin = errors.New("unknown proposer")

ErrUnknownOrigin is a draft's proposing intent, workflow or turn that the manifests or the book do not know.

Functions

func EvidenceOps

func EvidenceOps(d draft.Draft) []items.Op

EvidenceOps are the items ledger ops that record sent draft d on each of its items; the caller applies them with provenance items.Effects.

Types

type Effects

type Effects func(p unit.ProviderID) (port.Effects, error)

Effects returns the publishing capability of a provider; an error wrapping ErrDisabled when its plugin is off or has no publisher.

type Evidence

type Evidence func(ctx context.Context, d draft.Draft) error

Evidence receives a sent draft's evidence for its items (wired to the items ledger, op "evidence").

func EvidenceTo

func EvidenceTo(apply func(ctx context.Context, prov items.Provenance, ops []items.Op) error) Evidence

EvidenceTo is an Evidence that applies a sent draft's EvidenceOps through apply, with provenance effects.

type Filter

type Filter struct {
	States    []draft.State
	Unit      *unit.Unit
	Entry     string
	Rule, Key string
}

type ItemReader

type ItemReader interface {
	Items(ctx context.Context, u unit.Unit) ([]items.Item, error)
}

ItemReader reads a unit's items, for the confidence Would.Policy weighs.

type Manifests

type Manifests interface {
	// IntentApproval is the block of intent name, nil when it declares none; known is false for an unknown intent.
	IntentApproval(name string) (a *draft.Approval, known bool)
	// WorkflowApproval is the block of workflow name, nil when it declares none; known is false for an unknown workflow.
	WorkflowApproval(name string) (a *draft.Approval, known bool)
	// Turn is the intent of turn seq in u's book and the workflow that started it; ok is false when the book has no such turn.
	Turn(ctx context.Context, u unit.Unit, seq int64) (intent, workflow string, ok bool, err error)
}

Manifests reads the [draft_approval] blocks of the loaded intents and workflows, and the turns book.

type Policies

type Policies interface {
	For(ctx context.Context, u unit.Unit, o draft.Origin) (draft.Approval, error)
}

Policies resolves the approval of a proposal on u whose Approval is nil.

type Proposal

type Proposal struct {
	Unit                   unit.Unit
	Items                  []string
	Entry                  string
	Kind                   draft.Kind
	Target, Text, Reaction string
	Origin                 draft.Origin
	Approval               *draft.Approval // nil: resolved by Service.Policies from Origin
}

type Resolver

type Resolver struct {
	Manifests Manifests
}

Resolver is the Policies of the manifests, for turn and session drafts only: the proposing turn's workflow block, then its intent's, else always. The intent and workflow come from the turn in the book; an Origin that names others than the book's resolves to always. Every other origin resolves to always, so a rule's policy reaches a draft only through Proposal.Approval.

func (Resolver) For

type Service

type Service struct {
	Store    Store
	Effects  Effects
	Policies Policies   // nil resolves every proposal to always
	Evidence Evidence   // nil none
	Items    ItemReader // nil: no item counts as low confidence
	Changes  port.Changes
	Clock    port.Clock
	Log      func(format string, args ...any) // ids, states and kinds only; never text or tokens
	// OnSent runs after a draft is stored as sent and its Evidence call (last-nudge stamps, plugin bookkeeping).
	OnSent []func(ctx context.Context, d draft.Draft) error
	// ObservedFor is how long an observed draft keeps an auto proposal of its key from being observed again;
	// zero keeps it for good.
	ObservedFor time.Duration
}

func (*Service) Approve

func (s *Service) Approve(ctx context.Context, id draft.ID, text *string) (draft.Draft, error)

func (*Service) Discard

func (s *Service) Discard(ctx context.Context, id draft.ID, reason string) (draft.Draft, error)

func (*Service) Edit

func (s *Service) Edit(ctx context.Context, id draft.ID, text string) (draft.Draft, error)

func (*Service) List

func (s *Service) List(ctx context.Context, f Filter) ([]draft.Draft, error)

func (*Service) NextDeadline

func (s *Service) NextDeadline(ctx context.Context) (time.Time, bool, error)

NextDeadline is the earliest Deadline of a proposed window draft; false when there is none.

func (*Service) Propose

func (s *Service) Propose(ctx context.Context, p Proposal) (draft.Draft, error)

func (*Service) RecordSent

func (s *Service) RecordSent(ctx context.Context, p Proposal, ev draft.Evidence) (draft.Draft, error)

RecordSent stores a post already made outside the outbox (origin session) as sent.

func (*Service) Recover

func (s *Service) Recover(ctx context.Context) error

Recover runs once at daemon start: every sending draft -> Verify -> sent | failed; a draft whose provider answers ErrDisabled stays sending for the next Recover.

func (*Service) Retry

func (s *Service) Retry(ctx context.Context, id draft.ID, confirm bool) (draft.Draft, error)

Retry: failed -> approved. A draft that failed as "not confirmed after a restart" or with an Error starting "may have been posted" needs confirm true, else ErrNeedsConfirm.

func (*Service) Send

func (s *Service) Send(ctx context.Context) (sent, failed int, err error)

Send is the sender pass: every approved draft -> sending -> sent | failed, one Publish each, no retry.

func (*Service) Tick

func (s *Service) Tick(ctx context.Context) (approved int, err error)

Tick approves every proposed window draft whose Deadline passed, through the same gate as Approve; a draft the gate refuses stays proposed.

type Store

type Store interface {
	Insert(ctx context.Context, d draft.Draft) (draft.Draft, error) // assigns ID
	Get(ctx context.Context, id draft.ID) (draft.Draft, error)      // ErrNotFound
	List(ctx context.Context, f Filter) ([]draft.Draft, error)      // newest first
	// Update writes d only while the stored state is from and the stored Rev is d.Rev, and returns
	// d with Rev bumped; ErrConflict otherwise.
	Update(ctx context.Context, d draft.Draft, from draft.State) (draft.Draft, error)
}

Jump to

Keyboard shortcuts

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