draft

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 15 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 draft holds the Outbox drafts: posts the loop proposes and the user approves before they reach a provider.

Index

Constants

View Source
const (
	WithdrawAssigned   = "assigned"
	WithdrawMoot       = "moot"
	WithdrawOutside    = "outside"
	WithdrawJoined     = "joined"
	WithdrawEnded      = "ended"
	WithdrawSkipped    = "skipped"
	WithdrawSuperseded = "superseded"
)

The reasons a draft is withdrawn, as Reason of the discarded draft: a workflow's, its person was assigned the items or it is moot; a verb ended the task the draft served; the user skipped its workflow on its unit; or one draft to the whole conversation replaced it. Outside: it addresses someone who cannot read the conversation it posts in. Joined: the person it was written to in their own conversation joined the one it came from.

View Source
const (
	BasisNone  = ""
	BasisAgent = "agent"
)

The bases a KindSpec names.

View Source
const EditableText = "text"

EditableText is the entry of a KindSpec's Editable that lets a person change a draft's text.

View Source
const ReasonClosedSilently = "closed_silently"

ReasonClosedSilently is the Reason of a draft the user discarded and closed without its message: its effects apply as if it was sent.

Variables

View Source
var (
	// ErrUnknownKind is wrapped when a draft names a kind its provider
	// declares none of.
	ErrUnknownKind = errors.New("unknown draft kind")
	// ErrPayload is wrapped when a payload does not fit its kind's schema.
	ErrPayload = errors.New("the payload does not fit its kind's schema")
)
View Source
var ApprovalModes = []ApprovalMode{Send, Delay, Wait, DryRun}

ApprovalModes are the draft approval's modes.

View Source
var ErrEmptyText = errors.New("empty text")

ErrEmptyText is wrapped by CheckText.

View Source
var ErrNotEditable = errors.New("not a person's to change")

ErrNotEditable is wrapped when a person's edit changes what a draft's kind does not let them.

View Source
var ErrTransition = errors.New("draft: transition not allowed")

ErrTransition is wrapped by Can.

View Source
var Open = []State{Held, Queued, Sending}

Open are the states in which a draft may still be posted.

View Source
var SettledStates = []State{Sent, Dropped}

SettledStates are the states of a settled draft.

WithdrawReasons are every reason a draft is withdrawn with.

Functions

func SameContent added in v0.5.0

func SameContent(a, b Draft) bool

SameContent says whether a and b post the same.

func SettledAt added in v0.2.0

func SettledAt(ds []Draft, workflow string, subject unit.Unit) time.Time

SettledAt is the newest UpdatedAt of the drafts of ds that workflow proposed on subject and that settled, sent or dropped (withdrawn ones included; a failed draft may still be approved again); zero when none. A draft is on a task subject when it serves that task, and on any other subject when it is on that unit.

func Subjects added in v0.4.0

func Subjects(d Draft) []unit.Unit

Subjects are the subjects d is on: its unit and, when it serves one, its task.

Types

type Actor added in v0.5.0

type Actor struct {
	Kind    ActorKind
	Session string
}

Actor is who changed a draft: Session is the agent session of an ActorSession, "" otherwise.

func ProposerOf added in v0.5.0

func ProposerOf(o Origin) Actor

ProposerOf is who wrote the content a proposal of o brings: its session's, an agent's, when one proposed it or a turn did; a person's for a draft the user wrote with no session; a rule's otherwise.

type ActorKind added in v0.5.0

type ActorKind string

ActorKind is who changed a draft.

const (
	ActorPerson  ActorKind = "person"
	ActorSession ActorKind = "session"
	ActorRule    ActorKind = "rule"
	ActorWindow  ActorKind = "window"
)

type Approval

type Approval struct {
	Mode   ApprovalMode
	Window time.Duration // Mode "delay" only, > 0
}

func (Approval) Releases added in v0.2.0

func (a Approval) Releases() bool

Releases says whether a sends a draft with no person approving it.

func (Approval) Validate

func (a Approval) Validate() error

