Documentation
¶
Overview ¶
Package draft holds the Outbox drafts: posts the loop proposes and the user approves before they reach a provider.
Index ¶
- Constants
- Variables
- func SameContent(a, b Draft) bool
- func SettledAt(ds []Draft, workflow string, subject unit.Unit) time.Time
- func Subjects(d Draft) []unit.Unit
- type Actor
- type ActorKind
- type Approval
- type ApprovalMode
- type Broadcast
- type Catalog
- type Cause
- type Condition
- type Content
- type Decision
- type Delivery
- type DeliverySpec
- type Draft
- type Evidence
- type FactSpec
- type ID
- type Kind
- type KindSpec
- type Origin
- type OriginKind
- type Placed
- type Policy
- type Revision
- type Rule
- type State
- type Subject
Constants ¶
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.
const ( BasisNone = "" BasisAgent = "agent" )
The bases a KindSpec names.
const EditableText = "text"
EditableText is the entry of a KindSpec's Editable that lets a person change a draft's text.
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 ¶
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") )
var ApprovalModes = []ApprovalMode{Send, Delay, Wait, DryRun}
ApprovalModes are the draft approval's modes.
var ErrEmptyText = errors.New("empty text")
ErrEmptyText is wrapped by CheckText.
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.
var ErrTransition = errors.New("draft: transition not allowed")
ErrTransition is wrapped by Can.
var Open = []State{Held, Queued, Sending}
Open are the states in which a draft may still be posted.
var SettledStates = []State{Sent, Dropped}
SettledStates are the states of a settled draft.
var WithdrawReasons = []string{WithdrawAssigned, WithdrawMoot, WithdrawOutside, WithdrawJoined, WithdrawEnded, WithdrawSkipped, WithdrawSuperseded}
WithdrawReasons are every reason a draft is withdrawn with.
Functions ¶
func SameContent ¶ added in v0.5.0
SameContent says whether a and b post the same.
func SettledAt ¶ added in v0.2.0
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.
Types ¶
type Actor ¶ added in v0.5.0
Actor is who changed a draft: Session is the agent session of an ActorSession, "" otherwise.
func ProposerOf ¶ added in v0.5.0
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 Approval ¶
type Approval struct {
Mode ApprovalMode
Window time.Duration // Mode "delay" only, > 0
}
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.
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
Kinds are the catalog's kinds, in the order they were declared.
func (*Catalog) Lookup ¶ added in v0.5.0
Lookup is the kind name of provider; false when provider declares none.
func (*Catalog) Posts ¶ added in v0.5.0
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
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.
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
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.
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 ¶
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
Concerns says whether d is on u, or was proposed by a turn on u.
func (Draft) EffectsDue ¶ added in v0.4.0
EffectsDue says whether d's effects are owed: it was sent, or closed without its message.
func (Draft) PayloadFacts ¶ added in v0.5.0
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.
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 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
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.
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
}
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
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 (Policy) Decide ¶ added in v0.2.0
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
ReadsSubject says whether a rule of p reads a fact of the draft's subject.
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.
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.