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 ActionObject(id int64) string
- func Body(owner string, at time.Time, text string) string
- func CIResultText(n int64, head12 string, ok, bad int, failed []string) string
- func Expired(created, now time.Time) bool
- func ExpiresAt(created time.Time) time.Time
- func GroupOf(state string, prs []PR, inFlight bool) string
- func HandoffText(pr int64, state string) string
- func Header(owner string, at time.Time) string
- func Open(state string) bool
- func PickText(option, question string) string
- func ReassignHandoffText(task int64, to string) string
- func StateOf(waitingNow bool, ep *Episode) string
- func Suppressed(guard string) string
- func TextSHA256(text string) string
- type Action
- type Actions
- type Ask
- type Digest
- type Episode
- type Evidence
- type Group
- type ListFilter
- type Move
- type PG
- func (p *PG) Baseline(ctx context.Context) (time.Time, error)
- func (p *PG) ClaimPush(ctx context.Context, now time.Time) (int, bool, 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) GetAction(ctx context.Context, id int64) (Action, error)
- func (p *PG) HidePush(ctx context.Context) (bool, error)
- func (p *PG) ListActions(ctx context.Context, f ListFilter) ([]Action, error)
- func (p *PG) Look(ctx context.Context, at time.Time) (time.Time, error)
- func (p *PG) MoveAction(ctx context.Context, id int64, from []string, m Move) (Action, bool, error)
- func (p *PG) OpenActions(ctx context.Context) ([]Action, error)
- func (p *PG) Propose(ctx context.Context, pr Proposal) (Action, error)
- func (p *PG) ProposedOn(ctx context.Context, episode int64, class string) (bool, error)
- func (p *PG) PushShown(ctx context.Context) ([]int64, error)
- func (p *PG) SyncPush(ctx context.Context) (PushSync, error)
- type PR
- type Proposal
- type PushSync
- type Session
- type Since
- type Store
Constants ¶
const ( ClassContinue = "continue" ClassHandoff = "handoff" ClassStopNote = "stop_note" ClassCustom = "custom" // ClassWrap is session_wrap's one card, "Write handoff, then close": the // handoff text, then the session's window closed once its handoff turn // has ended. ClassWrap = "wrap" // ClassReassign is work_reassign's one card, two steps: the task routed // to the session it goes to, then the session it leaves asked for its // handoff. ClassReassign = "reassign" // ClassAnswerRule is session_answer continue: a fixed text answering a // session's held plain-text question (an open ask-log row of its stop). ClassAnswerRule = "answer_rule" // ClassAnswerComposed is session_answer composed: the chief's own words, // answering a session's held plain-text question. ClassAnswerComposed = "answer_composed" // ClassAnswerPick is session_answer pick: one of a held picker's own // options, typed into the picker as the owner's tap types it. ClassAnswerPick = "answer_pick" // ClassCIResult is muster's own: the CI running when the session stopped // has finished. ClassCIResult = "ci_result" // ClassClose is a session closed on the owner's tap: A8's fallback // when a wrap's handoff turn never came within 24 h, and // end_session_propose outside an owner turn. ClassClose = "close" )
The action classes this phase writes (0158's CHECK, widened by 0159).
const ( ProposerChief = "chief" ProposerSweep = "sweep_code" )
Who proposed an action (0158's CHECK).
const ( StateProposed = "proposed" StateApproved = "approved" StateRejected = "rejected" StateExpired = "expired" StateQueued = "queued" StateSent = "sent" StateFailed = "failed" )
The action states (0158's CHECK). Suppressed(guard) is the family of "muster did not send it, and why".
const ( // GuardMovedOn: the session left the stop, the idle streak or the pull // request head the action was proposed on, before it was sent. GuardMovedOn = "moved_on" // GuardFlagOff: fleet orchestration was turned off before it was sent. GuardFlagOff = "flag_off" )
The guards a suppressed action names.
const ( ViaWeb = "web" ViaWebEdit = "web_edit" ViaWebBulk = "web_bulk" ViaSweep = "sweep" )
How a decision was made (decided_via).
const ( // MaxCustomBytes bounds a custom text (session_instruct's `custom`). MaxCustomBytes = 4 << 10 // MaxReasonRunes bounds a row's reason (0158's CHECK). MaxReasonRunes = 300 // ProposalTTL is how long a proposal waits for its tap before it expires. ProposalTTL = 12 * time.Hour // PushEvery is the batched push's least gap ("N proposals waiting"). PushEvery = 30 * time.Minute )
Limits.
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 AnswerContinueText = "Yes, continue."
AnswerContinueText is session_answer continue's text (ask-autoapproval's "continue", after muster's attribution line).
const ContinueText = "Yes, continue with what you proposed. Ask with attention_ask before anything destructive, outward or outside this task."
ContinueText is the `continue` class's text (§4.2, after its attribution).
const HeaderPrefix = "[Chief, approved by "
HeaderPrefix starts every text a fleet action pastes: muster's attribution line, naming who approved it and when — never in the owner's voice. It is one of "muster's own pastes" (internal/api nudgeInjectedPrefixes), so the line is never quoted later as the owner's words.
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.
const StopNoteText = "" /* 136-byte string literal not displayed */
StopNoteText is the `stop_note` class's text.
Variables ¶
var ( // ErrAlreadyProposed: an open action of the same class for the same // session exists (fleet_actions_one_open). ErrAlreadyProposed = errors.New("fleet: an action of this class is already open for this session") // ErrActionNotFound: no such action of the principal's. ErrActionNotFound = errors.New("fleet: no such action") // ErrBadProposal: a proposal the store refused before the database. ErrBadProposal = errors.New("fleet: not a valid proposal") )
Errors the store returns.
var AnswerKinds = []string{"continue", "composed", "pick"}
AnswerKinds are session_answer's answer kinds. (merge_when_green is held out until muster can read the audit ladder's verdict: ask-autoapproval decision 6.)
var ClassVerb = map[string]string{ ClassContinue: "Continue", ClassHandoff: "Write handoff", ClassStopNote: "Stop and wait", ClassCustom: "Send the chief's message", ClassWrap: "Write handoff, then close", ClassReassign: "Move a task", ClassAnswerRule: "Answer", ClassAnswerComposed: "Answer (the chief's words)", ClassAnswerPick: "Pick an option", ClassCIResult: "Tell it CI finished", ClassClose: "Close", }
ClassVerb is each class as the card's verb.
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.
var InstructClasses = []string{ClassContinue, ClassHandoff, ClassStopNote, ClassCustom}
InstructClasses are session_instruct's classes.
Functions ¶
func ActionObject ¶ added in v0.251.0
ActionObject is an action's audit object.
func Body ¶ added in v0.251.0
Body is what a fleet action pastes: the attribution line, then its text.
func CIResultText ¶ added in v0.251.0
CIResultText is the ci_result text (§4.2, after muster's attribution line): facts muster read itself, no model text. failed names the failed checks.
func Expired ¶ added in v0.290.0
Expired reports whether a proposal made at created has expired at now.
func ExpiresAt ¶ added in v0.290.0
ExpiresAt is when a proposal made at created expires: ProposalTTL after it. The one rule the card's "expires in …", the tap and the draw all read (internal/api fleetExpire, fleetApprove).
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 HandoffText ¶ added in v0.251.0
HandoffText is the `handoff` text for a session whose latest pull request is number pr in state ("merged" or "closed"; §4.2), or with no pull request known (pr 0): the instruction alone.
func Header ¶ added in v0.251.0
Header is the attribution line for a text owner approved at at: "[Chief, approved by <owner> at HH:MM UTC]".
func Open ¶ added in v0.251.0
Open reports whether state is unfinished: still a proposal, or on its way.
func PickText ¶ added in v0.251.0
PickText is what an answer_pick card shows: the option, and the question.
func ReassignHandoffText ¶ added in v0.251.0
ReassignHandoffText is the second step of a reassign: the session the task left is told where it went, and asked for its handoff.
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.
func Suppressed ¶ added in v0.251.0
Suppressed is the state of an action muster did not send because of guard.
func TextSHA256 ¶ added in v0.251.0
TextSHA256 is the hex SHA-256 of text.
Types ¶
type Action ¶ added in v0.251.0
type Action struct {
ID int64
Owner int64
CreatedAt time.Time
Class string
Proposer string
// SubjectKind and SubjectKey name the session as the stall sweep keys it
// (session_episodes' kind and key).
SubjectKind, SubjectKey string
Host, TmuxSession, Window string
AgentID, ChatSessionID int64
// EpisodeID and StreakKey are the stop and idle streak it was proposed
// on: re-read at the tap and at the paste.
EpisodeID int64
StreakKey string
// Evidence is references only: the pull request's repo, number and head.
Evidence Evidence
Reason string
// Text is what it sends after the attribution line.
Text string
TextSHA256 string
TaskID int64
ToSubject string
State string
Outcome string
DecidedBy int64
DecidedVia string
DecidedAt time.Time
// SendQueueID is the queued message it sent (0: none); RouteID a
// reassign's route.
SendQueueID int64
RouteID string
// CloseAfter is a wrap's close step: the streak its handoff was sent on.
CloseAfter string
FinishedAt time.Time
}
Action is one fleet_actions row.
type Actions ¶ added in v0.251.0
type Actions interface {
// Propose writes p as a proposed action; ErrAlreadyProposed when an open
// action of p's class for p's session exists.
Propose(ctx context.Context, p Proposal) (Action, error)
// GetAction is the principal's action id; ErrActionNotFound for none.
GetAction(ctx context.Context, id int64) (Action, error)
// OpenActions is the principal's unfinished actions, oldest first.
OpenActions(ctx context.Context) ([]Action, error)
// ListActions is the principal's actions, newest first.
ListActions(ctx context.Context, f ListFilter) ([]Action, error)
// MoveAction moves action id from one of from to m, with one audit row
// ("fleet.<class>.<state>"); moved false when it was in none of from.
MoveAction(ctx context.Context, id int64, from []string, m Move) (Action, bool, error)
// ProposedOn reports whether an action of class was ever proposed on
// episode (whatever became of it): the sweep proposes once per stop.
ProposedOn(ctx context.Context, episode int64, class string) (bool, error)
// ClaimPush records a batched push at now when one is due: the last was
// PushEvery or more ago (or never) and a proposal was made after it. The
// count is the open proposals the push names. A due push also records the
// waiting proposals it shows (SyncPush's baseline).
ClaimPush(ctx context.Context, now time.Time) (count int, due bool, err error)
// SyncPush compares the proposals waiting now with the ones the owner's
// "N proposals waiting" notification shows, and records the new set when
// it changed. It never touches ClaimPush's clock.
SyncPush(ctx context.Context) (PushSync, error)
// HidePush records that no such notification is showing; showing reports
// whether one was (fleet proposals turned off).
HidePush(ctx context.Context) (showing bool, err error)
// PushShown is the waiting set the notification shows, as recorded; nil
// when none is showing (a withdrawal's re-check reads it).
PushShown(ctx context.Context) ([]int64, error)
}
Actions is the action log's store.
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 Evidence ¶ added in v0.251.0
type Evidence struct {
PRRepo string `json:"pr_repo,omitempty"`
PRNumber int64 `json:"pr_number,omitempty"`
PRState string `json:"pr_state,omitempty"`
// PRHead is the pull request's head commit, 12 hex, when it was read.
PRHead string `json:"pr_head,omitempty"`
// SubjectID is the session's fleet id ("mirror:<key>", "agent:<id>").
SubjectID string `json:"subject_id,omitempty"`
// Label is the session's name as the card shows it (muster's own label:
// a focus title or a window name, cut).
Label string `json:"label,omitempty"`
// Runtime is the session's runtime ("" for Claude Code, "opencode", "pod").
Runtime string `json:"runtime,omitempty"`
// PRHeadFull is the full head a ci_result read (40 hex).
PRHeadFull string `json:"pr_head_full,omitempty"`
// AskID, AskTool and Option are an answer_pick's held picker (its
// internal/askq entry and call) and the option it picks.
AskID string `json:"ask_id,omitempty"`
AskTool string `json:"ask_tool,omitempty"`
Option string `json:"option,omitempty"`
// AskLogID is an answer_rule / answer_composed's held question: the open
// ask-log row (internal/asklog) of the session's stop it answers.
AskLogID int64 `json:"ask_log_id,omitempty"`
}
Evidence is an action's references: never transcript text.
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 ListFilter ¶ added in v0.251.0
type ListFilter struct {
Since time.Time
State string
// Subject is one session, matched EXACTLY and before Limit: "mirror:<key>"
// its key; "agent:<id>" every stop of that agent (its keys are
// "<id>:<conversation>") — never another id that starts with it.
Subject string
Limit int
}
ListFilter narrows ListActions.
type Move ¶ added in v0.251.0
type Move struct {
State string
Outcome string
// Decision fields, set on the move that decides it.
DecidedVia string
DecidedBy int64
// Links the delivery makes.
SendQueueID int64
RouteID string
CloseAfter string
// Finish ends the action (finished_at = now()).
Finish bool
}
Move is one state change (MoveAction).
type PG ¶
type PG struct {
// contains filtered or unexported fields
}
PG is Store on Postgres.
func (*PG) FleetChatOr ¶
func (p *PG) FleetChatOr(ctx context.Context, keep func(id int64) bool, create func() (int64, error)) (int64, error)
FleetChatOr implements Store.
func (*PG) ListActions ¶ added in v0.251.0
ListActions implements Actions.
func (*PG) MoveAction ¶ added in v0.251.0
MoveAction implements Actions.
func (*PG) OpenActions ¶ added in v0.251.0
OpenActions implements Actions.
func (*PG) ProposedOn ¶ added in v0.251.0
ProposedOn implements Actions.
func (*PG) SyncPush ¶ added in v0.297.0
SyncPush implements Actions.
🔴 ONE ROW LOCK DECIDES: two passes (or a pass and a tap) that race read the same mark under FOR UPDATE, so a change is acted on once — the second finds the set already recorded. NULL (nothing showing) is left NULL: a notification is only ever replaced or withdrawn, never raised, here.
🔴 ONLY A SHRINK IS ACTED ON (operator decision "respect the swipe"): a proposal the push counted that no longer waits. Growth alone — a new proposal — changes nothing here and leaves the mark as it was: a quiet replacement would resurrect a push the owner swiped away for news they have not been alerted to, and ClaimPush's next alert tells them (out loud).
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 Proposal ¶ added in v0.251.0
type Proposal struct {
Class, Proposer string
SubjectKind, SubjectKey string
Host, TmuxSession, Window string
AgentID, ChatSessionID int64
EpisodeID int64
StreakKey string
Evidence Evidence
Reason string
Text string
TaskID int64
ToSubject string
}
Proposal is what Propose writes.
type PushSync ¶ added in v0.297.0
type PushSync struct {
// Withdraw: a notification was showing and no proposal waits now.
Withdraw bool
// Replace: a notification is showing and a proposal it counted no longer
// waits: it is replaced in place with Count and the newest still waiting
// (Newest). A set that only GREW is not replaced (the swipe rule: a new
// proposal waits for ClaimPush's alert, never resurrects the push).
Replace bool
Count int
Newest int64
}
PushSync is what SyncPush found. Nothing to do unless Withdraw or Replace.
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.