Validate refuses an unknown mode, a window <= 0 with delay, a window set without delay.

type ApprovalMode

type ApprovalMode string // "wait" (default), "delay", "send", "dry_run"
const (
	Wait   ApprovalMode = "wait"
	Delay  ApprovalMode = "delay"
	Send   ApprovalMode = "send"
	DryRun ApprovalMode = "dry_run"
)

func ModeOf added in v0.3.0

func ModeOf(m gate.Mode) ApprovalMode

ModeOf is a gate's approval mode as a draft's: send and run send it.

func (ApprovalMode) Releases added in v0.2.0

func (m ApprovalMode) Releases() bool

Releases says whether m sends a draft with no person approving it.

type Broadcast added in v0.4.0

type Broadcast string

Broadcast says whether a thread reply is also posted to its conversation. It is NoBroadcast when the draft replies in no thread, as its publisher places it when it is proposed.

const (
	NoBroadcast  Broadcast = ""
	BroadcastOff Broadcast = "off"
	BroadcastOn  Broadcast = "on"
)

func (Broadcast) Valid added in v0.4.0

func (b Broadcast) Valid() bool

type Catalog added in v0.5.0

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

Catalog is the draft kinds and deliveries the plugins' manifests declare, each kind keyed by its provider and name.

func NewCatalog added in v0.5.0

func NewCatalog(kinds []KindSpec, deliveries []DeliverySpec, defaults map[string]string) (*Catalog, error)

NewCatalog is the catalog of kinds and deliveries; defaults are, by provider, the delivery of a draft that names neither a kind nor one of the provider's deliveries. It refuses a kind declared twice by one provider, a delivery none of its provider's deliveries names, and a schema that does not compile.

func (*Catalog) Kinds added in v0.5.0

func (c *Catalog) Kinds() []KindSpec

Kinds are the catalog's kinds, in the order they were declared.

func (*Catalog) Lookup added in v0.5.0

func (c *Catalog) Lookup(provider, name string) (KindSpec, bool)

Lookup is the kind name of provider; false when provider declares none.

func (*Catalog) Posts added in v0.5.0

func (c *Catalog) Posts(provider, delivery string) bool

Posts says whether a draft of provider's delivery reaches people; a delivery provider does not declare does, so a rule must name it to release it.

func (*Catalog) Shape added in v0.5.0

func (c *Catalog) Shape(provider string, d Draft) (Draft, error)

Shape is d with its kind, purpose and delivery as provider's manifest declares them, provider being the one that posts d. A kind d names is looked up; with none, it is the kind named as d's purpose when that kind posts as d's delivery, or when d names no delivery or one provider does not declare, else the first kind declared with d's delivery, else with provider's default delivery. Its purpose is its kind when it names none, and its delivery is its kind's. A kind provider does not declare wraps ErrUnknownKind. A provider that declares no kind leaves d as it is but for an empty purpose, which takes its kind.

func (*Catalog) Validate added in v0.5.0

func (c *Catalog) Validate(spec KindSpec, payload json.RawMessage) error

Validate refuses a payload that does not fit spec's schema, wrapping ErrPayload; an empty payload is the empty object.

type Cause added in v0.5.0

type Cause string

Cause is why a draft failed, or why its approval was refused, as its readers act on it.

const (
	// CauseStale: its unit moved past the basis it was written against, as a live read or its publisher
	// found; it stands until its content is revised.
	CauseStale Cause = "stale"
	// CauseUnconfirmed: its post may have reached its provider, so posting it again takes a person's confirm.
	CauseUnconfirmed Cause = "unconfirmed"
)

type Condition added in v0.2.0

type Condition interface {
	Holds(facts map[string]any, now time.Time) (bool, error)
}

Condition is a rule's compiled when over the facts RuleFacts and the unit's facts give.

type Content added in v0.5.0

