Documentation
¶
Overview ¶
Package stage is the flow-progression service: a work item can carry one flow (a template's steps, snapshotted at start), and only an explicit action moves it — `done` after the current step's gate passes, `back` with a reason, `blocked` with a reason, or a person's approval. The gates read stored facts and git, never model text; a gate that cannot be judged here (a project that is not on this machine, git failing) answers needs_human instead of an error.
Dependencies point down only (G022): stage -> jobstore / project / config. Plan: docs/plans/2026-11-26-flow-progression-plan.md, design: docs/design/2026-11-18-resident-sessions-and-team-design.md §6.
Index ¶
- Constants
- Variables
- func BriefOf(v View) stagenote.Brief
- func TemplateNames() []string
- type Deps
- type Gate
- type GitRunner
- type Result
- type Service
- func (s *Service) Approve(id, by string) (Result, error)
- func (s *Service) Back(id, reason, by string) (View, error)
- func (s *Service) Blocked(id, reason, by string) (View, error)
- func (s *Service) BriefForSession(sid, projectKey string) *stagenote.Brief
- func (s *Service) Done(id, by string) (Result, error)
- func (s *Service) Drop(id, reason, by string) (View, error)
- func (s *Service) Enabled(projectKey string) bool
- func (s *Service) ForSession(sid string, withGate bool) (View, bool, error)
- func (s *Service) ListOpen(projectKey string) ([]View, error)
- func (s *Service) Start(in StartInput) (View, error)
- func (s *Service) Status(id string) (View, error)
- func (s *Service) TurnNote(lang i18n.Lang, sids ...string) string
- type StartInput
- type Template
- type View
Constants ¶
const ( StepDesign = "design" StepReview = "review" StepPlan = "plan" StepDoing = "doing" StepVerify = "verify" StepDone = "done" )
The steps a template is made of.
const ( TemplateFeature = "feature" TemplateSmall = "small" )
Built-in template names.
const DefaultReviewMax = 2
DefaultReviewMax is the review round cap of the built-in templates: after that many review rounds only a person's approval passes the review gate.
Variables ¶
var ErrMoved = errors.New("stage flow moved to another step meanwhile; read its status and try again")
ErrMoved is returned by an action whose flow was moved by someone else between reading and writing it (the step is no longer the one the caller saw).
Functions ¶
Types ¶
type Deps ¶
type Deps struct {
Store *jobstore.Store
// Config returns the current server configuration (projects, stage settings); it is
// called per request so a reload applies.
Config func() *config.Config
// Git defaults to project.GitRO.
Git GitRunner
}
Deps is what the service needs from the process.
type Gate ¶
type Gate struct {
Step string `json:"step"`
OK bool `json:"ok"`
Missing []string `json:"missing"`
NeedsHuman bool `json:"needs_human"`
}
Gate is the answer of one step's gate. Missing is written so it tells the agent what to do next. NeedsHuman means the gate cannot be judged here (or only a person can pass it): the flow stays on the step and the item belongs in the person's queue — never an error.
type Result ¶
type Result struct {
Advanced bool `json:"advanced"`
Gate Gate `json:"gate"`
Stage View `json:"stage"`
From string `json:"from,omitempty"`
// Moved is set when the flow had already left the step this call evaluated: a concurrent
// `done` won, and nothing was written by this one.
Moved bool `json:"moved,omitempty"`
}
Result is the answer of an action that may advance the flow. Advanced is false when the gate did not pass (Gate says what is missing) or another call advanced the flow first.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the stage flow service.
func (*Service) Approve ¶
Approve records a person's approval of the current step and advances when the gate passes with it: the review gate is the approval itself, and a gate that cannot be judged here (needs_human) is waived. A gate that is plainly unmet (a doc missing) stays unmet. The entry layer must admit only a person.
func (*Service) Back ¶
Back sends the flow to the previous step; the reason is required and goes to the journal.
func (*Service) Blocked ¶
Blocked marks the flow blocked on its current step with a reason. A later Done lifts it.
func (*Service) BriefForSession ¶
BriefForSession returns the `stage` object of a session's view: the flow of the work item the session is on, or — with none in progress — an Enabled-only object when the project has the flow on (projectKey "" has no project to opt out of, so it gets nothing). nil when there is nothing to say or the lookup failed (a view never fails over its stage).
func (*Service) Done ¶
Done evaluates the current step's gate and, when it passes, moves the flow to the next step (the last step finishes it). A blocked flow is unblocked first. A gate that does not pass leaves the flow where it is and says what is missing. Of several concurrent calls exactly one advances the flow; the others see Moved.
func (*Service) Drop ¶
Drop abandons the flow (the work item itself is untouched). The reason is optional.
func (*Service) Enabled ¶
Enabled reports whether the stage flow is on for a project (projects.<key>.stage.enabled, default true). A flow already started is unaffected by it; callers (the start-a-flow prompts) use it to decide whether to remind.
func (*Service) ForSession ¶
ForSession returns the flow of the work item the session is currently on (the newest change when it is on several); ok=false when it has none in progress. withGate evaluates the current step's gate too (it may run git, so a per-turn caller passes false).
func (*Service) ListOpen ¶
ListOpen returns the flows in progress (project != "" keeps one project's), without gates.
func (*Service) Start ¶
func (s *Service) Start(in StartInput) (View, error)
Start begins a flow. The work item is the explicit one, else the open item already linked to the issue, else a new item that gets the issue linked. A flow already in progress on it is jobstore.ErrStageActive.
func (*Service) Status ¶
Status returns the flow of a work item with the current step's gate evaluated.
func (*Service) TurnNote ¶
TurnNote is the per-turn reminder line of a session that has a flow in progress (ACP sessions take it in front of every turn); "" when it has none. A resident session is known by more than one id (its job id, the agent's own session id): the first that is on a flow wins. It reads the stored flow only, never a gate.
type StartInput ¶
type StartInput struct {
Issue string
WorkItemID string
// Template is a built-in template name; empty = feature.
Template string
// ProjectKey and Title are used only when a new work item has to be created.
ProjectKey string
Title string
// SessionID, when set, becomes a current session of the work item.
SessionID string
By string
}
StartInput names what a flow starts on: an issue (the item already linked to it, else a new item linked to it) and/or an explicit work item.
type Template ¶
type Template struct {
Name string
Steps []string
// ReviewMax caps the review rounds a review job may satisfy the gate in.
ReviewMax int
// PlanDoc makes the plan gate also ask for a committed plan document (role plan).
PlanDoc bool
}
Template is a flow definition. Starting a flow copies it into the work item's row, so changing a template later never touches a flow in progress.
func TemplateByName ¶
TemplateByName returns a built-in template (a copy); ok=false for an unknown name.
type View ¶
type View struct {
WorkItemID string `json:"work_item_id"`
ProjectKey string `json:"project_key,omitempty"`
Template string `json:"template"`
Steps []string `json:"steps"`
Step string `json:"step"`
StepIndex int `json:"step_index"`
StepEnteredAt int64 `json:"step_entered_at"`
Status string `json:"status"`
Level string `json:"level"`
BlockedReason string `json:"blocked_reason,omitempty"`
DoingDoneSHA string `json:"doing_done_sha,omitempty"`
ReviewMax int `json:"review_max"`
Approved bool `json:"approved,omitempty"`
Gate *Gate `json:"gate,omitempty"`
}
View is a flow as the entry layers show it. Gate is the evaluation of the current step (nil when the flow is finished, or when the caller asked for no evaluation).