sessionwake

package
v0.282.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 11 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 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.

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

View Source
const (
	DecisionApproved    = "approved"
	DecisionRejected    = "rejected"
	DecisionSent        = "sent"
	DecisionFailed      = "failed"
	DecisionUnconfirmed = "unconfirmed"
	// 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).

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

View Source
const MaxDetailRunes = 300

MaxDetailRunes bounds Wake.Detail (0177's CHECK).

View Source
const MaxOperatorTextBytes = 40960

MaxOperatorTextBytes bounds Wake.OperatorText (0177's CHECK).

Variables

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

type New

type New struct {
	Kind          Kind
	AskID         int64
	DraftID       int64
	PageID        int64
	ResponseID    int64
	RouteID       string
	OfficerItemID int64
	Decision      string
	Count         int
	Component     string
	OperatorText  string
	Host          string
	Session       string
	ViaHost       string
	ViaSession    string
	StepUpAt      time.Time
}

New is a wake to create (Create): every Wake field but the delivery's.

func (New) Valid

func (n New) Valid() error

Valid reports whether n is a wake 0177 holds, checked here so a caller gets a reason instead of a constraint name.

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

type OutcomeOwed struct {
	Owner   int64
	DraftID int64
}

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 NewPG

func NewPG(pool *pgxpool.Pool) *PGStore

NewPG returns a store on pool.

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

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

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

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

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

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

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

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

ForAsks is each of asks ids' wake (its answer's or its dismissal's), by ask.

func (*PGStore) ForDrafts

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

ForDrafts is each of drafts ids' latest wake (its outcome's once there is one, else its decision's), by draft.

func (*PGStore) Get

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

Get is wake id, as the caller sees it.

func (*PGStore) GiveUp

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

GiveUp settles queued wake id as unconfirmed, saying why (a day queued).

func (*PGStore) Hand

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

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

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

Hold records why queued wake id still waits (detail), leaving it queued.

func (*PGStore) MarkRead

func (s *PGStore) MarkRead(ctx context.Context, n New) ([]Wake, error)

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

func (s *PGStore) MarkWaited(ctx context.Context, askID int64) ([]Wake, error)

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

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

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

func (s *PGStore) Requeue(ctx context.Context, id, queueID int64, detail string) (bool, error)

Requeue moves wake id back to queued from delivering on row queueID — that row provably pasted nothing — saying why (detail).

func (*PGStore) Retry

func (s *PGStore) Retry(ctx context.Context, id int64, stepUpAt time.Time) (Wake, error)

Retry queues wake id once more — an unconfirmed one, or one held for a fresh sign-in (HeldForSignIn) — recording stepUpAt (the sign-in of the request that asked; zero keeps the wake's own): ErrNotRetryable for any other state, with the wake as it stands.

type State

type State string

State is where a wake is (0177's header).

const (
	Queued      State = "queued"
	Delivering  State = "delivering"
	Delivered   State = "delivered"
	Unconfirmed State = "unconfirmed"
	Waited      State = "waited"
)

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
	// 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, and the attempt a KindOfficerDraftOutcome wake's chain
	// ended on.
	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
	State       State
	Detail      string
	Attempts    int
	QueuedAt    time.Time
	SendQueueID int64
	DeliveredAt time.Time
}

Wake is one row.

Jump to

Keyboard shortcuts

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