type Content struct {
	Unit unit.Unit
	// Items decide where a draft with no target posts, such as a Slack segment's reply to the message an item
	// started at.
	Items     []string
	Kind      Kind
	Delivery  Delivery
	Target    string
	Text      string
	Reaction  string
	Broadcast Broadcast
	Payload   []byte
	Basis     string
	Effects   []string
}

Content is what a draft posts and what follows its post: a gate approves a draft's Content at its Rev, and a write that changes it is a new revision.

func (Content) Equal added in v0.5.0

func (c Content) Equal(o Content) bool

Equal says whether c and o post the same.

type Decision added in v0.2.0

type Decision struct {
	Approval Approval
	// Rule is the index of the rule that matched; -1 for none.
	Rule int
	// PostReleased says that a rule naming d's delivery released a draft
	// whose delivery posts, the only way one is sent with no person
	// approving it.
	PostReleased bool
}

Decision is the approval Decide picked and why.

type Delivery added in v0.2.0

type Delivery string

Delivery is how a draft reaches the provider, as its plugin's manifest declares it.

type DeliverySpec added in v0.5.0

type DeliverySpec struct {
	Provider, Name string
	// Posts says a draft of the delivery reaches people.
	Posts bool
}

DeliverySpec is a delivery a plugin's manifest declares.

type Draft

type Draft struct {
	ID        ID
	Unit      unit.Unit
	Items     []string // item ids of Unit; may be empty
	Task      string   // the task it serves, "" none; the Outbox row of the draft itself is "draft:<ID>"
	Kind      Kind
	Purpose   string    // what it is for: "nudge", "close", "ask_owner", or any label its proposer names
	Delivery  Delivery  // how it is posted
	Effects   []string  // applied when it is sent, such as "task.nudged"
	Target    string    // plugin target grammar; "" means the unit itself (its thread, its PR)
	Broadcast Broadcast // a thread reply also posted to its conversation; NoBroadcast when it replies in no thread
	Text      string    // standard Markdown with mentions as @{<person key>}; the Effects implementation converts both; Kind "delete": the text of the message it removed, as Slack held it
	Reaction  string    // Kind "react" only: emoji name without colons
	Replaced  string    // Kind "edit" only: the text the edit replaced
	Original  string    // Text as proposed
	Edited    bool      // Text != Original
	Origin    Origin
	State     State
	Evidence  Evidence // State "sent" only
	Error     string   // State "failed" only, never a token
	// Cause is why the draft failed, or why its approval was refused, when a reader acts on it; "" for any other.
	Cause  Cause
	Reason string // State "dropped": "user", "assigned", "moot", "dry_run", ...
	// Rev is the draft's content revision: 1 as proposed, and one more for each write that changes its
	// Content. A gate approves a draft at its Rev; a person and an agent revise it at the Rev they read.
	Rev int64
	// Version is the stored row's write counter, which every write bumps and checks, a state move as much as
	// a revision.
	Version int64
	// EffectsAppliedAt is when the Effects of a sent draft were applied;
	// zero while they are not.
	EffectsAppliedAt time.Time
	// Why is why it was proposed, in the user's language when it was;
	// Language is the locale Text is written in. Both "" for a draft no
	// workflow step wrote.
	Why, Language string
	// Payload is what the kind's schema shapes beside Text, posted
	// verbatim; nil for a kind without one.
	Payload json.RawMessage
	// Basis is what the proposer read the unit at, such as a head commit,
	// for a kind whose KindSpec.Basis is BasisAgent; "" none.
	Basis string
	// Hold keeps the draft waiting for a person whatever its approval
	// rules say, except under dry_run.
	Hold bool
	// By is who wrote the current content (Text, Payload, Basis); the outbox sets it on Propose, Amend
	// and AgentAmend.
	By Actor

	CreatedAt, UpdatedAt, SendingAt time.Time
}

func (Draft) Can

func (d Draft) Can(s State) error

Can says why d cannot move to s, nil when it can: held->queued|failed|dropped; queued->sending|failed|dropped; sending->sent|failed; failed->queued (by hand only)|dropped.

func (Draft) Concerns added in v0.5.0

