fleet

package
v0.256.0 Latest Latest
Warning

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

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

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

View Source
const (
	ProposerChief = "chief"
	ProposerSweep = "sweep_code"
)

Who proposed an action (0158's CHECK).

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

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

View Source
const (
	ViaWeb     = "web"
	ViaWebEdit = "web_edit"
	ViaWebBulk = "web_bulk"
	ViaSweep   = "sweep"
)

How a decision was made (decided_via).

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

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

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

View Source
const (
	GroupNeedsYou  = "needs_you"
	GroupWaitingCI = "waiting_ci"
	GroupWorking   = "working"
	GroupDone      = "done"
	GroupStalled   = "stalled"
)

The digest's groups, in the order the card draws them.

View Source
const AnswerContinueText = "Yes, continue."

AnswerContinueText is session_answer continue's text (ask-autoapproval's "continue", after muster's attribution line).

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

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

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

View Source
const StopNoteText = "" /* 136-byte string literal not displayed */

StopNoteText is the `stop_note` class's text.

Variables

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

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

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

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

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

GroupOrder is the card's order of the groups.

InstructClasses are session_instruct's classes.

Functions

func ActionObject added in v0.251.0

func ActionObject(id int64) string

ActionObject is an action's audit object.

func Body added in v0.251.0

func Body(owner string, at time.Time, text string) string

Body is what a fleet action pastes: the attribution line, then its text.

func CIResultText added in v0.251.0

func CIResultText(n int64, head12 string, ok, bad int, failed []string) string

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 GroupOf

func GroupOf(state string, prs []PR, inFlight bool) string

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

func HandoffText(pr int64, state string) string

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(owner string, at time.Time) string

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

func Open(state string) bool

Open reports whether state is unfinished: still a proposal, or on its way.

func PickText added in v0.251.0

func PickText(option, question string) string

PickText is what an answer_pick card shows: the option, and the question.

func ReassignHandoffText added in v0.251.0

func ReassignHandoffText(task int64, to string) string

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

func StateOf(waitingNow bool, ep *Episode) string

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

func Suppressed(guard string) string

Suppressed is the state of an action muster did not send because of guard.

func TextSHA256 added in v0.251.0

func TextSHA256(text string) string

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.
	ClaimPush(ctx context.Context, now time.Time) (count int, due bool, err error)
}

Actions is the action log's store.

type Ask

type Ask struct {
	ID        int64
	Question  string
	CreatedAt time.Time
}

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

type Digest struct {
	Total  int
	Groups []Group
	Since  Since
}

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.

func Build

func Build(sessions []Session, asks []Ask, baseline time.Time) Digest

Build is the digest of sessions and the chief's open asks, against baseline (the owner's previous look; zero for none). Each session is in exactly one group (GroupOf), or none when its state is unknown — the total counts every session given.

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.

func (Group) Count

func (g Group) Count() int

Count is the group's count: its sessions and asks.

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 NewPG

func NewPG(pool *pgxpool.Pool) *PG

NewPG is Store over pool.

func (*PG) Baseline

func (p *PG) Baseline(ctx context.Context) (time.Time, error)

Baseline implements Store.

func (*PG) ClaimPush added in v0.251.0

func (p *PG) ClaimPush(ctx context.Context, now time.Time) (int, bool, error)

ClaimPush implements Actions.

func (*PG) FleetChat

func (p *PG) FleetChat(ctx context.Context) (int64, error)

FleetChat implements Store.

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) GetAction added in v0.251.0

func (p *PG) GetAction(ctx context.Context, id int64) (Action, error)

GetAction implements Actions.

func (*PG) ListActions added in v0.251.0

func (p *PG) ListActions(ctx context.Context, f ListFilter) ([]Action, error)

ListActions implements Actions.

func (*PG) Look

func (p *PG) Look(ctx context.Context, at time.Time) (time.Time, error)

Look implements Store.

func (*PG) MoveAction added in v0.251.0

func (p *PG) MoveAction(ctx context.Context, id int64, from []string, m Move) (Action, bool, error)

MoveAction implements Actions.

func (*PG) OpenActions added in v0.251.0

func (p *PG) OpenActions(ctx context.Context) ([]Action, error)

OpenActions implements Actions.

func (*PG) Propose added in v0.251.0

func (p *PG) Propose(ctx context.Context, pr Proposal) (Action, error)

Propose implements Actions.

func (*PG) ProposedOn added in v0.251.0

func (p *PG) ProposedOn(ctx context.Context, episode int64, class string) (bool, error)

ProposedOn implements Actions.

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

Jump to

Keyboard shortcuts

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