Documentation
¶
Overview ¶
Package sessionwake is the store of the lines muster owes a MIRRORED Claude Code session because its owner decided something the session was waiting on (migration 0177, session_wakes; docs/attention.md "Delivery"): an ask it raised was answered or dismissed, a reply draft it wrote was decided and later sent or not, or a page it made got a response — and (migration 0178) work it ASKED for: an officer's draft for an item it enqueued was decided and later sent or not, or a step-up card its call raised was settled — and (migration 0191) someone sent feedback on a page it made, from the viewer's Feedback pill: the owner's words, or a link viewer's, fenced as untrusted.
The delivery itself — resolving the session's window, queueing the line in the window's send queue, the paste's gate and outcome — lives in internal/api (session_wake.go). This package holds the rows and their moves.
🔴 THE STATES ARE THE ANSWER DELIVERY'S (internal/attention, 0031) and every move is ONE conditional UPDATE on the state it leaves, so of two callers exactly one moves a row: queued → delivering (Hand: the send-queue row that carries it) → delivered | unconfirmed (Finish, only for that row); queued → unconfirmed (GiveUp, a day queued); delivering → queued (Requeue, the row provably pasted nothing); queued | delivering | unconfirmed → waited (MarkWaited: the session read it itself); unconfirmed → queued (Retry, the owner's).
🔴 THE ROW HOLDS THE PARTS OF THE LINE, NEVER THE LINE. Only internal/api's renderWake turns a row into text, and the one kind that carries other viewers' responses (KindPageResponses) holds a count and no text — the database refuses one with text (0177's session_wakes_count_has_no_text).
PRINCIPALS. Create, AddPageResponses, Get, ForAsks, ForDrafts, Retry and MarkWaited run under the caller's principal (row-level security: the owner's rows only). Due runs under the system scope and hands each row to a delivery that acts as its owner; the moves run under whatever principal the caller holds (the owner's, in internal/api).
Index ¶
- Constants
- Variables
- type Kind
- type New
- type OfficerOutcomeOwed
- type OutcomeOwed
- type PGStore
- func (s *PGStore) AddPageResponses(ctx context.Context, pageID int64, host, session string, n int) (Wake, error)
- func (s *PGStore) Create(ctx context.Context, n New) (Wake, bool, error)
- func (s *PGStore) DraftOutcomesOwed(ctx context.Context, limit int) ([]OutcomeOwed, error)
- func (s *PGStore) Due(ctx context.Context, limit int) ([]Wake, error)
- func (s *PGStore) Finish(ctx context.Context, id, queueID int64, delivered bool, detail string) (bool, error)
- func (s *PGStore) ForAsks(ctx context.Context, ids []int64) (map[int64]Wake, error)
- func (s *PGStore) ForDrafts(ctx context.Context, ids []int64) (map[int64]Wake, error)
- func (s *PGStore) Get(ctx context.Context, id int64) (Wake, error)
- func (s *PGStore) GiveUp(ctx context.Context, id int64, detail string) (bool, error)
- func (s *PGStore) Hand(ctx context.Context, id, queueID int64) (bool, error)
- func (s *PGStore) Hold(ctx context.Context, id int64, detail string) error
- func (s *PGStore) MarkRead(ctx context.Context, n New) ([]Wake, error)
- func (s *PGStore) MarkWaited(ctx context.Context, askID int64) ([]Wake, error)
- func (s *PGStore) OfficerOutcomesOwed(ctx context.Context, limit int) ([]OfficerOutcomeOwed, error)
- func (s *PGStore) Requeue(ctx context.Context, id, queueID int64, detail string) (bool, error)
- func (s *PGStore) Retry(ctx context.Context, id int64, stepUpAt time.Time) (Wake, error)
- type State
- type Store
- type Wake
Constants ¶
const ( DecisionApproved = "approved" DecisionRejected = "rejected" DecisionSent = "sent" DecisionFailed = "failed" DecisionUnconfirmed = "unconfirmed" // DecisionPluginRefused: an officer's draft for an item the session // enqueued was refused by its plugin's pre-approval check // (KindOfficerDraftDecided, migration 0183). Its OperatorText is the // PLUGIN's reason, never the owner's words. DecisionPluginRefused = "plugin_refused" // A step-up card's (KindStepUpDecided): confirmed and its call ran; // confirmed and its call ran but the tool refused it; refused on the // phone; dismissed; settled by the owner approving or rejecting the // card's draft on another door (the web UI, another session's request). DecisionConfirmed = "confirmed" DecisionConfirmedFailed = "confirmed_failed" DecisionRefused = "refused" DecisionDismissed = "dismissed" DecisionSettledApproved = "settled_approved" DecisionSettledRejected = "settled_rejected" )
Decisions a draft wake carries (Wake.Decision).
const HeldForSignIn = "it waits for a fresh sign-in"
HeldForSignIn is the detail of a queued wake that waits for the owner's fresh sign-in (internal/api): Retry takes it as well as an unconfirmed one.
const MaxDetailRunes = 300
MaxDetailRunes bounds Wake.Detail (0177's CHECK).
const MaxOperatorTextBytes = 40960
MaxOperatorTextBytes bounds Wake.OperatorText (0177's CHECK).
Variables ¶
var ( // ErrInvalid refuses a wake that is not one 0177 holds. ErrInvalid = errors.New("sessionwake: invalid wake") // ErrNotFound: no such wake the caller can see. ErrNotFound = errors.New("sessionwake: no such wake") // ErrNotRetryable: Retry of a wake that is not unconfirmed. ErrNotRetryable = errors.New("sessionwake: only a wake whose delivery failed can be retried") )
Functions ¶
This section is empty.
Types ¶
type Kind ¶
type Kind string
Kind is what a wake is about.
const ( // KindAskAnswered: the owner answered an ask the session raised. KindAskAnswered Kind = "ask_answered" // KindAskDismissed: the owner dismissed it without answering. KindAskDismissed Kind = "ask_dismissed" // KindDraftDecided: the owner approved or rejected a reply draft the // session wrote (a route's answer). KindDraftDecided Kind = "draft_decided" // KindDraftOutcome: an approved draft's send outcome (sent, failed, // unconfirmed). KindDraftOutcome Kind = "draft_outcome" // KindPageOwn: the owner responded on a page the session made, from // their own view. KindPageOwn Kind = "page_own_response" // KindPageResponses: OTHER viewers responded on it — a count, never // their words. KindPageResponses Kind = "page_responses" // KindOfficerDraftDecided: the owner approved or rejected an outbound // draft an officer filed for an officer item the session ENQUEUED // (migration 0178, officer_items.requested_session). KindOfficerDraftDecided Kind = "officer_draft_decided" // KindOfficerDraftOutcome: that approved draft — or the retry successor // its chain ended on — was sent, failed, or may have been sent. Count is // the attempt it ended on. KindOfficerDraftOutcome Kind = "officer_draft_outcome" // KindStepUpDecided: the owner settled a step-up card the session's MCP // call raised (confirmed or refused on their phone, decided its draft on // another door, or dismissed it). Component is the tool's name, AskID the // card. KindStepUpDecided Kind = "stepup_decided" // KindPageFeedback: someone sent FEEDBACK on a page the session made, // from the viewer's Feedback pill (migration 0191): one wake per message, // its words in OperatorText. LinkID 0 is the page's OWNER, from their own // view (their words); LinkID set is a share link's viewer (a stranger's // words, fenced as untrusted on the line). KindPageFeedback Kind = "page_feedback" )
type New ¶
type New struct {
Kind Kind
AskID int64
DraftID int64
PageID int64
ResponseID int64
RouteID string
OfficerItemID int64
LinkID int64
Decision string
Count int
Component string
OperatorText string
Host string
Session string
ViaHost string
ViaSession string
StepUpAt time.Time
RetryAt time.Time
}
New is a wake to create (Create): every Wake field but the delivery's.
type OfficerOutcomeOwed ¶ added in v0.281.0
type OfficerOutcomeOwed struct {
Owner int64
DraftID int64
Attempt int
Status string
Decision int64
}
OfficerOutcomeOwed is one settled attempt of an officer's approved draft whose session has not been told how it ended (OfficerOutcomesOwed): the draft that settled (the approved draft itself, or the retry successor its chain ended on) and the decision wake it follows.
type OutcomeOwed ¶
OutcomeOwed is one approved draft whose send outcome its session has not been told yet (DraftOutcomesOwed).
type PGStore ¶
type PGStore struct {
// contains filtered or unexported fields
}
PGStore is the store on Postgres.
func (*PGStore) AddPageResponses ¶
func (s *PGStore) AddPageResponses(ctx context.Context, pageID int64, host, session string, n int) (Wake, error)
AddPageResponses records n more of OTHER viewers' responses to page pageID for the session that made it: folded into the page's one queued count line when there is one (0177's session_wakes_one_queued_count), else a new one. It carries a count and nothing else.
func (*PGStore) Create ¶
Create records wake n for the caller's principal (its owner), queued. The bool is false — and the existing row is returned — when the same decision already has its wake (0177's one-per-decision indexes, a draft's decision keyed on the decision itself since 0178): a second answer path racing the first, or a repeat, owes nothing more.
func (*PGStore) DraftOutcomesOwed ¶
DraftOutcomesOwed is every owner's drafts whose approval the owner decided (a draft_decided wake, approved) that have since settled — sent, unconfirmed, or failed with no retry after it — and have no outcome wake yet, at most limit, over the last 8 days (system scope: the sweep files each as its owner). It catches every path a draft settles by — the plugin's result, a lease that lapsed — without a hook in each.
func (*PGStore) Due ¶
Due is every owner's owed (queued) and in-flight (delivering) wakes, oldest first, at most limit (system scope: the sweep acts on each as its owner).
func (*PGStore) Finish ¶
func (s *PGStore) Finish(ctx context.Context, id, queueID int64, delivered bool, detail string) (bool, error)
Finish settles wake id from delivering on row queueID: delivered, or unconfirmed saying why. False when the wake is no longer that row's (the session read it meanwhile, or it already settled).
func (*PGStore) ForAsks ¶
ForAsks is each of asks ids' wake (its answer's or its dismissal's), by ask.
func (*PGStore) ForDrafts ¶
ForDrafts is each of drafts ids' latest wake (its outcome's once there is one, else its decision's), by draft.
func (*PGStore) Hand ¶
Hand moves queued wake id to delivering on send-queue row queueID: false when it is no longer queued (another sweep handed it, or the session read it).
func (*PGStore) MarkRead ¶
MarkRead records that the session read ask n.AskID's answer or dismissal itself (attention_wait returned it), WHETHER OR NOT its wake exists yet: an existing one that is queued, delivering or unconfirmed moves to waited, and a missing one is written as waited — so the wake the decision files after the wait returned (Create's one-per-decision index) finds it already read and is never delivered. Order cannot matter. It returns the rows it moved or wrote.
func (*PGStore) MarkWaited ¶
MarkWaited records that the session read ask askID's answer (or dismissal) itself — attention_wait returned it — so its wake is never pasted: queued, delivering and unconfirmed all move to waited. It returns the rows that moved (one that was delivering names the queue row the caller cancels; the paste's gate refuses it anyway).
func (*PGStore) OfficerOutcomesOwed ¶ added in v0.281.0
OfficerOutcomesOwed is every owner's officer drafts whose approval the owner decided (an officer_draft_decided wake, approved) and whose RETRY CHAIN (0175: the approved draft and every successor naming it in retry_of) has since ENDED on one of its attempts — sent, unconfirmed, or failed with no later attempt in the chain — with no outcome wake for that attempt yet, at most limit, over the last 8 days (system scope: the sweep files each as its owner). A failed attempt that has a successor is not an end: the chain is still trying, and nothing is owed until it stops. An owner's manual retry after the end files a new attempt, whose own end is owed again.
func (*PGStore) Requeue ¶
Requeue moves wake id back to queued from delivering on row queueID — that row provably pasted nothing — saying why (detail).
type Store ¶
type Store interface {
Create(ctx context.Context, n New) (Wake, bool, error)
AddPageResponses(ctx context.Context, pageID int64, host, session string, n int) (Wake, error)
Get(ctx context.Context, id int64) (Wake, error)
ForAsks(ctx context.Context, ids []int64) (map[int64]Wake, error)
ForDrafts(ctx context.Context, ids []int64) (map[int64]Wake, error)
Due(ctx context.Context, limit int) ([]Wake, error)
Hold(ctx context.Context, id int64, detail string) error
Hand(ctx context.Context, id, queueID int64) (bool, error)
Requeue(ctx context.Context, id, queueID int64, detail string) (bool, error)
Finish(ctx context.Context, id, queueID int64, delivered bool, detail string) (bool, error)
GiveUp(ctx context.Context, id int64, detail string) (bool, error)
MarkWaited(ctx context.Context, askID int64) ([]Wake, error)
MarkRead(ctx context.Context, n New) ([]Wake, error)
Retry(ctx context.Context, id int64, stepUpAt time.Time) (Wake, error)
DraftOutcomesOwed(ctx context.Context, limit int) ([]OutcomeOwed, error)
OfficerOutcomesOwed(ctx context.Context, limit int) ([]OfficerOutcomeOwed, error)
}
Store is the wakes' store as internal/api consumes it. *PGStore.
type Wake ¶
type Wake struct {
ID int64
Owner int64
CreatedAt time.Time
Kind Kind
AskID int64
DraftID int64
PageID int64
ResponseID int64
// RouteID is a draft wake's route (muster's own id, rt_…), "" otherwise.
RouteID string
// OfficerItemID is an officer wake's item: the one the session enqueued.
OfficerItemID int64
// LinkID is a KindPageFeedback wake's share link (0191): the link a
// viewer's message came through; 0 for the owner's own message.
LinkID int64
// Decision is a draft wake's: approved or rejected (KindDraftDecided),
// sent, failed or unconfirmed (KindDraftOutcome).
Decision string
// Count is how many other viewers' responses a KindPageResponses wake
// stands for, the attempt a KindOfficerDraftOutcome wake's chain ended
// on, and the page version a KindPageFeedback wake's message was sent
// from.
Count int
// Component is a KindPageOwn wake's page component, and a
// KindStepUpDecided wake's tool name (its own CHECKed shape).
Component string
// OperatorText is the OWNER'S OWN WORDS the line carries, fenced: an
// ask's answer, the reason given with a rejection, a response sent from
// their own view. "" for every other line.
OperatorText string
// Host and Session are the mirrored session it goes to: its host and its
// Claude Code session id.
Host string
Session string
// ViaHost and ViaSession name the mirrored session the decision was made
// from (attention_answer, plugin_draft_decide), "" for the owner's own
// pages and phone.
ViaHost string
ViaSession string
// StepUpAt is the sign-in time of the request that decided it (or of the
// owner's later "Send to session"); zero for none. A line carrying
// OperatorText is queued only while it is fresh (internal/api).
StepUpAt time.Time
// RetryAt is a plugin_refused wake's: when the plugin said the draft could
// be tried again (its refusal's retry_at), zero for none (migration 0183,
// whose session_wakes_retry_at_plugin_refused CHECK holds it to that kind).
RetryAt time.Time
State State
Detail string
Attempts int
QueuedAt time.Time
SendQueueID int64
DeliveredAt time.Time
}
Wake is one row.