func (d Draft) Concerns(u unit.Unit) bool

Concerns says whether d is on u, or was proposed by a turn on u.

func (Draft) Content added in v0.5.0

func (d Draft) Content() Content

Content is what d posts.

func (Draft) EffectsDue added in v0.4.0

func (d Draft) EffectsDue() bool

EffectsDue says whether d's effects are owed: it was sent, or closed without its message.

func (Draft) PayloadFacts added in v0.5.0

func (d Draft) PayloadFacts(spec KindSpec) map[string]any

PayloadFacts are the payload facts of d that spec, d's kind as its publisher's manifest declares it, declares, each the string its pointer reaches in d's payload; none when spec is not of d's kind, and a fact whose pointer reaches no string is absent.

func (Draft) RuleFacts added in v0.2.0

func (d Draft) RuleFacts() map[string]any

RuleFacts are the facts of d a rule reads: its delivery, as its plugin publishes it, its proposer, and its purpose and effects only when a workflow or a rule of the loop named them.

type Evidence

type Evidence struct {
	Ref       string // Slack: message ref, <conversation>/<ts>; GitHub: comment id
	Permalink string
	At        time.Time
}

type FactSpec added in v0.5.0

type FactSpec struct {
	Name, Pointer string
}

FactSpec is a payload field read as an approval fact: Name is draft.<provider>.<kind>.<field>, Pointer a JSON pointer into the payload to a required string enum.

type ID

type ID int64

type Kind

type Kind string

Kind is a draft kind's name, which its plugin's manifest declares.

type KindSpec added in v0.5.0

type KindSpec struct {
	Provider, Name string
	// Delivery is how the plugin posts a draft of the kind.
	Delivery string
	// Schema is the JSON schema of the kind's payload, a path in the
	// plugin's directory; Preview is the template of its summary line, a
	// path in the plugin's profile layer.
	Schema, Preview string
	// Basis is who states what a draft of the kind was written against:
	// BasisAgent, or BasisNone.
	Basis        string
	TextRequired bool
	// Editable are what a person may change on a draft of the kind: "text",
	// or a JSON pointer into its payload.
	Editable []string
	// Facts are the payload fields an approval rule reads.
	Facts []FactSpec
	// Verdict is the JSON pointer to the payload field whose value is the record verdict a sent draft of the
	// kind posts; "" posts none. Verdicts are the values its schema allows there.
	Verdict  string
	Verdicts []string
	// SchemaJSON is the content of Schema.
	SchemaJSON json.RawMessage
	// Posts says a draft of the kind reaches people, as its delivery's
	// posts says.
	Posts bool
}

KindSpec is a draft kind as its plugin's manifest declares it, keyed by Provider and Name.

func (KindSpec) CheckEdit added in v0.5.0

func (k KindSpec) CheckEdit(before, after Draft) error

CheckEdit refuses after, a person's edit of before, when it changes the text and k's Editable lacks EditableText, or a payload value at a JSON pointer none of k's Editable pointers covers.

func (KindSpec) CheckText added in v0.5.0

func (s KindSpec) CheckText(text string) error

CheckText refuses a blank text for a kind that requires one.

func (KindSpec) VerdictOf added in v0.5.0

func (s KindSpec) VerdictOf(d Draft) string

VerdictOf is the record verdict d, a draft of kind s, posts: the payload field s.Verdict points to; "" when the kind posts none or the payload lacks it.

type Origin

type Origin struct {
	Kind     OriginKind
	TurnSeq  int64  // Kind "turn": the turn (session or headless) that proposed it; Kind "session": the handle's newest turn on the unit, 0 none
	Intent   string // the proposing turn's intent ("" for auto and user)
	Workflow string // the workflow that started the proposing turn (turn.Turn.Workflow), "" none
	Rule     string // Kind "auto": the core or plugin rule, e.g. "stalled-nudge", "closure", "ask-owner", "github-nudge"
	Key      string // Kind "auto": the rule's dedupe key, e.g. "stalled-nudge:<task>:<person key>"
	// Unit is the unit of the proposing turn when it is not the draft's, such
	// as a pull request whose turn drafts in a Slack thread; zero when it is.
	Unit unit.Unit
	// Session is the session that proposed it through its tools, which never
	// resolves its gate; "" when no session did.
	Session string
}

