Documentation
¶
Overview ¶
Package attention is the ATTENTION QUEUE's explicit asks (migration 0025): a question an agent — a dispatched agent or a mirrored Claude Code session — puts to its owner, and the owner's answer.
The attention VIEW (internal/api) is wider: it also lists mirrored sessions waiting on the person and reply drafts awaiting approval. Those are derived live from the state that owns them; only the explicit asks are stored, here.
🔴 THE STORE HAS TWO HALVES AND THEY RUN UNDER DIFFERENT PRINCIPALS. Ask, Get, Open, Answer, AnswerFromSession and Cancel run under the CALLER's principal: attention_asks is under FORCE row-level security, so a request sees, asks into and answers only its own user's rows, and the owner of a new row is the principal's user (owner_id's default), never a parameter. ExpireDue runs under the system scope (sys): the sweep moves every owner's lapsed asks and hands each back with its owner, so the caller can notify that owner and no other. The delivery sweep's two (DueDeliveries, RecoverDeliveries) are the same shape: every owner's rows, each handed back with its owner, so the caller delivers under THAT owner's principal.
🔴 AN ANSWER TO AN AGENT IS DELIVERED (migration 0031). Answer queues the delivery in the same statement; the caller (internal/api) pushes it into the asker's session as a turn exactly once, unless the asker read it with attention_wait first (MarkWaited) — see the Delivery states.
🔴 AN ASK LEAVES "open" ONCE. Answer, Cancel and ExpireDue are each one UPDATE conditional on status = 'open' (and, for an answer or a cancel, on the ask not having lapsed), so a concurrent answer and cancel cannot both land: the loser reads ErrNotOpen and the row as the winner left it.
Index ¶
- Constants
- Variables
- func AskObject(id int64) string
- func CleanAnswer(s string) (string, error)
- func CleanSuggestions(in, options []string) []string
- func IsOwnerDoor(ctx context.Context, owner int64) bool
- func SourceBody(body string) (out string, cut bool)
- type AnswerSource
- type Ask
- type AskWhy
- type Asker
- type Attachment
- type Delivery
- type ItemContext
- type Kind
- type New
- type PGStore
- func (s *PGStore) Answer(ctx context.Context, id int64, answer string) (Ask, error)
- func (s *PGStore) AnswerByChief(ctx context.Context, id int64, answer string) (Ask, error)
- func (s *PGStore) AnswerFromSession(ctx context.Context, id int64, answer, host, session string) (Ask, error)
- func (s *PGStore) AnswerInSession(ctx context.Context, asker Asker, message string, queueID int64, ...) ([]Ask, error)
- func (s *PGStore) AnswerTeamPageCard(ctx context.Context, id int64, answer string) (Ask, error)
- func (s *PGStore) Answered(ctx context.Context, since time.Time, limit int) ([]Ask, error)
- func (s *PGStore) AnsweredByQueue(ctx context.Context, ids []int64) (map[int64]string, error)
- func (s *PGStore) AnswersForTask(ctx context.Context, taskID int64) ([]Ask, error)
- func (s *PGStore) Cancel(ctx context.Context, id int64) (Ask, error)
- func (s *PGStore) CancelTeamPageCard(ctx context.Context, id int64) (Ask, error)
- func (s *PGStore) ClaimDelivery(ctx context.Context, id int64, by string, lease, grace time.Duration) (Ask, bool, error)
- func (s *PGStore) Create(ctx context.Context, n New) (Ask, error)
- func (s *PGStore) DueDeliveries(ctx context.Context, grace time.Duration, limit int) ([]Ask, error)
- func (s *PGStore) ExpireDue(ctx context.Context) ([]Ask, error)
- func (s *PGStore) FinishDelivery(ctx context.Context, id int64, by string, delivered bool, sessionID int64, ...) (bool, error)
- func (s *PGStore) Get(ctx context.Context, id int64) (Ask, error)
- func (s *PGStore) MarkQuestionTurn(ctx context.Context, id int64) (bool, error)
- func (s *PGStore) MarkWaited(ctx context.Context, id int64) (bool, error)
- func (s *PGStore) Open(ctx context.Context) ([]Ask, error)
- func (s *PGStore) OpenForTask(ctx context.Context, taskID int64) ([]Ask, error)
- func (s *PGStore) QuestionsDue(ctx context.Context, limit int) ([]Ask, error)
- func (s *PGStore) RecoverDeliveries(ctx context.Context) ([]Ask, error)
- func (s *PGStore) ReleaseDelivery(ctx context.Context, id int64, by, detail string) error
- func (s *PGStore) RetryDelivery(ctx context.Context, id int64) (Ask, error)
- func (s *PGStore) Search(ctx context.Context, q Search) ([]Ask, error)
- func (s *PGStore) SessionAskCounts(ctx context.Context, q SessionAsksQuery) (open, total int, err error)
- func (s *PGStore) SessionAsks(ctx context.Context, q SessionAsksQuery) ([]Ask, error)
- func (s *PGStore) SetSuggestions(ctx context.Context, id int64, suggestions []string) (Ask, bool, error)
- func (s *PGStore) UnmarkQuestionTurn(ctx context.Context, id int64) error
- func (s *PGStore) WithdrawAbout(ctx context.Context, agentID int64, key string, except int64) ([]Ask, error)
- type Search
- type SessionAsksQuery
- type SourceMessage
- type Status
- type StepUpCard
- type StepUpMedium
- type Store
- type WithAudit
Constants ¶
const ( // MaxAttachments is how many files one ask may carry (0145's CHECK holds 4). MaxAttachments = askattach.MaxCount // MaxAttachmentNameRunes bounds an attachment's shown name. MaxAttachmentNameRunes = 120 // MaxWhyRunes bounds the agent's own context: a longer one is REFUSED, as // an over-long question is. MaxWhyRunes = 500 // MaxWhyFocusRunes and MaxWhyLastRunes bound the fallback's two fields; a // longer one is cut (muster built it, so there is nobody to refuse). MaxWhyFocusRunes = 200 MaxWhyLastRunes = 600 )
The bounds of an ask's attachments and why.
const ( ViaBrowser = "browser" ViaDevice = "device" )
The owner's own doors (migration 0092), stamped by Answer from the answering principal: the Attention view in a signed-in browser session, and the owner's paired phone. NULL (the zero AnswerSource) is an answer recorded before 0092, one settled in session, or one whose principal was neither — and no binding reads that as an owner's door.
const ( MaxQuestionRunes = 4000 MaxOptions = 10 MaxOptionRunes = 200 MaxAnswerRunes = 8000 MaxLabelRunes = 200 // MaxOpenPerOwner bounds one owner's open asks: an agent asking in a loop // would otherwise fill the view (and the owner's lock screen) without limit. MaxOpenPerOwner = 50 // DefaultTimeout is how long an ask waits for an answer when the asker // names no timeout; MinTimeout and MaxTimeout clamp one it does name. DefaultTimeout = 24 * time.Hour MinTimeout = time.Minute MaxTimeout = 7 * 24 * time.Hour )
The bounds, each also a CHECK in 0025.
const ( MaxSuggestions = 3 MaxSuggestionRunes = 140 )
MaxSuggestions and MaxSuggestionRunes bound an ask's stored suggested replies (0057's CHECK holds the count).
const ( // MaxContextFieldRunes bounds each one-line field. MaxContextFieldRunes = 200 // MaxSourceBodyRunes and MaxSourceBodyLines bound the source message's // body as an ask shows it; a longer one is cut, with Truncated set. MaxSourceBodyRunes = 1500 MaxSourceBodyLines = 30 )
The bounds of an ItemContext.
const ( MaxStepUpTitleRunes = 200 MaxStepUpWhyRunes = 300 MaxStepUpAboutRunes = 200 MaxStepUpAskerRunes = 200 MaxStepUpVenueRunes = 64 MaxStepUpToolRunes = 64 MaxStepUpPreviewRunes = 2600 MaxStepUpDetailsRunes = 3000 MaxStepUpExcerptRunes = 300 MaxStepUpParts = 1000 MaxStepUpMedia = 4 MaxStepUpMediumRunes = 150 )
The bounds of a StepUpCard. A card's Text must fit MaxQuestionRunes: the sum of these (with its separators) stays under it.
const ByChief = "chief"
ByChief is answered_by for the chief's answer to a question a mirrored session put to it with chief_ask (New.ToChief, migration 0050): the only ask an agent answers (AnswerByChief).
const ByOperator = "operator"
ByOperator is who answers an ask: the operator — on the attention view, or (migration 0034) through one of their own mirrored Claude Code sessions' attention_answer. No dispatched agent answers one — not even the chief — except a question a mirrored session addressed TO the chief (ByChief).
const DeliveryLapsedDetail = "muster stopped while delivering it, so the agent may or may not have received it"
DeliveryLapsedDetail is an unconfirmed delivery's detail when its process stopped mid-turn.
const MaxDeliveryDetailRunes = 300
MaxDeliveryDetailRunes bounds DeliveryDetail (0031's CHECK).
const MaxNoteRunes = 1000
MaxNoteRunes bounds an owner's note on a multi-select answer, as the form's box does (maxlength). The WHOLE answer — every picked label, the separator and the note — is what MaxAnswerRunes then bounds (CleanAnswer): a note that pushes it past is refused, and the owner shortens it, exactly as an over-long free-text answer is.
const MaxSearchResults = 200
MaxSearchResults bounds one search.
const MaxSearchTextRunes = 200
MaxSearchTextRunes bounds a search's text.
const MaxSessionAsks = 50
MaxSessionAsks bounds one session's list.
const NotePrefix = " — note: "
NotePrefix introduces the owner's optional note on a multi-select answer: "a; b — note: use the staging key". Appended to the joined labels by the answer form's handler; a single-select answer never carries one.
const OptionSep = "; "
OptionSep joins the option labels a MULTI-select ask's answer picked into the one answer string stored (attention_asks.multi, migration 0175): the owner ticks "a" and "b" and the answer recorded is "a; b". A single-select answer is one label and never holds it. It is the same separator a multi-select owner card joins its picks with (ui.OwnerAskMultiSep): both answers read the same way to whoever reads them back.
const SystemAskerLabel = "muster"
SystemAskerLabel is the label of an ask muster itself raised.
const ViaMCP = "mcp"
ViaMCP is answered_via for an answer given through attention_answer, from a mirrored session (migration 0034). An answer given on the attention view has no answered_via.
Variables ¶
var ( // ErrInvalid: the ask or answer breaks a bound (its text says which). ErrInvalid = errors.New("attention: invalid") // ErrAnswerTooLong: an answer over MaxAnswerRunes (CleanAnswer), always // with ErrInvalid — the one refusal a form can name on its own, since a // dictated answer can run past the bound. // Its text is the refusal's own words, as every other bound's. ErrAnswerTooLong = fmt.Errorf("the answer is longer than %d characters", MaxAnswerRunes) // ErrNotFound: no such ask among the caller's. ErrNotFound = errors.New("attention: no such ask") // ErrNotOpen: the ask was already answered, cancelled or expired. ErrNotOpen = errors.New("attention: the ask is no longer open") // ErrSameHost: a mirrored session tried to answer an OPEN ask that a // mirrored session on its OWN host raised (AnswerFromSession). // // 🔴 THE HOST IS THE PRINCIPAL, NOT THE SESSION. muster knows a mirrored // caller's host from its token, but the session only from the pane the // caller names (X-Muster-Pane, set by the caller; the host's MCP secret is // readable by every session of its user), so one session can claim to be // a sibling pane. A per-session "not your own ask" rule would rest on that // claim; a per-host rule rests only on the token. ErrSameHost = errors.New("attention: a mirrored session cannot answer an ask raised by a session on its own host") // ErrTooMany: the owner already has MaxOpenPerOwner open asks. ErrTooMany = fmt.Errorf("attention: there are already %d open asks; wait for some to be answered", MaxOpenPerOwner) // ErrNotice: an answer to a notice (KindNotice). A notice points at a // session; it has nothing to answer, so nothing is recorded or relayed. ErrNotice = errors.New("attention: that is a notice, not a question: it has no answer (open its session, or dismiss it)") )
var ErrNotOwnerDoor = errors.New("attention: this question is your owner's to answer, in muster or on their phone")
ErrNotOwnerDoor: an owner card answered through a door that is not the owner's own (answerSQL); the card stays open.
var ErrNotRetryable = errors.New("attention: only an answer whose delivery failed can be delivered again")
ErrNotRetryable: only an unconfirmed delivery can be retried.
Functions ¶
func CleanAnswer ¶
CleanAnswer validates an answer's text.
func CleanSuggestions ¶
CleanSuggestions is in as an ask stores it: each trimmed; a blank one, an over-long one (more than MaxSuggestionRunes), a line-broken one and a duplicate (of another suggestion or of one of options, case aside) dropped; at most MaxSuggestions kept. A chip is sent as written, so a suggestion is kept whole or not at all.
func IsOwnerDoor ¶ added in v0.170.0
IsOwnerDoor reports whether ctx is owner answering through one of their own doors — a signed-in browser session or their paired phone (answerVia) — and nobody else. THE predicate a binding to the owner's own tap uses (a release); answerSQL holds an owner card to the same doors.
func SourceBody ¶ added in v0.224.0
SourceBody is body as an ask shows it: CRLF folded, every fence.Unsafe code point but the line break replaced (fence.Sanitize per line), blank edges trimmed, then cut to MaxSourceBodyLines lines and MaxSourceBodyRunes runes; cut reports whether anything was dropped.
Types ¶
type AnswerSource ¶
AnswerSource is where the operator gave an answer when it was NOT the attention view: Via (ViaMCP) and the mirrored session it came from (Host, the session's mirror host; Session, its Claude session id). The zero value is the view.
func (AnswerSource) OwnerDoor ¶ added in v0.170.0
func (src AnswerSource) OwnerDoor() bool
OwnerDoor reports whether src is one of the owner's own doors — their browser or their phone (0092) — the doors IsOwnerDoor admits for a release, read back from the row. An MCP answer, an unrecorded door and an answer settled in session are not.
func (AnswerSource) String ¶
func (src AnswerSource) String() string
String is "<host>/<session>", "" for the view.
func (AnswerSource) ViaSession ¶
func (src AnswerSource) ViaSession() bool
ViaSession reports whether src names a mirrored session (an MCP answer).
type Ask ¶
type Ask struct {
ID int64 `json:"id"`
// Kind is KindAsk or KindNotice (migration 0071).
Kind Kind `json:"kind,omitempty"`
Owner int64 `json:"-"`
Asker Asker `json:"-"`
Question string `json:"question"`
Options []string `json:"options"`
// Multi: the asker's options are CHECKBOXES — the owner may pick any
// number — and a picked answer is the labels joined by OptionSep
// (migration 0175). false (every row before 0175, and every ordinary ask)
// is one option, one button. It is PAGE-ONLY: the phone's notification
// answers with one chip (internal/push), whatever this says.
Multi bool `json:"multi,omitempty"`
Status Status `json:"status"`
Answer string `json:"answer,omitempty"`
AnsweredBy string `json:"answered_by,omitempty"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt time.Time `json:"expires_at"`
ResolvedAt time.Time `json:"resolved_at,omitzero"`
// Delivery is the answer's delivery to the asker (migration 0031), ""
// when there is nothing to deliver; DeliveryDetail why it is waiting or
// failed; DeliveredSession the chat session it went to (0 = none).
Delivery Delivery `json:"-"`
DeliveryDetail string `json:"-"`
DeliveryAttempts int `json:"-"`
DeliveredSession int64 `json:"-"`
// DeliveryQueuedAt is when the delivery was last queued (the answer, or a
// Retry); zero when there is none.
DeliveryQueuedAt time.Time `json:"-"`
// TaskID is the task the ask is about (migration 0032), 0 for none. Only
// muster's own task path sets it (New.TaskID); an agent's attention_ask
// never does.
TaskID int64 `json:"task_id,omitempty"`
// AnsweredVia is where the operator gave the answer when it was not the
// attention view (migration 0034): the zero value for the view (and for
// every answer recorded before 0034).
AnsweredVia AnswerSource `json:"-"`
// AnsweredByUser is the PERSON whose update answered the ask (migration
// 0127's answered_by_user, stamped by the database from muster.uid, never
// by the statement): on a team's ask, the member who answered it. 0 for an
// ask that is not answered, or was answered before 0127.
AnsweredByUser int64 `json:"-"`
// ToChief: a mirrored session's question to its owner's chief (chief_ask,
// migration 0050) — the chief may answer it (AnswerByChief), and the owner's
// Attention queue does not list it.
ToChief bool `json:"-"`
// RouteID is a question's routed message (New.RouteID), "" for none.
RouteID string `json:"-"`
// Suggestions are the suggested replies generated for the ask while it was
// open (migration 0057, SetSuggestions), at most MaxSuggestions; empty for
// none.
Suggestions []string `json:"-"`
// OwnerCard: ask_owner's stored card (New.OwnerCard, migration 0092).
OwnerCard bool `json:"-"`
// AskedSession is the chat session key the chief asked an owner card in
// (New.AskedSession), "" for unknown.
AskedSession string `json:"-"`
// SubjectKey is the session the chief's ask was raised about (New.SubjectKey,
// migration 0103), "" for none.
SubjectKey string `json:"-"`
// Context is the officer item the ask is about (New.Context, migration
// 0129), nil for none.
Context *ItemContext `json:"-"`
// Attachments are the files the asker attached (New.Attachments,
// migration 0145), nil for none.
Attachments []Attachment `json:"-"`
// Why is why the ask is here (New.Why, migration 0145), nil for none.
Why *AskWhy `json:"-"`
// StepUp is a step-up confirmation card's parts (New.StepUp, migration
// 0171), nil for every other ask and for a card filed before 0171.
StepUp *StepUpCard `json:"-"`
}
Ask is one explicit ask.
func (Ask) ChosenOption ¶ added in v0.170.0
ChosenOption is the index of the stored option a's answer picked: the answer is exactly one of a's OWN stored options (the label a button sends), and ok is false for a free-text answer, an unanswered ask, or a notice. It binds a tap to the option tapped by the row muster stored, never by text the asker wrote afterwards. Whether the door was the owner's is a separate question (AnsweredVia.OwnerDoor).
A MULTI-select answer that picked several options joins them with OptionSep ("a; b") and so matches none of them here: ok is false. A multi answer that picked exactly one label still reads as that option.
type AskWhy ¶ added in v0.243.0
type AskWhy struct {
Text string `json:"text,omitempty"`
Focus string `json:"focus,omitempty"`
Last string `json:"last,omitempty"`
}
AskWhy is why an ask is here: Text (the agent's own context), or the fallback Focus and Last. Exactly one of the two forms is ever stored.
type Asker ¶
type Asker struct {
AgentID int64
MirrorHost string
MirrorSession string
// System: muster itself raised the ask (no agent, no session).
System bool
// Label is the name the view shows beside the question.
Label string
}
Asker is who raised an ask: a dispatched agent (AgentID), a mirrored session (MirrorHost + MirrorSession: a Claude Code session id, or a mirrored opencode session's key, "opencode:<id>" — mirror.ValidMCPCaller), or muster itself (System: an ask nobody waits on, migration 0028). Exactly one is set.
type Attachment ¶ added in v0.243.0
type Attachment struct {
// ID is the upload's public id (uploads.Upload.PublicID); its object is
// "uploads/" + ID.
ID string `json:"id"`
// Name is the upload's cleaned filename, as the owner is shown it.
Name string `json:"name"`
// Type is the type muster SNIFFED from the bytes when it stored them.
Type string `json:"type"`
Size int64 `json:"size"`
}
Attachment is one file an ask carries: an upload of the ask's owner.
func CleanAttachments ¶ added in v0.243.0
func CleanAttachments(in []Attachment) ([]Attachment, error)
CleanAttachments is in as an ask stores it: each id an upload public id, none twice, at most MaxAttachments; each name sanitised and bounded (a blank one is "file"); each type one line; each size positive. nil for none.
type Delivery ¶
type Delivery string
Delivery is where an answer stands on its way to the asker (migration 0031).
const ( // DeliveryNone: nothing to deliver (not answered by the operator in the // queue, a system asker's, or answered before delivery existed). DeliveryNone Delivery = "" // DeliveryQueued: answered; a delivery into the asking agent's session is owed. DeliveryQueued Delivery = "queued" // DeliveryDelivering: one process holds the delivery lease. DeliveryDelivering Delivery = "delivering" // DeliveryDelivered: the turn completed in DeliveredSession. DeliveryDelivered Delivery = "delivered" // DeliveryUnconfirmed: the turn failed after the text may have reached the // agent, its lease lapsed mid-turn, or it was still queued a day on. Never // resent unless the operator retries it (RetryDelivery) — and not even // then once the asker has read it (MarkWaited moves it to waited). DeliveryUnconfirmed Delivery = "unconfirmed" // DeliveryWaited: the asker read the answer through attention_wait. DeliveryWaited Delivery = "waited" // DeliveryPull: a mirrored session's answer, left for its attention_wait. DeliveryPull Delivery = "pull" )
type ItemContext ¶ added in v0.224.0
type ItemContext struct {
Officer string `json:"officer"`
ItemID int64 `json:"item_id"`
Kind string `json:"kind"`
Subject string `json:"subject"`
// Source is the plugin message the item is, nil for an item no plugin
// message became.
Source *SourceMessage `json:"source,omitempty"`
}
ItemContext is the officer item an ask is about, as muster read it.
type Kind ¶ added in v0.138.0
type Kind string
Kind is what an attention_asks row is (migration 0071).
const ( // KindAsk is a question: it has an answer (or is dismissed or expires). // Every row before 0071 is one. KindAsk Kind = "ask" // KindNotice is a POINTER muster raised itself (today: a live chief nudge, // internal/api actAsk) at a session the owner may want to look at. It has // no options and no answer — never answered, only dismissed, withdrawn or // expired — and it does NOT count toward MaxOpenPerOwner. // // 🔴 NEVER ANSWERED, IN THREE PLACES: Clean refuses options on one; the // answer UPDATE (answerSQL) moves only kind = 'ask'; and 0071's CHECK // refuses an answer on a notice row whatever wrote it. KindNotice Kind = "notice" )
type New ¶
type New struct {
Asker Asker
Question string
Options []string
// Multi: the asker's options are checkboxes, so the owner may pick any
// number and the answer is the labels joined by OptionSep (migration
// 0175). false is the single-select default, unchanged.
Multi bool
// TaskID links the ask to one of the caller's tasks (0: none). Set ONLY by
// muster's task path (internal/api askOwnerAboutTask), never from an
// agent's arguments: agent_dispatch trusts it as the provenance of the
// owner's answer.
TaskID int64
// PluginMessageID links the ask to the plugin message it was raised for
// (0: none; migration 0051). Set ONLY by muster's unrouted-message sweep
// (internal/api unrouted.go; docs/plugins.md#a-message-the-chief-does-not-act-on).
PluginMessageID int64
// Timeout is how long the ask waits; 0 is DefaultTimeout, and anything
// else is clamped to [MinTimeout, MaxTimeout].
Timeout time.Duration
// ToChief addresses the ask to the owner's chief: set only by the mirrored
// sessions' chief_ask, and it writes an audit row with the ask
// (chief_question.asked). RouteID, when set, is the routed message the
// question is about, stored with it (a retried turn quotes it again) and
// on that row.
ToChief bool
RouteID string
// Notice files a KindNotice instead of a question: muster's own (System
// asker), no options, no task, never to the chief — Clean refuses
// anything else. It is not counted toward MaxOpenPerOwner.
Notice bool
// OwnerCard files ask_owner's stored card (internal/api raiseOwnerCard
// only): answered only through the owner's own doors (answerSQL), and a
// message the owner types to the asker settles at most one open card
// (AnswerInSession). AskedSession is the chat session key it was asked in
// ("" for unknown), where its answer is delivered.
OwnerCard bool
AskedSession string
// SubjectKey is the session key (chat_messages.about) of the owner's view
// line the chief was answering when it raised the ask (migration 0103), ""
// for none. Set ONLY by internal/api (chiefAskSubject), never from an
// asker's arguments: WithdrawAbout withdraws by it when the chief files a
// proposal about that session.
SubjectKey string
// Context is the officer item the ask is about (migration 0129), nil for
// none. Set ONLY by muster's builtin-officer path (internal/api
// officerItemContext), never from an asker's arguments; Clean sanitises
// and bounds it (item_context.go).
Context *ItemContext
// Attachments are files of the asker's owner's upload store the ask
// carries (migration 0145; ask_media.go), nil for none. Set ONLY by
// internal/api's attention_ask, from upload rows it read under the
// owner's principal; Clean checks their shape and count.
Attachments []Attachment
// Why is why the ask is here (migration 0145): the agent's own context, or
// muster's fallback (ask_media.go). Clean sanitises and bounds it.
Why *AskWhy
// StepUp is a step-up confirmation card's parts (migration 0171;
// step_up.go): set ONLY by internal/api's hostStepUpGate, on a System
// ask. When set, Clean REPLACES Question with StepUp.Text() — the one
// text the card's push, page and phone prompt read.
StepUp *StepUpCard
// With is an audit row written in Create's OWN transaction, as the
// caller's principal, naming the new ask (Detail is called with its id):
// nil for none. Set ONLY by internal/api's agent_dispatch, for a held
// dispatch's card (its hold): the card and its hold then commit together,
// so no reader ever sees the card without its hold.
With *WithAudit
}
New is what an asker supplies.
type PGStore ¶
type PGStore struct {
// contains filtered or unexported fields
}
PGStore is Store on Postgres.
func (*PGStore) Answer ¶
Answer records the owner's answer from the Attention view or their phone, stamping the door from ctx's principal (answerVia; NULL for any other).
func (*PGStore) AnswerByChief ¶
AnswerByChief records the chief's answer to question id — an open question a mirrored session addressed to the chief (ToChief) — as answered_by ByChief, left for the session's attention_wait (pull), with its audit row. Any other ask, another owner's (row-level security) and a missing one are ErrNotFound alike: the chief answers no ask but one put to it.
func (*PGStore) AnswerFromSession ¶
func (s *PGStore) AnswerFromSession(ctx context.Context, id int64, answer, host, session string) (Ask, error)
AnswerFromSession runs under the caller's principal, like Answer: row-level security keeps it to the caller's own asks, so another owner's ask is ErrNotFound exactly as a missing one is.
func (*PGStore) AnswerInSession ¶
func (s *PGStore) AnswerInSession(ctx context.Context, asker Asker, message string, queueID int64, keep func(Ask) bool) ([]Ask, error)
AnswerInSession runs under the caller's principal, like Answer: row-level security keeps it to the caller's own asks.
🔴 ONLY ASKS RAISED BEFORE THE MESSAGE: the caller runs it as the message is sent (or queued), and an ask is answered only when its created_at is before this UPDATE's statement_timestamp() — the time the statement began.
🔴 ONE OWNER CARD PER MESSAGE (#496's one card per answer): of the asker's open owner cards (OwnerCard), only the OLDEST is settled — the one the chat draws as the card this message answers — and every other stays open for its own answer. Every other ask settles as it always did.
func (*PGStore) AnswerTeamPageCard ¶ added in v0.256.0
AnswerTeamPageCard records a team MEMBER's answer to a team agent's page share card (migration 0165's muster_answer_team_page_card): an open owner card of a team the caller is a member of (viewer and up), answered from their browser or paired phone (answerVia), whose page link the caller has already decided. The answer is the same transition as Answer's, the caller recorded as answered_by_user. 0127 writes attention_asks at operator, so a viewer's answer through Answer would not record; this one function, in the database, is the narrow door. ErrNotOpen (with the card as it stands) for a row that is not such a card.
func (*PGStore) AnsweredByQueue ¶
AnsweredByQueue runs under the caller's principal (row-level security keeps it to their own asks).
func (*PGStore) AnswersForTask ¶
AnswersForTask runs under the caller's principal (row-level security keeps it to their own asks), and names the owner as well.
func (*PGStore) CancelTeamPageCard ¶ added in v0.256.0
CancelTeamPageCard withdraws a team page link's card on behalf of the team member who revoked the link (migration 0165's muster_cancel_team_page_card): an open owner card of a team the caller is a member of, named by a revoked, agent-made link of that team. 0127 writes attention_asks at operator, so a viewer-role creator's or manager's cancel through Cancel would withdraw nothing. ErrNotOpen (with the card as it stands) for a row that is not such a card.
func (*PGStore) ClaimDelivery ¶
func (s *PGStore) ClaimDelivery(ctx context.Context, id int64, by string, lease, grace time.Duration) (Ask, bool, error)
ClaimDelivery runs under the owner's principal.
func (*PGStore) DueDeliveries ¶
func (*PGStore) FinishDelivery ¶
func (*PGStore) MarkQuestionTurn ¶
MarkQuestionTurn takes question id's turn: one conditional UPDATE on its turn not having started, so of two callers exactly one gets true and puts it to the chief. False for a question no longer open.
func (*PGStore) MarkWaited ¶
MarkWaited runs under the caller's principal (the asker's tool call).
🔴 IT ALSO TAKES AN UNCONFIRMED ONE (#152 r2). A delivery that gave up (a day queued, a failed turn, a lapsed lease) and whose asker then read the answer here is the asker's: left unconfirmed, the owner's Retry would queue it and the sweep push a copy of an answer the agent already has.
🔴 IT ALSO TAKES A DELIVERY IN FLIGHT. A wait that reads the answer while an attempt holds the lease wins it: the lease is dropped, so the attempt's give-up (ReleaseDelivery) or outcome (FinishDelivery), both conditional on still holding it, change nothing — the give-up used to put a read answer back in the queue, and the sweep pushed it a second time.
func (*PGStore) OpenForTask ¶
OpenForTask runs under the caller's principal (row-level security keeps it to their own asks).
func (*PGStore) QuestionsDue ¶
QuestionsDue is every owner's open questions to the chief whose turn has not started (chief_turn_at NULL: the chief was busy or stopped), oldest first, at most limit (system scope: the attention sweep retries each as its owner).
func (*PGStore) RecoverDeliveries ¶
func (*PGStore) ReleaseDelivery ¶
func (*PGStore) RetryDelivery ¶
RetryDelivery runs under the caller's principal: row-level security keeps it to their own asks.
func (*PGStore) Search ¶ added in v0.265.0
Search is the caller's own asks matching q, newest first (open ones first with q.OpenFirst).
func (*PGStore) SessionAskCounts ¶ added in v0.282.0
func (s *PGStore) SessionAskCounts(ctx context.Context, q SessionAsksQuery) (open, total int, err error)
SessionAskCounts is how many of the asks SessionAsks would list for q are open, and how many there are in all — UNCAPPED (MaxSessionAsks bounds the list, not the count): the Open button's numbers, read without the rows. Zero for a q that names no session.
func (*PGStore) SessionAsks ¶ added in v0.282.0
SessionAsks is the caller's own asks raised by the session q names: the open (unexpired) ones first, then the answered ones, newest first within each, at most q.Limit. None for a q that names no session.
func (*PGStore) SetSuggestions ¶
func (s *PGStore) SetSuggestions(ctx context.Context, id int64, suggestions []string) (Ask, bool, error)
SetSuggestions implements Store under the caller's principal (row-level security: another owner's ask is not found, as a missing one is).
🔴 ONE CONDITIONAL UPDATE, ON THE ASK STILL BEING OPEN. A generation starts after the ask is filed and can finish after it was answered, dismissed or expired; the condition is what keeps a settled ask from being given chips — and so from being re-pushed, which the caller does only on ok.
func (*PGStore) UnmarkQuestionTurn ¶
UnmarkQuestionTurn gives question id's turn back (its runtime provably took nothing), for the sweep to retry.
func (*PGStore) WithdrawAbout ¶ added in v0.185.0
func (s *PGStore) WithdrawAbout(ctx context.Context, agentID int64, key string, except int64) ([]Ask, error)
WithdrawAbout runs under the caller's principal: row-level security keeps it to the caller's own asks. 🔴 ONLY THE STRUCTURAL LINK: an ask is withdrawn when agent agentID raised it (agent_id) about exactly key (about_key, which only muster sets), never by what its question says; a notice, a question to the chief and an ask with no about_key are never touched.
type Search ¶ added in v0.265.0
type Search struct {
// AskID matches the ask with that id (0: none).
AskID int64
// DraftID matches the step-up cards that confirm a decision on that
// plugin draft (StepUpCard.DraftID; 0: none).
DraftID int64
// Text matches, case-insensitively and as a plain substring (no
// wildcards: % _ and \ are themselves), the question, the why line, any
// option, the answer, who asked (the stored label, the mirrored session),
// and a step-up card's title, why and post text ("": none), on every ask
// whatever its age: attention_asks keeps an ask's text as long as the ask
// (only the separate ask log forgets text, after MUSTER_ASK_LOG_TEXT_TTL).
Text string
// Limit is how many asks at most, newest first (≤ 0: MaxSearchResults).
Limit int
// OpenFirst orders the asks still open (not answered, cancelled or past
// their expiry) before the rest, newest first within each, BEFORE the
// limit cuts: an old open ask is never cut by newer closed ones.
OpenFirst bool
}
Search is what an ask search matches. An ask matches when ANY of its set parts does; a zero part matches nothing.
type SessionAsksQuery ¶ added in v0.282.0
type SessionAsksQuery struct {
AgentID int64
MirrorHost string
MirrorSessions []string
// Limit is how many asks at most (≤ 0 or over it: MaxSessionAsks).
Limit int
}
SessionAsksQuery names ONE session whose asks are listed: an agent (AgentID), or a mirrored session on MirrorHost by any of the MCP caller keys its window runs (MirrorSessions, mirror.Window.MCPCallerKeys).
func (SessionAsksQuery) Valid ¶ added in v0.282.0
func (q SessionAsksQuery) Valid() bool
Valid reports whether q names a session.
type SourceMessage ¶ added in v0.224.0
type SourceMessage struct {
Plugin string `json:"plugin"`
MessageID int64 `json:"message_id"`
Venue string `json:"venue,omitempty"`
Thread string `json:"thread,omitempty"`
Sender string `json:"sender,omitempty"`
// SenderVerified is the plugin's assertion that it authenticated Sender;
// false is shown UNVERIFIED.
SenderVerified bool `json:"sender_verified"`
Body string `json:"body,omitempty"`
// Truncated: Body is the first MaxSourceBodyRunes runes or
// MaxSourceBodyLines lines of a longer body.
Truncated bool `json:"truncated,omitempty"`
// URL is the message's url when the plugin sent one: an absolute http(s)
// URL, shown as text, never as a link.
URL string `json:"url,omitempty"`
// Unread: muster could not read the message when it raised the ask, so
// Sender and Body are empty (the item's venue and thread are still shown).
Unread bool `json:"unread,omitempty"`
}
SourceMessage is the plugin message an officer item is: UNTRUSTED, an outside sender's words.
type Status ¶
type Status string
Status is where an ask is.
const ( Open Status = "open" Answered Status = "answered" Cancelled Status = "cancelled" Expired Status = "expired" // AnsweredInSession: the operator wrote to the asker directly — a message // into the mirrored session's window, or to the dispatched agent's chat — // after the ask was raised (AnswerInSession, migration 0026). The message is // the answer. AnsweredInSession Status = "answered_in_session" )
type StepUpCard ¶ added in v0.261.0
type StepUpCard struct {
// Tool is the gated tool's name (e.g. plugin_draft_decide).
Tool string `json:"tool"`
// Title is the card's short action title: "Post to X?", "Start this
// agent?". The push title.
Title string `json:"title"`
// Why is the one line that says why it is being asked: a draft's officer
// item, else the asking session.
Why string `json:"why"`
// Asker names who asked (the asking session), drawn as a small label.
Asker string `json:"asker,omitempty"`
// About is the card's where line: who or what the call is about, when
// the title and preview do not: the route an answer goes on, the batch,
// the session a message is routed to, the pairing code, or — on a draft
// card — who asked. "" for none.
About string `json:"about,omitempty"`
// Preview is what is about to happen: a post's exact text, or a plain
// summary of the call. Line breaks kept.
Preview string `json:"preview,omitempty"`
// Venue is where a post goes, "" for any other card.
Venue string `json:"venue,omitempty"`
// Platform is an outbound draft's venue as its plugin names it ("x",
// "reddit"): what picks the preview's logo. "" for a reply draft (its
// venue is its plugin's label) and for any other card.
Platform string `json:"platform,omitempty"`
// Target is an outbound draft's target kind (post, reply, dm, follow,
// like): how its preview is labelled. "" for any other card.
Target string `json:"target,omitempty"`
// Handle is the person a dm or a follow reaches, as the draft names it;
// "" for every other card.
Handle string `json:"handle,omitempty"`
// Parts is how many posts an X thread's WHOLE body becomes (counted
// before Preview was cut to an excerpt of it), 0 for anything that is
// not a thread. A preview drawn as a thread takes its part count from
// here, never from the parts the excerpt happens to hold.
Parts int `json:"parts,omitempty"`
// Excerpt is the one line saying Preview is only part of what is about
// to happen ("⚠ AN EXCERPT: …"), "" when Preview is all of it. Drawn
// OUTSIDE the preview on every face, and a paragraph of Text.
Excerpt string `json:"excerpt,omitempty"`
// DraftID is the draft a plugin_draft_decide card is bound to (its
// Media are served from it), 0 for any other card.
DraftID int64 `json:"draft_id,omitempty"`
// Media are the draft's media the card shows, in the draft's order.
Media []StepUpMedium `json:"media,omitempty"`
// Changed: the draft the call names is not what it names (its body or
// media SHA-256 differ, or it could not be read), so the card shows no
// preview and says to refuse.
Changed bool `json:"changed,omitempty"`
// Details is the boilerplate, on the record: the host, the session, the
// call and its arguments in words (never JSON, never a hash), and why the
// phone is needed.
Details string `json:"details"`
// RaisedByHost / RaisedBySession are the mirrored Claude Code session
// whose MCP call raised the card (migration 0178's session wakes): the
// host of the mirror token the call came in on and the session that host
// listed running in the calling window — muster's binding of the caller,
// never the call's arguments. Both "" for a caller that is not one (a
// remote caller, an opencode session). The owner's settling of the card
// is pasted into that session (internal/api session_wake_requests.go).
RaisedByHost string `json:"raised_by_host,omitempty"`
RaisedBySession string `json:"raised_by_session,omitempty"`
}
StepUpCard is a step-up card's parts, as muster built them when it filed the card. Only muster files one (a System asker).
func CleanStepUp ¶ added in v0.261.0
func CleanStepUp(c *StepUpCard) (*StepUpCard, error)
CleanStepUp is c as an ask stores it (the file header's rules): every field sanitised and bounded, a title, a why and details required. nil for nil.
func (*StepUpCard) MediaLine ¶ added in v0.261.0
func (c *StepUpCard) MediaLine() string
MediaLine is the card's one line about its media, "" for none: "With 1 image" / "With 2 images and 1 video".
func (*StepUpCard) Text ¶ added in v0.261.0
func (c *StepUpCard) Text() string
Text is the card's question: its title, its why and its where line, then its preview and its media line. No host, no hash, no JSON — those are Details. THE ONE TEXT the page's summary and the phone's prompt read.
type StepUpMedium ¶ added in v0.261.0
type StepUpMedium struct {
N int `json:"n"`
Ref string `json:"ref"`
Type string `json:"type"`
SHA256 string `json:"sha256"`
}
StepUpMedium is one medium of a draft a card shows: its index among the draft's refs (what the draft's media route serves), its ref, type and hash. The type picks how it is drawn (an image or a video) and the hash is on the record; neither is ever drawn on any face of the card.
func (StepUpMedium) Video ¶ added in v0.261.0
func (m StepUpMedium) Video() bool
Video reports whether m is a video (else it is drawn as an image).
type Store ¶
type Store interface {
// Create files n for the caller's principal.
Create(ctx context.Context, n New) (Ask, error)
// Get is one of the caller's asks; an open ask past its expiry reads as
// Expired even before the sweep has moved it.
Get(ctx context.Context, id int64) (Ask, error)
// Open is the caller's open, unexpired asks, oldest first.
Open(ctx context.Context) ([]Ask, error)
// Answer records the operator's answer to an open ask, given on the
// attention view.
Answer(ctx context.Context, id int64, answer string) (Ask, error)
// AnswerByChief records the chief's answer to an open question a mirrored
// session addressed to it (ToChief); ErrNotFound for any other ask.
AnswerByChief(ctx context.Context, id int64, answer string) (Ask, error)
// QuestionsDue is every owner's open questions to the chief not yet put to
// it (system scope); MarkQuestionTurn takes one's turn, once;
// UnmarkQuestionTurn gives it back.
QuestionsDue(ctx context.Context, limit int) ([]Ask, error)
MarkQuestionTurn(ctx context.Context, id int64) (bool, error)
UnmarkQuestionTurn(ctx context.Context, id int64) error
// AnswerFromSession records the operator's answer to an open ask, given
// through attention_answer by their mirrored Claude Code session (host,
// session): the same transition as Answer, plus its provenance (ViaMCP).
// ErrSameHost when a mirrored session on host raised the (open) ask.
AnswerFromSession(ctx context.Context, id int64, answer, host, session string) (Ask, error)
// OpenForTask is the caller's open, unexpired asks linked to taskID
// (migration 0032), oldest first.
OpenForTask(ctx context.Context, taskID int64) ([]Ask, error)
// Cancel withdraws an open ask.
Cancel(ctx context.Context, id int64) (Ask, error)
// WithdrawAbout withdraws (Cancelled) every open, unexpired question agent
// agentID raised about session key (SubjectKey, migration 0103) — never
// ask except, and never an ask with no SubjectKey — and returns them.
WithdrawAbout(ctx context.Context, agentID int64, key string, except int64) ([]Ask, error)
// AnswerInSession settles as AnsweredInSession every open ask asker raised
// (of its owner cards, only the oldest) before this statement began (created_at < statement_timestamp()), with
// message (capped at MaxAnswerRunes) as the answer and queueID (0 = none)
// as the send-queue row that carried it, and returns them; none for a
// blank message. keep (nil: none) names asks the message must NOT settle
// although they qualify — they stay open, and they still count as the
// oldest owner card (no younger card is settled in a kept one's place).
AnswerInSession(ctx context.Context, asker Asker, message string, queueID int64, keep func(Ask) bool) ([]Ask, error)
// AnsweredByQueue is, for each of ids that answered asks in session, the
// label of the asker it answered.
AnsweredByQueue(ctx context.Context, ids []int64) (map[int64]string, error)
// ExpireDue moves every owner's lapsed open asks to Expired and returns
// them (system scope).
ExpireDue(ctx context.Context) ([]Ask, error)
// SetSuggestions stores the suggested replies of the caller's ask id
// (migration 0057) and returns the ask — ONLY while it is open and
// unexpired, and only once (an ask that already has some keeps them): ok is
// false, with nothing written, for an ask that is settled, lapsed, already
// suggested, or left with no suggestion once cleaned (CleanSuggestions);
// ErrNotFound for another owner's or a missing one.
SetSuggestions(ctx context.Context, id int64, suggestions []string) (a Ask, ok bool, err error)
// MarkWaited records that the asker read ask id's answer through
// attention_wait: a queued, pull, in-flight or unconfirmed delivery becomes
// DeliveryWaited (an in-flight one loses its lease), so no turn is pushed
// and no Retry can queue one.
// It reports whether it moved the row.
MarkWaited(ctx context.Context, id int64) (bool, error)
// ClaimDelivery takes ask id's delivery lease for by, for lease: one
// conditional UPDATE on DeliveryQueued and on the answer being at least
// grace old (an asker blocked in attention_wait reads it first). False,
// with nothing changed, when another claimer or a reader won.
ClaimDelivery(ctx context.Context, id int64, by string, lease, grace time.Duration) (Ask, bool, error)
// ReleaseDelivery returns a claimed delivery that sent nothing to
// DeliveryQueued, detail saying why (only by's own lease).
ReleaseDelivery(ctx context.Context, id int64, by, detail string) error
// FinishDelivery settles by's claimed delivery: DeliveryDelivered into
// sessionID, or DeliveryUnconfirmed with detail. It reports whether by
// still held the lease.
FinishDelivery(ctx context.Context, id int64, by string, delivered bool, sessionID int64, detail string) (bool, error)
// RetryDelivery moves the caller's unconfirmed delivery back to
// DeliveryQueued (ErrNotRetryable otherwise).
RetryDelivery(ctx context.Context, id int64) (Ask, error)
// Answered is the caller's answers resolved since since that have a
// delivery to show (or were a system asker's) — and every unconfirmed one,
// however old, since it waits on the owner's Retry — newest first, at most
// limit.
Answered(ctx context.Context, since time.Time, limit int) ([]Ask, error)
// DueDeliveries is every owner's queued deliveries at least grace old,
// least-tried first (so answers stuck on an agent that will not take them
// cannot starve newer ones), then oldest, at most limit (system scope).
DueDeliveries(ctx context.Context, grace time.Duration, limit int) ([]Ask, error)
// RecoverDeliveries settles as DeliveryUnconfirmed every owner's delivery
// whose lease lapsed (its process died mid-turn) and returns them (system
// scope).
RecoverDeliveries(ctx context.Context) ([]Ask, error)
// AnswersForTask is the caller's asks linked to taskID that were answered
// THROUGH THE ASK ITSELF (Answered) — on the Attention view or through a
// mirrored session's attention_answer (ViaMCP; AnsweredVia says which) —
// newest first: agent_dispatch's instructions provenance. Left out on
// purpose: AnsweredInSession (one message to the asker's session settles
// every open ask that asker raised, on every task, so it is not an answer
// to any one task's ask).
//
// ⚠ AN MCP ANSWER COUNTS, BY OPERATOR DECISION ("Just remove the filter").
// Its text came out of a Claude Code session, which may have been fed
// outside text, so a session (or a leaked mirror token) can write a
// dispatched agent's instructions this way. That risk was stated and
// accepted; the kickoff names where the answer came from.
AnswersForTask(ctx context.Context, taskID int64) ([]Ask, error)
// Search is the caller's OWN asks (never a team's it can also read, never
// one put to the chief) matching q, newest first (search.go).
Search(ctx context.Context, q Search) ([]Ask, error)
// SessionAsks is the caller's OWN open and answered asks raised by one
// session (never a team's, never one put to the chief, never a notice),
// open first, newest first (session_asks.go).
SessionAsks(ctx context.Context, q SessionAsksQuery) ([]Ask, error)
// SessionAskCounts is how many of those asks are open, and how many
// there are in all, uncapped (session_asks.go).
SessionAskCounts(ctx context.Context, q SessionAsksQuery) (open, total int, err error)
}
Store is the asks' persistence. See the package doc for which methods run under whose principal.