Documentation
¶
Overview ¶
Package gates holds every decision waiting on the user: it opens a gate, resolves it only through the user API or a trusted policy rule, and applies the one consequence its kind names.
Index ¶
- Constants
- Variables
- type Begun
- type Decider
- type Decision
- type Def
- type Deliverer
- type Deps
- type Events
- type HeldTasks
- type Intent
- type Once
- type OwnTasks
- type Policy
- type Profile
- type Publisher
- type Query
- type Reader
- type Releaser
- type Resolution
- type Sent
- type Service
- func (s *Service) ActingFor(ctx context.Context, id task.ID) ([]gate.Gate, error)
- func (s *Service) Cut() []gate.Gate
- func (s *Service) HoldsTask(ctx context.Context, id task.ID) (bool, error)
- func (s *Service) NextDeadline(ctx context.Context) (time.Time, error)
- func (s *Service) Open(ctx context.Context, g gate.Gate, p Policy) (gate.Gate, error)
- func (s *Service) RecordSent(ctx context.Context, g gate.Gate) (gate.Gate, error)
- func (s *Service) Resolve(ctx context.Context, id int64, r Resolution) error
- func (s *Service) SettleEnded(ctx context.Context) error
- func (s *Service) SettleHeld(ctx context.Context, id task.ID) error
- func (s *Service) Supersede(ctx context.Context, id int64, by task.Actor) error
- func (s *Service) TaskEnded(ctx context.Context, id task.ID, by task.Actor, session string, at time.Time) (err error)
- func (s *Service) Tick(ctx context.Context, now time.Time) error
- func (s *Service) Withdraw(ctx context.Context, id int64, reason string) error
- type Sessions
- type Store
- type Tasks
- type Unblocker
Constants ¶
const RuleWindow = "window"
RuleWindow is the Rule of a gate its passed Deadline resolved to its Default.
Variables ¶
var ( // ErrRefused is a resolution the gate does not accept: by an agent through // a session the user does not drive or whose turn produced the gate's // subject, by a plugin, by a rule the trusted policy does not hold, or by // a window that has not passed. ErrRefused = errors.New("the gate refuses the resolution") // ErrIntent is an intent the gate does not offer, or one gates.toml does // not declare for it. ErrIntent = errors.New("the gate offers no such intent") // ErrNoDef is a gate gates.toml does not declare, by name or by kind. ErrNoDef = errors.New("gates.toml declares no such gate") )
var ( ErrNoGate = errors.New("no such gate") ErrResolved = errors.New("the gate is resolved already") )
Functions ¶
This section is empty.
Types ¶
type Begun ¶
type Begun interface {
// Begin marks resolved gate id's consequence run, and begun until End.
Begin(ctx context.Context, id int64) error
End(ctx context.Context, id int64) error
// Begun are the resolved gates whose consequence began and never ended.
Begun(ctx context.Context) ([]gate.Gate, error)
}
Begun is optional on a Store: it keeps an at-most-once consequence begun until it ends, so one a stopped daemon cut can be reported.
type Decision ¶
Decision is how an approval decides a gate: its Mode, a delay's Window, and Rule, the rule that decided, which a gate it releases records.
type Def ¶
type Def struct {
Name string
Kind gate.Kind
Label string
Intents []Intent
// EndsTask is the category, done or dropped, a task opened only to hold gates ends in once the gate closes
// with a status and none of its gates is open; a status it leaves out leaves the task open.
EndsTask map[gate.Status]task.Category
// ClosesWith is the intent, one that refuses the gate, the gate closes with once its task ends; "" leaves it
// open.
ClosesWith string
}
Def is a gate the profile's gates.toml declares: its kind, its words and its intents in the order clients offer them.
type Deps ¶
type Deps struct {
Store Store
Reader Reader
Profile Profile
// Tasks gives a gate the task of its unit; nil leaves it with none.
Tasks Tasks
// Policy decides a gate Open is given no policy for, and is the one a
// resolution naming a rule is checked against; nil holds every gate.
Policy Policy
Clock port.Clock
Publisher Publisher
Releaser Releaser
Deliverer Deliverer
Decider Decider
Unblocker Unblocker
// Events records a resolved step gate; nil records none.
Events Events
// Sessions says which sessions the user drives; nil refuses every agent.
Sessions Sessions
Log func(format string, args ...any)
}
Deps are what the service reads, writes and applies. Every consequence port is optional: a kind whose port is nil resolves with no consequence.
type HeldTasks ¶ added in v0.4.0
HeldTasks is optional on Tasks: ends task id, one Tasks opened only to hold gates, into category c once its last gate closed; a task opened otherwise, or ended already, is left as it is.
type Intent ¶
Intent is what a gate is resolved with: the status gates.toml gives it, and whether it takes text.
type Once ¶
Once is optional on a consequence port: a gate it answers true for is marked run before its consequence runs, so a daemon that stops during the consequence never runs it again, and may leave it not run. For a consequence that acts in the user's name and keeps no record a second run could read, such as a round or a verb.
type OwnTasks ¶
OwnTasks is optional on Tasks: the unit's own task, such as a pull request's, which a gate on the unit goes to whatever its state, reopened when it is done, so the unit keeps one task.
type Policy ¶
Policy is a trusted approval: the profile's and the configuration's [gates.approval], never an agent's or a thread's text.
func WorkflowPolicy ¶ added in v0.4.0
func WorkflowPolicy(w workflow.Workflow, facts workflow.Facts, gateFacts func(gate.Gate) workflow.Facts, now time.Time) Policy
WorkflowPolicy is the approval of the gates workflow w opens on a unit whose facts are facts: the [gates.approval] of the gate's kind, w's run approval for a plan gate, its first rule that holds over facts and gateFacts of the gate at now, else its mode and window. A gate of a kind w approves none of waits.
type Query ¶
Query narrows Where: a zero field matches every gate, but Statuses, which matches the open gates when empty.
type Reader ¶
type Reader interface {
// Get is gate id; ErrNoGate when there is none.
Get(ctx context.Context, id int64) (gate.Gate, error)
// OfTask are task id's gates, open and closed.
OfTask(ctx context.Context, id task.ID) ([]gate.Gate, error)
// Where are the gates matching q.
Where(ctx context.Context, q Query) ([]gate.Gate, error)
}
Reader reads the gates, open and closed. Its lists are ordered by ID, oldest first; a list nothing matches is empty.
type Resolution ¶
type Resolution struct {
Status gate.Status
Intent string
Answer string
By task.Actor
Rule string
Session string
}
Resolution is how a gate closed: Intent is the intent a person or a rule chose and Status the one gates.toml gives it, Answer a question's text, By who resolved it, Rule the policy rule that released it ("window" for a deadline's default), "" for a person. Session is the session an agent resolves it through, which the service checks the user drives.
type Sent ¶
Sent records a post an agent made at once with a tool as a gate already approved. It is no resolution: no agent resolves an open gate.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service opens the gates and is the only code that resolves one.
func (*Service) ActingFor ¶ added in v0.4.0
ActingFor are the open gates that would act in task id's name: those of kind proposal, plan or step on its own unit, and the proposals on any task whose proposed verb names id in task.ArgTask.
func (*Service) Cut ¶
Cut are the resolved gates whose at-most-once consequence began and was cut by a daemon that stopped, so it may not have run, by ID.
func (*Service) HoldsTask ¶ added in v0.4.0
HoldsTask says whether an open gate of task id holds it open: one whose ClosesWith names one of its intents, a question to the person only the person, or the end of the task's unit, settles.
func (*Service) NextDeadline ¶
NextDeadline is the earliest Deadline of an open gate, zero when none has one.
func (*Service) Open ¶
Open opens g under p, nil meaning the service's Policy. The gate takes its kind and intents from gates.toml: the gate g names, else the first of its kind. It takes the task of its unit, or a new capture task when no task holds it. A policy that releases it resolves it at once with its rule; a delay gives it a Deadline and the Default its approving intent; a dry_run rejects a draft gate and holds any other.
func (*Service) RecordSent ¶
RecordSent records g, a post a tool made at once, as a gate already approved by g.By with g.Rule, worded by gates.toml and on the task of its unit when one holds it. It resolves no gate and applies no consequence.
func (*Service) Resolve ¶
Resolve closes open gate id with r. It accepts a person's intent, an agent's through a session the user drives whose turns did not produce the gate's subject, the Default of a gate whose Deadline passed with the rule window, and a rule the service's trusted Policy holds for the gate now; it refuses anything else, an unattended agent's or a plugin's above all. Status comes from the intent's declaration in gates.toml. It then applies the one consequence the gate's kind names.
func (*Service) SettleEnded ¶ added in v0.4.0
SettleEnded settles every task a closed gate whose status ends a held task was on, as SettleHeld does, so a task left open by gates that closed before their declaration ended it ends now.
func (*Service) SettleHeld ¶ added in v0.4.0
SettleHeld ends task id when Tasks opened it only to hold gates and none of them is open, in the category the last gate to close that names one ends it in; it settles a task whose gates closed before endHeld ran.
func (*Service) Supersede ¶
Supersede closes open gate id as superseded by by, its subject gone or replaced, with no consequence: the subject's owner settles the subject. It refuses an agent: no agent closes an open gate. A person supersedes a draft's gate only to replace it with its edit's.
func (*Service) TaskEnded ¶ added in v0.4.0
func (s *Service) TaskEnded(ctx context.Context, id task.ID, by task.Actor, session string, at time.Time) (err error)
TaskEnded settles each gate of task id that HoldsTask counts and that opened by at, when by ended the task, through session when an agent did: the user's end, a person's or an agent's through a session the user drives, closes it with its ClosesWith intent, which refuses the gate, in their name, and supersedes one whose subject the session's own turn produced; a plugin's or a workflow's end, which only the end of the task's unit makes, supersedes it as moot. It never approves or answers, refuses any other agent, and logs what it returns.
type Sessions ¶ added in v0.4.0
Sessions says whether the user drives an agent's session, by its stable id.
type Store ¶
type Store interface {
// Open stores g as open with a new ID and OpenedAt, and returns it.
Open(ctx context.Context, g gate.Gate) (gate.Gate, error)
// Resolve closes the open gate id with r and returns it: ErrNoGate when
// there is none, ErrResolved when it is closed already. A Resolution whose
// Status is open is refused.
Resolve(ctx context.Context, id int64, r Resolution) (gate.Gate, error)
// Due are the open gates whose Deadline is set and not after now.
Due(ctx context.Context, now time.Time) ([]gate.Gate, error)
// Applied marks resolved gate id's consequence as run; an open gate is
// refused.
Applied(ctx context.Context, id int64) error
// Unapplied are the resolved gates whose consequence has not run: a
// superseded gate and a recorded send have none.
Unapplied(ctx context.Context) ([]gate.Gate, error)
}
Store writes the gates. Its lists are ordered by ID, oldest first; a list nothing matches is empty.