Documentation
¶
Overview ¶
Package fleet is the chief's view of its owner's whole fleet: each session's fleet state, the digest's groups (docs/chief.md "Fleet digest"), and the digest's marks (migration 0147, store.go).
Everything in this file is a pure function of what internal/api's fleet reader read (fleet_read.go): the hub's own windows, the session-state pass's open episodes, the pull requests muster recorded the sessions creating, and GitHub's answer for each. No model is called and no session text is read here; the digest is muster's own rendering, so it costs no chief turn.
🔴 ONE RULE, ONE PLACE: StateOf decides a session's fleet state and GroupOf its digest group, and both fleet_list and the digest card read them. A second copy of either is a digest that disagrees with what the chief reads.
Index ¶
- Constants
- Variables
- func GroupOf(state string, prs []PR, inFlight bool) string
- func StateOf(waitingNow bool, ep *Episode) string
- type Ask
- type Digest
- type Episode
- type Group
- type PG
- func (p *PG) Baseline(ctx context.Context) (time.Time, error)
- func (p *PG) FleetChat(ctx context.Context) (int64, error)
- func (p *PG) FleetChatOr(ctx context.Context, keep func(id int64) bool, create func() (int64, error)) (int64, error)
- func (p *PG) Look(ctx context.Context, at time.Time) (time.Time, error)
- type PR
- type Session
- type Since
- type Store
Constants ¶
const ( // StateWorking: no open stop — the session is busy, or idle under the // stall threshold. StateWorking = "working" // StateStalled: an open stop the stall classifier did not read as a // question. StateStalled = "stalled" // StateNeedsYou: an open stop that asks the owner something (the // session-state pass's needs_you, not waiting on a prompt). StateNeedsYou = "needs_you" // StateWaiting: a prompt or picker is on screen — the host reports the // window waiting now, or its open stop opened waiting. StateWaiting = "waiting" )
The fleet states (fleet_list's `state`).
const ( PROpen = "open" PRMerged = "merged" PRClosed = "closed" PRUnknown = "unknown" // GitHub was not asked, or did not answer )
The pull-request states a fleet row carries (fleet_list's prs[].state).
const ( GroupNeedsYou = "needs_you" GroupWaitingCI = "waiting_ci" GroupWorking = "working" GroupDone = "done" GroupStalled = "stalled" )
The digest's groups, in the order the card draws them.
const LookGap = 10 * time.Minute
LookGap is how long the owner must have been away for an open of the panel to count as a NEW look: opens closer together than this are one look, so the "since you last looked" line does not reset every time the panel is reopened within a few minutes.
Variables ¶
var GroupLabel = map[string]string{ GroupNeedsYou: "Needs you", GroupWaitingCI: "Waiting on checks", GroupWorking: "Working", GroupDone: "Done", GroupStalled: "Stalled", }
GroupLabel is each group's name on the card.
🔴 "Waiting on checks" SAYS WHAT IS KNOWN, NOT MORE: muster does not read checks yet, so the group is "stopped with an open pull request", and the card says the checks are unknown (GroupNote).
var GroupNote = map[string]string{ GroupWaitingCI: "Stopped with a pull request open. Its checks are not read yet, so whether CI is still running is unknown.", GroupDone: "Stopped, its latest pull request merged or closed, nothing queued to it.", }
GroupNote is the one line a group's open view starts with, where the label alone would claim more than muster knows.
var GroupOrder = []string{GroupNeedsYou, GroupWaitingCI, GroupWorking, GroupDone, GroupStalled}
GroupOrder is the card's order of the groups.
Functions ¶
func GroupOf ¶
GroupOf is the digest group of a session in fleet state state whose pull requests are prs (newest first) and that has a message queued to it or not (inFlight). "" for a state the digest does not group (none known).
- waiting or needs_you: Needs you;
- working: Working;
- stalled with its latest pull request open: Waiting on CI;
- stalled with its latest pull request merged or closed and nothing queued to it: Done, can wrap;
- any other stall (no pull request, its state unknown, or a message on its way): Stalled.
🔴 UNKNOWN IS NOT DONE: a pull request GitHub did not answer for leaves the session Stalled, never Done — a wrap proposed on a guess would close a session whose work is still open.
func StateOf ¶
StateOf is a session's fleet state: waitingNow is whether its host reports it waiting on a prompt NOW, ep its open episode (nil for none).
Precedence: waiting (now, or the stop opened waiting) > needs_you > stalled > working. 🔴 A WAIT ON SCREEN IS WAITING BEFORE ITS EPISODE OPENS: the session-state pass holds a waiting window's episode for its grace, and the owner is no less needed in that minute.
Types ¶
type Ask ¶
Ask is one of the chief's own open ask_owner cards: the digest's Needs you group lists them beside the sessions, so there is one place to clear them.
type Digest ¶
Digest is the card: every group in GroupOrder (empty ones included, so a chip row never moves), the total, and what moved since the last look.
type Episode ¶
type Episode struct {
ID int64
// State is the episode's own state: sessionstate's needs_you or stalled.
State string
// Waiting: it opened (or was last seen) waiting on a prompt.
Waiting bool
// Since is when the stop opened.
Since time.Time
// JevLabel is the stall classifier's label ("" when it did not run).
JevLabel string
}
Episode is a session's open stop as the fleet reads it (a session_episodes row, internal/sessionstate).
type Group ¶
type Group struct {
Key, Label string
Sessions []Session
// Asks is the chief's open cards (the Needs you group only).
Asks []Ask
}
Group is one of the digest's groups.
type PG ¶
type PG struct {
// contains filtered or unexported fields
}
PG is Store on Postgres.
type PR ¶
type PR struct {
Repo string `json:"repo"`
Number int64 `json:"number"`
State string `json:"state"`
// HeadSHA12 is the head commit's first 12 hex ("" when unknown).
HeadSHA12 string `json:"head_sha12,omitempty"`
// ClosedAt is when GitHub says it closed (zero while open or unknown).
ClosedAt time.Time `json:"-"`
}
PR is one pull request a session created (session_prs), newest first, with GitHub's state for it.
type Session ¶
type Session struct {
// ID is fleet_list's id ("mirror:<key>", "agent:<id>").
ID string
Kind string
Name string
// Where is a mirrored session's window as the owner finds it in a
// terminal ("" for an agent).
Where string
// Href is where "Open session" goes: the rendered view, the terminal, or
// the agent's conversation.
Href string
State string
Episode *Episode
PRs []PR
// InFlight: a message is queued to it.
InFlight bool
}
Session is one of the owner's sessions as the digest draws it.
type Since ¶
type Since struct {
// Baseline is the previous look; zero: none recorded, nothing is drawn.
Baseline time.Time
// NewStops: sessions whose open stop opened after it.
NewStops int
// Finished: Done sessions whose latest pull request closed after it.
Finished int
// NewQuestions: the chief's open cards asked after it.
NewQuestions int
}
Since is what moved since the owner's previous look (Digest.Since).
type Store ¶
type Store interface {
// Look records a look at the digest at at and returns the baseline the
// card compares against: the previous look, when the one before at is
// LookGap or more ago (it then becomes the baseline), else the baseline
// kept. Zero: no look before this one.
Look(ctx context.Context, at time.Time) (time.Time, error)
// Baseline is the stored baseline, without recording a look.
Baseline(ctx context.Context) (time.Time, error)
// FleetChat is the principal's Fleet side chat's session id (0: none).
FleetChat(ctx context.Context) (int64, error)
// FleetChatOr is the principal's Fleet side chat: the recorded one while
// keep(id) holds, else a new one create makes, recorded. 🔴 ONE CHAT
// HOWEVER MANY CALLERS RACE: the owner's marks row is locked (FOR UPDATE)
// from the read to the record, so a second caller waits, then reads the
// chat the first recorded instead of making another.
FleetChatOr(ctx context.Context, keep func(id int64) bool, create func() (int64, error)) (int64, error)
}
Store is the digest's marks.