attention

package
v0.236.0 Latest Latest
Warning

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

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

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

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

View Source
const (
	MaxSuggestions     = 3
	MaxSuggestionRunes = 140
)

MaxSuggestions and MaxSuggestionRunes bound an ask's stored suggested replies (0057's CHECK holds the count).

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

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

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

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

View Source
const MaxDeliveryDetailRunes = 300

MaxDeliveryDetailRunes bounds DeliveryDetail (0031's CHECK).

View Source
const SystemAskerLabel = "muster"

SystemAskerLabel is the label of an ask muster itself raised.

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

View Source
var (
	// ErrInvalid: the ask or answer breaks a bound (its text says which).
	ErrInvalid = errors.New("attention: invalid")
	// 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)")
)
View Source
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.

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

func AskObject(id int64) string

AskObject is the audit_log `object` naming an ask.

func CleanAnswer

func CleanAnswer(s string) (string, error)

CleanAnswer validates an answer's text.

func CleanSuggestions

func CleanSuggestions(in, options []string) []string

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

func IsOwnerDoor(ctx context.Context, owner int64) bool

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

func SourceBody(body string) (out string, cut bool)

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

type AnswerSource struct {
	Via     string
	Host    string
	Session string
}

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"`
	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:"-"`
}

Ask is one explicit ask.

func (Ask) ChosenOption added in v0.170.0

func (a Ask) ChosenOption() (int, bool)

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

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.

func (Asker) Same

func (a Asker) Same(b Asker) bool

Same reports whether b is the same asker as a (the label aside).

func (Asker) Valid

func (a Asker) Valid() error

Valid reports whether a is exactly one kind of asker with valid fields.

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

func Clean

func Clean(n New) (New, error)

Clean validates and normalises n: the question and options trimmed, blank options dropped, duplicates refused, the timeout clamped.

type PGStore

type PGStore struct {
	// contains filtered or unexported fields
}

PGStore is Store on Postgres.

func NewPG

func NewPG(pool *pgxpool.Pool) *PGStore

NewPG builds a PGStore.

func (*PGStore) Answer

func (s *PGStore) Answer(ctx context.Context, id int64, answer string) (Ask, error)

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

func (s *PGStore) AnswerByChief(ctx context.Context, id int64, answer string) (Ask, error)

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

func (s *PGStore) Answered(ctx context.Context, since time.Time, limit int) ([]Ask, error)

Answered runs under the caller's principal.

func (*PGStore) AnsweredByQueue

func (s *PGStore) AnsweredByQueue(ctx context.Context, ids []int64) (map[int64]string, error)

AnsweredByQueue runs under the caller's principal (row-level security keeps it to their own asks).

func (*PGStore) AnswersForTask

func (s *PGStore) AnswersForTask(ctx context.Context, taskID int64) ([]Ask, error)

AnswersForTask runs under the caller's principal (row-level security keeps it to their own asks), and names the owner as well.

func (*PGStore) Cancel

func (s *PGStore) Cancel(ctx context.Context, id int64) (Ask, error)

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

func (s *PGStore) Create(ctx context.Context, n New) (Ask, error)

func (*PGStore) DueDeliveries

func (s *PGStore) DueDeliveries(ctx context.Context, grace time.Duration, limit int) ([]Ask, error)

func (*PGStore) ExpireDue

func (s *PGStore) ExpireDue(ctx context.Context) ([]Ask, error)

func (*PGStore) FinishDelivery

func (s *PGStore) FinishDelivery(ctx context.Context, id int64, by string, delivered bool, sessionID int64, detail string) (bool, error)

func (*PGStore) Get

func (s *PGStore) Get(ctx context.Context, id int64) (Ask, error)

func (*PGStore) MarkQuestionTurn

func (s *PGStore) MarkQuestionTurn(ctx context.Context, id int64) (bool, error)

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

func (s *PGStore) MarkWaited(ctx context.Context, id int64) (bool, error)

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

func (s *PGStore) Open(ctx context.Context) ([]Ask, error)

func (*PGStore) OpenForTask

func (s *PGStore) OpenForTask(ctx context.Context, taskID int64) ([]Ask, error)

OpenForTask runs under the caller's principal (row-level security keeps it to their own asks).

func (*PGStore) QuestionsDue

func (s *PGStore) QuestionsDue(ctx context.Context, limit int) ([]Ask, error)

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 (s *PGStore) RecoverDeliveries(ctx context.Context) ([]Ask, error)

func (*PGStore) ReleaseDelivery

func (s *PGStore) ReleaseDelivery(ctx context.Context, id int64, by, detail string) error

func (*PGStore) RetryDelivery

func (s *PGStore) RetryDelivery(ctx context.Context, id int64) (Ask, error)

RetryDelivery runs under the caller's principal: row-level security keeps it to their own asks.

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

func (s *PGStore) UnmarkQuestionTurn(ctx context.Context, id int64) error

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

Store is the asks' persistence. See the package doc for which methods run under whose principal.

type WithAudit added in v0.227.0

type WithAudit struct {
	Action, Object string
	Detail         func(askID int64) map[string]any
}

WithAudit is New.With: the audit row's action and object, and its detail for the new ask's id.

Jump to

Keyboard shortcuts

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