stage

package
v0.220.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 18 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 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

View Source
const (
	// ActionSendContinue: the next step is the agent's, so the session is sent "continue
	// with <step>".
	ActionSendContinue = "send_continue"
	// ActionWaitCard: the next step waits for a person (review), so a 「等我」 card is raised.
	ActionWaitCard = "raise_wait_card"
)

The actions a level would take.

View Source
const (
	// DeliveredNow: the session took the turn.
	DeliveredNow = "delivered"
	// DeliveredQueued: the session sits on a seat that cannot take it now; the turn is queued
	// on the seat and goes out when a session is back there.
	DeliveredQueued = "queued"
	// NotDelivered: the session is offline or gone; nothing was queued.
	NotDelivered = "offline"
)

Outcomes of handing the reminder to a session.

View Source
const (
	OutcomeMatch      = "match"
	OutcomeMismatch   = "mismatch"
	OutcomeNoFollowup = "no_followup"
	OutcomePending    = "pending"
)

Outcomes of a recorded action.

View Source
const (
	StepDesign = "design"
	StepReview = "review"
	StepPlan   = "plan"
	StepDoing  = "doing"
	StepVerify = "verify"
	StepDone   = "done"
)

The steps a template is made of.

View Source
const (
	TemplateFeature = "feature"
	TemplateSmall   = "small"
)

Built-in template names.

View Source
const (
	// WaitReview: the review step waits for a person's approval.
	WaitReview = "review"
	// WaitNeedsHuman: the current step's gate cannot be judged here; a person confirms.
	WaitNeedsHuman = "needs_human"
	// WaitVerifyFailed: the newest verify-template run since doing finished failed.
	WaitVerifyFailed = "verify_failed"
)

Kinds of a waiting flow.

View Source
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.

View Source
const ReportObserveWindow = 24 * time.Hour

ReportObserveWindow is how long an action is watched before it reads no_followup; the plan driver's window (driver.ObserveWindow).

View Source
const ReportRecentWindow = 20

ReportRecentWindow is how many resolved actions the recent figure covers (the driver's job.PlanDriverUpgradeWindow).

Variables

View Source
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

func BriefOf

func BriefOf(v View) stagenote.Brief

BriefOf summarises a flow for a session view. It never evaluates a gate (that may run git), so it is safe on every heartbeat.

func IsAgentStep added in v0.220.0

func IsAgentStep(step string) bool

IsAgentStep reports whether the work of a step belongs to the agent.

func TemplateNames

func TemplateNames() []string

TemplateNames lists the built-in template names.

Types

type DeliverFunc added in v0.220.0

type DeliverFunc func(ctx context.Context, d Delivery) (string, error)

DeliverFunc hands a reminder to a session over the existing delivery paths. It returns one of DeliveredNow / DeliveredQueued / NotDelivered, or an error for a failure.

type Delivery added in v0.220.0

type Delivery struct {
	WorkItemID string
	SessionID  string
	Step       string
	// Text is the whole message, system prefix included.
	Text string
}

Delivery is one reminder to hand to a session.

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
	// Deliver hands the `remind` level's "continue" turn to a session; nil = the level
	// only records.
	Deliver DeliverFunc
	// Sync runs the reminder inline instead of in its own goroutine (tests).
	Sync bool
	// Now is the clock of the report's observation window (default time.Now).
	Now func() time.Time
}

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 GitRunner

type GitRunner func(dir string, capBytes int, args ...string) (string, error)

GitRunner runs a read-only git command in dir (see project.GitRO).

type Report added in v0.220.0

type Report struct {
	// WorkItemID / ProjectKey say what the report covers (both empty = every flow).
	WorkItemID  string `json:"work_item_id,omitempty"`
	ProjectKey  string `json:"project_key,omitempty"`
	WindowHours int    `json:"window_hours"`
	Total       int    `json:"total"`
	Pending     int    `json:"pending"`
	// Recent* is the overall figure of the latest ReportRecentWindow resolved actions.
	RecentN     int         `json:"recent_n"`
	RecentMatch int         `json:"recent_match"`
	RecentRate  float64     `json:"recent_rate"`
	ByAction    []ReportRow `json:"by_action"`
	ByRule      []ReportRow `json:"by_rule"`
	// Recent lists the newest actions, newest first.
	Recent []ReportAction `json:"recent"`
}

Report is the answer of `gofer stage report`.