func (Origin) ByAgent added in v0.5.0

func (o Origin) ByAgent() bool

ByAgent says whether an agent proposed a draft of o: a turn, or a session through its tools.

func (Origin) Proposer added in v0.2.0

func (o Origin) Proposer() string

Proposer names what proposed a draft of o: workflow:<name>, rule:<name>, intent:<name> or user.

type OriginKind

type OriginKind string // "turn", "session", "auto", "user"
const (
	OriginTurn    OriginKind = "turn"
	OriginSession OriginKind = "session"
	OriginAuto    OriginKind = "auto"
	OriginUser    OriginKind = "user"
)

type Placed added in v0.4.0

type Placed struct {
	Target    string
	Broadcast Broadcast
}

Placed is where its publisher puts a draft when it is proposed: the target a draft with none posts to, "" for its unit, and its Broadcast.

type Policy added in v0.2.0

type Policy struct {
	Default Approval
	Rules   []Rule
	// Scope is the workflow whose scoped facts of the subject the rules
	// read; "" reads the unit's facts unscoped.
	Scope string
}

Policy is the approval of a proposer's drafts: the first Rule whose When holds, else Default.

func Fixed added in v0.2.0

func Fixed(a Approval) *Policy

Fixed is the policy of a, with no rules.

func (Policy) Decide added in v0.2.0

func (p Policy) Decide(d Draft, s Subject, posts bool, now time.Time) (Decision, error)

Decide is d's approval under p over the facts of its subject s; posts says that d's delivery reaches people, as its plugin's manifest declares it. A rule applies only when the facts it reads are of s's slot, a rule that releases applies to a draft that posts only when it names d's delivery, and a draft that posts no such rule releases waits for a person unless the approval is dry_run.

func (Policy) ReadsSubject added in v0.2.0

func (p Policy) ReadsSubject() bool

ReadsSubject says whether a rule of p reads a fact of the draft's subject.

func (Policy) Validate added in v0.2.0

func (p Policy) Validate() error

Validate refuses a policy whose default or a rule's approval does not validate, or a rule with no When.

type Revision added in v0.5.0

type Revision struct {
	Rev     int64
	Text    string
	Payload json.RawMessage
	Basis   string
	By      Actor
	At      time.Time
}

Revision is one version of a draft's content, as its reviser left it.

type Rule added in v0.2.0

type Rule struct {
	When     Condition
	Approval Approval
	// Names is the delivery When holds for alone, which its top-level
	// conjunction pins; "" for none. A rule releases a draft whose delivery
	// posts only when it names that delivery.
	Names Delivery
	// Subjects are the slots of the subject facts When reads; the rule
	// applies only to a draft whose subject is of that slot.
	Subjects []string
	// Payload are the payload facts When reads. A rule that releases never
	// applies to a draft that lacks one, and a draft whose own kind
	// declares one its payload does not hold waits.
	Payload []string
}

Rule is one [gates.approval] rule of a draft gate.

type State

type State string

State is where a draft's delivery stands; whether it may be posted at all is its gate's decision. A draft is held while its gate is open, queued once its gate approved it, and dropped when its gate refused it or its proposer withdrew it.

const (
	Held    State = "held"
	Queued  State = "queued"
	Sending State = "sending"
	Sent    State = "sent"
	Failed  State = "failed"
	Dropped State = "dropped"
)

type Subject added in v0.2.0

type Subject struct {
	Slot  string
	Facts map[string]any
	// Kind is the draft's kind as its plugin declares it, whose Facts are
	// the payload facts the rules read; the zero KindSpec gives none.
	Kind KindSpec
}

Subject is the facts a policy's rules read beside the draft's own, and the slot they are of.

Jump to

Keyboard shortcuts

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