draft

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 8 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 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 ApprovalModes = []ApprovalMode{Send, Delay, Wait, DryRun}

ApprovalModes are the draft approval's modes.

View Source
var ConversationKinds = []Kind{Reply, Nudge, Close, AskOwner, React}

ConversationKinds are the kinds slack_draft offers on a conversation: all but a review comment, an edit and a deletion, which slack_edit and slack_delete make at once.

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 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 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 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 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 // "message", "reaction", "comment", "edit", "delete"

Delivery is how a draft reaches the provider.

const (
	Message         Delivery = "message"
	Reaction        Delivery = "reaction"
	CommentDelivery Delivery = "comment"
	// EditDelivery replaces the text of a message the user posted.
	EditDelivery Delivery = "edit"
	// DeleteDelivery removes a message the user posted.
	DeleteDelivery Delivery = "delete"
)

func ShapeOf added in v0.2.0

func ShapeOf(k Kind) (purpose string, d Delivery)

ShapeOf is the purpose and delivery of a draft of kind k.

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
	Reason    string   // State "dropped": "user", "assigned", "moot", "dry_run", ...
	Rev       int64    // the stored row's version; every Update bumps it
	// 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

	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) 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) 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 ID

type ID int64

type Kind

type Kind string // "reply", "nudge", "close", "react", "ask_owner", "comment", "edit", "delete"
const (
	Reply    Kind = "reply"
	Nudge    Kind = "nudge"
	Close    Kind = "close"
	React    Kind = "react"
	AskOwner Kind = "ask_owner"
	Comment  Kind = "comment"
	Edit     Kind = "edit"
	Delete   Kind = "delete"
)

func KindOf added in v0.2.0

func KindOf(purpose string, d Delivery) Kind

KindOf is the kind readers of Kind see for a purpose and a delivery.

func (Kind) Emoji added in v0.2.0

func (k Kind) Emoji() bool

Emoji says whether a draft of kind k posts an emoji, and no text.

func (Kind) Valid

func (k Kind) Valid() bool

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) 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 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
}

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
}

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