type ReportAction added in v0.220.0

type ReportAction struct {
	WorkItemID string `json:"work_item_id"`
	Action     string `json:"action"`
	Step       string `json:"step"`
	Rule       string `json:"rule"`
	// Outcome is match / mismatch / no_followup / pending.
	Outcome string `json:"outcome"`
	// Observed is what actually happened next ("" while pending or with no follow-up).
	Observed string `json:"observed,omitempty"`
	At       int64  `json:"at"`
}

ReportAction is one recorded action with its outcome.

type ReportRow added in v0.220.0

type ReportRow struct {
	Action string `json:"action"`
	// Rule is set on the ByRule rows only.
	Rule       string  `json:"rule,omitempty"`
	Total      int     `json:"total"`
	Match      int     `json:"match"`
	Mismatch   int     `json:"mismatch"`
	NoFollowup int     `json:"no_followup"`
	Pending    int     `json:"pending"`
	Rate       float64 `json:"rate"`
	// RecentN / RecentMatch / RecentRate cover the latest ReportRecentWindow resolved
	// actions (ByAction rows only).
	RecentN     int     `json:"recent_n,omitempty"`
	RecentMatch int     `json:"recent_match,omitempty"`
	RecentRate  float64 `json:"recent_rate,omitempty"`
}

ReportRow totals actions: one row per action, or per action and rule.

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 New

func New(d Deps) *Service

New builds the service; Deps.Store is required.

func (*Service) Approve

func (s *Service) Approve(id, by string) (Result, error)

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

func (s *Service) Back(id, reason, by string) (View, error)

Back sends the flow to the previous step; the reason is required and goes to the journal.

func (*Service) Blocked

func (s *Service) Blocked(id, reason, by string) (View, error)

Blocked marks the flow blocked on its current step with a reason. A later Done lifts it.

func (*Service) BriefForSession

func (s *Service) BriefForSession(sid, projectKey string) *stagenote.Brief

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

func (s *Service) Done(id, by string) (Result, error)

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) Drain added in v0.220.0

func (s *Service) Drain()

Drain waits for the "continue" turns still being sent, so none writes to the store after it closes (G051). serve calls it through the HTTP server's Drain.

func (*Service) Drop

func (s *Service) Drop(id, reason, by string) (View, error)

Drop abandons the flow (the work item itself is untouched). The reason is optional.

func (*Service) Enabled

func (s *Service) Enabled(projectKey string) bool

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

func (s *Service) ForSession(sid string, withGate bool) (View, bool, error)

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

func (s *Service) ListOpen(projectKey string) ([]View, error)

ListOpen returns the flows in progress (project != "" keeps one project's), without gates.

func (*Service) NextStep added in v0.220.0

func (s *Service) NextStep(id string) (string, error)

NextStep is the name of the step `done` would move the flow of work item id to ("" when the flow is finished or already on its last step). It reads the stored flow only, never a gate.

func (*Service) Report added in v0.220.0

func (s *Service) Report(workItemID, project string) (Report, error)

Report builds the consistency report of one work item (id != "") or of a project (project != ""; both empty = every flow on this server).

func (*Service) SetLevel added in v0.220.0

func (s *Service) SetLevel(id, level, by string) (View, error)

SetLevel sets the autonomy level (record | remind) of a flow in progress. The entry layer must admit only a person.

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

func (s *Service) Status(id string) (View, error)

Status returns the flow of a work item with the current step's gate evaluated.

func (*Service) TurnNote

func (s *Service) TurnNote(lang i18n.Lang, sids ...string) string

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.

func (*Service) Waiting added in v0.220.0

func (s *Service) Waiting(allow func(string) bool) ([]WaitingFact, error)

Waiting lists the flows in progress that wait for a person; allow, when non-nil, is the caller's project scope.

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

func TemplateByName(name string) (Template, bool)

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

type WaitingFact added in v0.220.0

type WaitingFact struct {
	WorkItemID string   `json:"work_item_id"`
	Title      string   `json:"title"`
	ProjectKey string   `json:"project_key,omitempty"`
	Step       string   `json:"step"`
	Kind       string   `json:"kind"`
	Missing    []string `json:"missing,omitempty"`
	// Since is when the wait began: entering the step, or the failed run.
	Since int64 `json:"since"`
}

WaitingFact is one flow that waits for a person.

Jump to

Keyboard shortcuts

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