gates

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 13 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 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

View Source
const RuleWindow = "window"

RuleWindow is the Rule of a gate its passed Deadline resolved to its Default.

Variables

View Source
var (
	// ErrRefused is a resolution the gate does not accept: by an agent or 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")
)
View Source
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 Decider

type Decider interface {
	Decide(ctx context.Context, g gate.Gate) error
}

Decider applies the operations of a resolved proposal gate.

type Decision

type Decision struct {
	Mode   gate.Mode
	Window time.Duration
	Rule   string
}

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
}

Def is a gate the profile's gates.toml declares: its kind, its words and its intents in the order clients offer them.

type Deliverer

type Deliverer interface {
	Deliver(ctx context.Context, g gate.Gate) error
}

Deliverer delivers a resolved question or post gate's answer to its session.

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

	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 Events

type Events interface {
	RecordEvents(ctx context.Context, evs ...port.Event) error
}

Events records the event a resolved step gate is, which workflows trigger on.

type Intent

type Intent struct {
	Name   string
	Status gate.Status
	Answer bool
}

Intent is what a gate is resolved with: the status gates.toml gives it, and whether it takes text.

type Once

type Once interface {
	Once(g gate.Gate) bool
}

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

type OwnTasks interface {
	ReopenOwn(ctx context.Context, u unit.Unit) (task.ID, bool, error)
}

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

type Policy interface {
	Decide(ctx context.Context, g gate.Gate) (Decision, error)
}

Policy is a trusted approval: the profile's and the configuration's [gates.approval], never an agent's or a thread's text.

type Profile

type Profile interface {
	Gate(name string) (Def, bool)
	FirstOf(k gate.Kind) (Def, bool)
}

Profile is the gates the profile declares, as loaded at each call.

type Publisher

type Publisher interface {
	Publish(ctx context.Context, g gate.Gate) error
}

Publisher publishes the draft of a resolved draft gate.

type Query

type Query struct {
	Kind     gate.Kind
	Name     string
	Task     task.ID
	Unit     unit.Unit
	Statuses []gate.Status
}

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 Releaser

type Releaser interface {
	Release(ctx context.Context, g gate.Gate) error
}

Releaser releases the plan item of a resolved plan gate.

type Resolution

type Resolution struct {
	Status gate.Status
	Intent string
	Answer string
	By     task.Actor
	Rule   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.

type Sent

type Sent interface {
	RecordSent(ctx context.Context, g gate.Gate) (gate.Gate, error)
}

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 New

func New(d Deps) *Service

func (*Service) Cut

func (s *Service) Cut() []gate.Gate

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

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

NextDeadline is the earliest Deadline of an open gate, zero when none has one.

func (*Service) Open

func (s *Service) Open(ctx context.Context, g gate.Gate, p Policy) (gate.Gate, error)

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

func (s *Service) RecordSent(ctx context.Context, g gate.Gate) (gate.Gate, error)

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

func (s *Service) Resolve(ctx context.Context, id int64, r Resolution) error

Resolve closes open gate id with r. It accepts a person's intent, 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 agent's or a plugin's resolution 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) Supersede

func (s *Service) Supersede(ctx context.Context, id int64, by task.Actor) error

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.

func (*Service) Tick

func (s *Service) Tick(ctx context.Context, now time.Time) error

Tick resolves every open gate whose Deadline is not after now to its Default, with the rule window, then runs the consequence of each resolved gate whose consequence never ran, as when the daemon stopped between the gate's resolution and its consequence.

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.

type Tasks

type Tasks interface {
	TasksOf(ctx context.Context, u unit.Unit) ([]task.Task, error)
	Open(ctx context.Context, r coretasks.OpenRequest) (task.Task, error)
}

Tasks finds the task a gate's unit is on, and opens one when none is.

type Unblocker

type Unblocker interface {
	Unblock(ctx context.Context, g gate.Gate) error
}

Unblocker unblocks the first run a resolved trust gate held.

Directories

Path Synopsis
Package gatestest holds an in-memory gates store, a recorder of the gates' consequences, and the suite every gates store passes.
Package gatestest holds an in-memory gates store, a recorder of the gates' consequences, and the suite every gates store passes.

Jump to

Keyboard shortcuts

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