Documentation
¶
Overview ¶
Package chiefnudge is the chief's stall nudges (docs/chief-nudges.md): the rules that decide which of an owner's sessions has stalled, what the chief may answer about one, and which of its answers muster accepts — plus the decisions table (migration 0064, chief_nudges).
It holds no I/O but the store. The sweep that reads windows, transcripts and the chief lives in internal/api (chief_nudge.go); everything here is a pure function of what that sweep read, so each guard is testable on its own and none of them lives in a prompt.
🔴 THE GUARDS ARE CODE, NOT INSTRUCTIONS. The chief is told the rules, but a nudge is accepted only when CheckQuote finds its quote, byte for byte, inside one of the OWNER's own messages to that session (OwnerMessages decides which those are); a session's own output can never authorise its own nudge, however it is worded.
Index ¶
- Constants
- Variables
- func AgentKey(agentID, chatSessionID int64) string
- func Anchor(owner []Msg) string
- func AskStall(r Result, threshold float64) bool
- func BuildJevRequest(text string) ([]byte, error)
- func Cut(s string, n int) string
- func EscalationNoTimes(title string) string
- func EscalationPartial(title string) string
- func EscalationQuestion(title string) string
- func EscalationViewOnly(title string) string
- func Exclude(s Session, idle time.Duration) string
- func GenericAskQuestion(title, read string) string
- func GenericAskRead(read string) string
- func NudgeText(ownerName string, m Msg, quote string, loc *time.Location) string
- func NudgeTextFrom(ownerName string, m Msg, quote, source string, loc *time.Location) string
- func Object(id int64) string
- func ParseJevResponse(body []byte) (string, map[string]float64, string, error)
- func Prompt(s Session, last Msg, owner []Msg, idle time.Duration, hint Hint, nonce string) string
- func QuoteSourceOf(p Proposal) string
- func Shown(text string) string
- func Suppressed(guard string) string
- func TailBytes(s string, limit int) string
- func Untimed(msgs []Msg) int
- type Classifier
- type Decision
- type Hint
- type Move
- type Msg
- func CheckQuote(p Proposal, owner []Msg) (Msg, error)
- func CheckQuoteFrom(p Proposal, session, chiefChat []Msg) (Msg, string, error)
- func LastIsAssistant(msgs []Msg) (Msg, bool)
- func OwnerMessages(msgs []Msg, injected, prefixes []string, since time.Time, skipFirst bool) []Msg
- func SinceOwner(msgs []Msg, injected, prefixes []string) (last Msg, ok bool, after int)
- type Owner
- type PG
- func (p *PG) ByAsk(ctx context.Context, askID int64) (Decision, error)
- func (p *PG) ByAsks(ctx context.Context, askIDs []int64) (map[int64]Decision, error)
- func (p *PG) Decided(ctx context.Context, kind, key, streak string) (bool, error)
- func (p *PG) ForEpisode(ctx context.Context, episodeID int64) (Decision, bool, error)
- func (p *PG) ForStreak(ctx context.Context, kind, key, streak string) (Decision, bool, error)
- func (p *PG) Get(ctx context.Context, id int64) (Decision, error)
- func (p *PG) Injected(ctx context.Context, kind, key string) ([]string, error)
- func (p *PG) Insert(ctx context.Context, d Decision, action string) (Decision, bool, error)
- func (p *PG) JevForStreak(ctx context.Context, kind, key, streak string) (Result, bool, error)
- func (p *PG) List(ctx context.Context, limit int) ([]Decision, error)
- func (p *PG) Move(ctx context.Context, id int64, from []string, m Move, action string) (bool, error)
- func (p *PG) NudgesForAnchor(ctx context.Context, kind, key, anchor string) (int, error)
- func (p *PG) NudgesSince(ctx context.Context, since time.Time) (int, error)
- func (p *PG) Owners(ctx context.Context) ([]Owner, error)
- func (p *PG) Pending(ctx context.Context, limit int) ([]Decision, error)
- func (p *PG) TeamHostOwners(ctx context.Context) ([]TeamHost, error)
- type Proposal
- type Result
- type Session
- type Store
- type TeamHost
Constants ¶
const ( // KindMirror is a mirrored window: Key is its Claude session id, or for an // opencode window its runtime-qualified key ("opencode:<id>", // mirror.Window.SessionKey) — Session.Runtime says which. KindMirror = "mirror" KindAgent = "agent" // one of the owner's dispatched agents; Key is its id )
Session kinds.
const ( DecisionNudge = "nudge" DecisionAsk = "ask" DecisionLeave = "leave" DecisionNotify = "notify" DecisionInvalid = "invalid" )
Decisions the chief may return, plus Invalid for an answer muster could not read.
With session state on (MUSTER_SESSION_STATE, docs/design/session-state.md step 3a) the chief answers nudge, leave or NOTIFY: the session's episode carries the one text-free push, so the chief writes no question, summary or options. With it off the chief still answers ask (a notice's message).
const ( ModeShadow = "shadow" ModeLive = "live" )
Modes.
const ( OutcomeWouldSend = "would_send" // shadow: a nudge that passed every guard OutcomeWouldAsk = "would_ask" // shadow: an ask muster would have raised OutcomeLeft = "left" // the chief said leave it OutcomeQueued = "queued" // live: a mirrored nudge waits in the send queue OutcomeSent = "sent" // live: the nudge reached the session OutcomeAsked = "asked" // live: an attention ask is open // OutcomeRelayQueued and OutcomeRelayed are a nudge ask's relay, retired // with nudge asks (migration 0071): no decision moves to either now. Older // rows keep them; the Chief nudges tab names them. OutcomeRelayQueued = "relay_queued" OutcomeRelayed = "relayed" OutcomeFailed = "failed" // live: the send did not happen (Detail says why) OutcomeAskClosed = "ask_closed" // live: the notice (or an older ask) ended (Detail says how) // OutcomeNotified: a notify (session state on). Nothing is sent and no // notice raised: the session's episode carries the push, in either mode // (shadow mode never quiets a stop, so a shadow notify pushes too). OutcomeNotified = "notified" SuppressedPrefix = "suppressed:" )
Outcomes: what became of a decision. A suppressed one is SuppressedPrefix + the guard's name.
const ( GuardQuote = "quote_unverified" // the nudge's quote is not in an owner message GuardHourlyCap = "hourly_cap" // the global hourly cap is reached GuardInvalid = "invalid_answer" // the chief's answer did not parse GuardNoQuestion = "no_question" // an ask with no question GuardAskFailed = "ask_not_created" // the attention ask could not be raised GuardMovedOn = "moved_on" // the session left its idle streak before muster acted GuardAskCap = "ask_cap" // the owner's open asks are at attention's cap GuardChiefError = "chief_error" // the chief's call failed (Detail says how); the next streak is judged again GuardSuperseded = "superseded" // a queued nudge was refused at its paste: the session had moved on GuardPartial = "partial_read" // reason text only: the transcript read was incomplete, so no owner message authorises a nudge // GuardLanesFull: the chief's ccd refused every check for this streak with // 503 capacity (every lane held by the owner's own sessions) for longer than // the sweep's bound; recorded so the streak stops being asked about. GuardLanesFull = "lanes_full" // GuardChiefNotReady: the same for a typed 503 not_ready (CCD_MAX_SESSIONS=0, // or a check CLI that never reaches its prompt). GuardChiefNotReady = "chief_not_ready" // GuardEpisode: a live ask raised NO notice, because session state is on // (MUSTER_SESSION_STATE) and the session's episode carries the one // text-free push for the stop. Older rows only: since migration 0078 that // decision is recorded as a notify (OutcomeNotified). GuardEpisode = "episode_push" )
Guard names (the part after SuppressedPrefix).
const ( // DefaultIdle is how long a session must have been idle to be a candidate // (MUSTER_CHIEF_NUDGE_IDLE). DefaultIdle = 10 * time.Minute MinIdle = 2 * time.Minute MaxIdle = 24 * time.Hour // DefaultHourlyCap is the global cap on nudges per hour, shadow and live // together (MUSTER_CHIEF_NUDGE_HOURLY_CAP). DefaultHourlyCap = 6 // MaxNudgesPerAnchor: after this many nudges since the owner's latest // message to a session, the next "nudge" becomes an ask. MaxNudgesPerAnchor = 2 // OwnerWindow is how far back the owner's own messages are read. OwnerWindow = 6 * time.Hour // MaxOwnerMessages is how many of them (the newest) the chief is shown. MaxOwnerMessages = 20 // MaxOwnerMessageRunes cuts each one; MaxLastRunes the session's last message. MaxOwnerMessageRunes = 2000 MaxLastRunes = 4000 // MinQuoteRunes and MinQuoteWords are the shortest quote accepted: a // fragment ("make", "ok go") matches almost any message and authorises // nothing in particular. A quote must be a phrase of the owner's. MinQuoteRunes = 12 MinQuoteWords = 3 // MaxQuoteRunes bounds a quote (the nudge carries it). MaxQuoteRunes = 500 // QueueRepairAfter: a live nudge recorded queued whose send_queue row was // never written (a crash between the two) is failed after this. QueueRepairAfter = 10 * time.Minute )
Defaults and bounds.
const ( ExclNotIdle = "not_idle" ExclTooSoon = "idle_too_short" ExclShell = "background_work" ExclTurnError = "turn_error" ExclOfficer = "officer" ExclChief = "chief" ExclOtherUser = "other_user" ExclOpenAsk = "open_ask" ExclDecided = "already_decided" ExclNoStreak = "no_streak" ExclLastOwner = "last_message_owner" ExclNoMessages = "no_messages" )
Exclusion reasons (Exclude's answers).
const ( // SourceSession: the candidate session's own owner messages // (OwnerMessages), as every nudge before step 3b-1. A nudge that names no // source is read as this one. SourceSession = "session" // SourceChiefChat: a turn of the owner's Chief chat that muster recorded as // TYPED by the owner (chat_messages.typed_by; docs/design/session-state.md, // "Covering words", step 3b-1). Session state on only, and live only for an // owner on MUSTER_CHIEF_NUDGE_CHIEF_CHAT_QUOTES_LIVE_OWNERS too. SourceChiefChat = "chief_chat" )
Where a nudge's quote is checked (Proposal.QuoteSource, Decision.QuoteSource, chief_nudges.quote_source, migration 0081).
const ( LabelNeedsInput = "needs_input" LabelAsksPermission = "asks_permission" LabelNeither = "neither" )
The labels.
const ChiefChatIDPrefix = "chief:"
ChiefChatIDPrefix opens the id a Chief-chat turn is shown (and quoted) by: "chief:<chat message id>". It can never equal a session message's id (a transcript place "line:<n>", or an agent's bare chat message id), so a quote id names one source whatever the chief says its source is.
const DecisionsURL = "https://openrouter.ai/api/alpha/decisions"
DecisionsURL is OpenRouter's Decisions API (not chat completions).
const DefaultAskThreshold = 0.9
DefaultAskThreshold is the backtested ask-score line (MUSTER_CHIEF_NUDGE_ASK_THRESHOLD).
const DefaultClassifyTimeout = 5 * time.Second
DefaultClassifyTimeout is a hard cap on one classification.
const GenericAskBody = "Its last turn looks like it asked you something."
GenericAskBody is muster's own sentence about a session that looks like it asked something, with no question of the chief's (the generic ask; a generic notice's message).
const JevModel = "~typesafe/jev-latest"
JevModel is the model asked; the response names the model actually served (Result.Model), which is what a decision records.
const MaxClassifyBytes = 8 * 1024
MaxClassifyBytes caps the text sent: its TAIL, where the ask is (Jev runs long inputs in a slower, less accurate mode).
const MaxGenericReadRunes = 300
MaxGenericReadRunes caps the chief's reason on the generic ask: a sentence or two.
const NudgeLabel = "[Chief nudge]"
NudgeLabel opens every nudge: the session reads a labelled message from the chief quoting its owner, never a message in the owner's voice.
Variables ¶
var ( ErrNoQuote = errors.New("the nudge quotes nothing") ErrQuoteShort = fmt.Errorf("the quote is not a phrase: it needs at least %d words and %d characters", MinQuoteWords, MinQuoteRunes) ErrQuoteLong = fmt.Errorf("the quote is longer than %d characters", MaxQuoteRunes) ErrNoCover = errors.New("the nudge names no pending action its quote covers") ErrQuoteUnknown = errors.New("the quote names no owner message of this session") ErrQuoteNotIn = errors.New("the quote is not, byte for byte and on word boundaries, in the owner message it names") ErrQuoteSource = errors.New("the nudge names a quote source muster does not know") ErrChiefChatOff = errors.New("the quote names the Chief chat, which no nudge here may quote") )
Quote guard errors.
var ErrNotFound = errors.New("chiefnudge: no such decision")
ErrNotFound: no such decision among the caller's.
var ErrUnparseable = errors.New("chiefnudge: the chief's answer is not a decision")
ErrUnparseable: the chief's answer holds no JSON object with a known decision.
var JevRubrics = map[string]string{ LabelNeedsInput: "Does the assistant end by asking the human a question, requesting " + "information or a decision it needs, or stating that progress is waiting on " + "a decision or an action only the human can take (e.g. 'still waiting on your " + "call', 'next step for you: …', 'once you've merged and run the SQL I'll…') — " + "other than asking permission to proceed with a step it has already proposed?", LabelAsksPermission: "Is the assistant holding its own next planned step until the human approves " + "it (e.g. 'shall I…', 'want me to start…', 'say proceed and I'll…', 'your call " + "to proceed')?", LabelNeither: "Is this a finished report, summary or status update — including waiting on a " + "background job, narrating work in progress, or ending with an OPTIONAL extra " + "offer after the requested work is done (e.g. 'I can look into it if you " + "want') — that needs nothing from the human to continue?", }
JevRubrics is THE one place the three rubric strings live — copied VERBATIM from ask_classifier.py's RUBRICS, which the operator approved and backtested. A reword is a different classifier: TestTheRubricsAreTheApprovedOnes pins every byte.
Functions ¶
func AgentKey ¶
AgentKey is a dispatched agent's conversation as a Session.Key: the agent and the chat session, so each conversation of an agent stalls (and is decided, capped and relayed to) on its own.
func Anchor ¶
Anchor is the owner's latest message's id among owner ("" for none): the nudge cap counts nudges per anchor, so a fresh instruction from the owner resets it.
func AskStall ¶
AskStall reports the backtested rule: the classification says the session stopped on an unasked question or permission request — its ask score is at least threshold.
func BuildJevRequest ¶
BuildJevRequest is the Decisions request for text: the reference's body.
func EscalationNoTimes ¶
EscalationNoTimes is the ask raised in place of a nudge for a session whose host sends no prompt times: no instruction of the owner's can be checked.
func EscalationPartial ¶
EscalationPartial is the ask raised in place of a nudge when the transcript read was incomplete: no instruction of the owner's can be checked.
func EscalationQuestion ¶
EscalationQuestion is the ask raised in place of a third nudge.
func EscalationViewOnly ¶ added in v0.138.0
EscalationViewOnly is the ask raised in place of a nudge for a session muster cannot type into (an opencode pane: view only).
func Exclude ¶
Exclude is why s is NOT a candidate, "" when it is: idle for at least idle, no background work, no turn error, not an officer, the chief or another user's, no open ask, and this idle streak not already decided. Coverage (officers, the chief, other users) is decided here as well as by what the sweep lists, so a new source of sessions cannot widen it by accident.
func GenericAskQuestion ¶
GenericAskQuestion is the generic ask's text for a session titled title, with GenericAskRead(read).
func GenericAskRead ¶ added in v0.122.0
GenericAskRead is the generic ask's line for the chief's read of the session — read is the chief's OWN reason from its answer (Proposal.Reason), never the reason muster builds around it — on one line, cut to MaxGenericReadRunes; "" for none.
It is the chief's words, held as the normal ask path holds the chief's question: ParseProposal's one-line cut, no check for session text. The generic ask's own sentence and options still carry none.
func NudgeText ¶
NudgeText is the nudge pasted into the session (operator decision: a labelled message quoting the owner). ownerName is who said it ("your owner" when unknown); m.At, when set, is when, in loc.
func NudgeTextFrom ¶ added in v0.145.0
NudgeTextFrom is NudgeText for a quote checked in source: a Chief-chat quote says it was said to the chief, so the session reads where the words were written. A session quote is NudgeText unchanged.
func ParseJevResponse ¶
ParseJevResponse is (label, scores, served model) from a response. The label is the argmax over OUR labels, never the response's own `choice`, so a response cannot steer the rule with a label it was not asked about.
func Prompt ¶
Prompt is the chief's turn for one stalled session: muster's instructions (outside the fence), then — fenced, as data — the session's focus title, its last message and the owner's own messages to it, each with the id a nudge must quote it by.
🔴 EVERY WORD OF THE SESSION'S IS INSIDE THE FENCE, and the owner's messages too (they are quoted back, so they must be the exact bytes CheckQuote matches against: the caller passes them already redacted, and the chief is shown exactly those).
func QuoteSourceOf ¶ added in v0.145.0
QuoteSourceOf is the source p's quote is checked against: "" is read as SourceSession (every nudge before step 3b-1 named none); anything else is returned as the chief wrote it, for CheckQuoteFrom to refuse.
func Shown ¶
Shown is text as the chief is shown it in the stall check's fenced block: each line through fence.Sanitize. A quote is matched against THIS form, so a tab or a control character the chief saw replaced does not make a true quote fail.
Types ¶
type Classifier ¶
type Classifier struct {
Key func(ctx context.Context, owner int64) (string, error)
Missing func(error) bool
URL string // "" = DecisionsURL
Client *http.Client
Timeout time.Duration // 0 = DefaultClassifyTimeout
}
Classifier is the Jev call. Key is the owner's OpenRouter key (the focus summarizer's resolution); Missing tells "no key" from a lookup failure.
type Decision ¶
type Decision struct {
ID int64
Owner int64
Kind string
Key string
Host string
TmuxSession string
Window string
AgentID int64
// ChatSessionID is the agent's conversation the decision is about (0 for a
// mirrored session): where its nudge goes.
ChatSessionID int64
Title string
StreakKey string
AnchorKey string
IdleSince time.Time
DecidedAt time.Time
Decision string
Message string
QuoteID string
QuoteAt time.Time
QuoteText string
Covered string
Question string
Options []string
Reason string
Mode string
Outcome string
Detail string
AskID int64
SendQueueID int64
RelayText string
UpdatedAt time.Time
// The stall classifier's result on the session's last message (jev.go):
// zero values with JevError "" mean it was not run.
JevLabel string
JevNeedsInput float64
JevAsksPermission float64
JevNeither float64
JevAskScore float64
JevModel string
JevLatencyMS int
JevError string
// EpisodeID is the session-state episode (session_episodes) the decision
// was taken in, 0 when session state is off: the chief judges an episode at
// most once (chief_nudges_one_per_episode, migration 0078), and a queued
// nudge whose episode is no longer the session's open one is dropped.
EpisodeID int64
// QuoteSource is where the nudge's quote was checked (SourceSession,
// SourceChiefChat; migration 0081), "" for a decision with no quote or from
// before 0081. 🔴 The paste gate reads it: a Chief-chat nudge is sent only
// for an owner on MUSTER_CHIEF_NUDGE_CHIEF_CHAT_QUOTES_LIVE_OWNERS too.
QuoteSource string
// ChiefChatInView: the owner's typed Chief-chat lines were in the chief's
// prompt when it decided (migration 0081; operator decision 2026-11-04,
// "Shadow whole decision"). 🔴 Such a nudge is gated like a Chief-chat
// quote whatever its QuoteSource: shadow until the owner is on
// MUSTER_CHIEF_NUDGE_CHIEF_CHAT_QUOTES_LIVE_OWNERS too. The paste gate, an
// agent's turn and the reconcile retry read it.
ChiefChatInView bool
}
Decision is one row of chief_nudges.
func (Decision) Jev ¶ added in v0.143.0
Jev is d's stored classification as a Result (WithJev's inverse; the latency is kept, the probabilities are the three scores).
func (Decision) Suppressed ¶
Suppressed reports whether d's outcome is a guard's.
type Hint ¶
type Hint struct {
AskStall bool
Label string
AskScore float64
// Notify: session state is on, so the chief answers nudge, leave or notify
// and writes no question (docs/design/session-state.md, step 3a). Off, it
// answers nudge, ask (with the notice's question) or leave, as before.
Notify bool
// ChiefChat is the owner's TYPED Chief-chat turns in the window (step
// 3b-1: chat_messages.typed_by), each with its "chief:<id>" id, already
// redacted and cut like owner — the exact bytes CheckQuoteFrom matches. The
// chief may quote them, naming quote_source "chief_chat". Read only with
// Notify: with session state off the prompt is the one from before 3b-1,
// byte for byte, whatever this holds.
ChiefChat []Msg
}
Hint is what the stall classifier told the sweep, passed on to the chief, and which answers the sweep takes.
type Msg ¶
type Msg struct {
Role string // "user" or "assistant" (anything else is ignored)
Text string
// ID names it within its session: a chat message id (agent) or a prompt's
// byte offset in the transcript (mirror). "" for an assistant message.
ID string
// At is when it was written; zero when the source does not say (a
// mirrored transcript from a muster-mirror older than the PromptAt field).
At time.Time
}
Msg is one transcript message, oldest first in a slice.
func CheckQuote ¶
CheckQuote is the nudge guard: p's quote must be a phrase (MinQuoteWords words, MinQuoteRunes characters), name a covered action, and appear BYTE FOR BYTE — starting and ending on word boundaries — inside the one owner message p.QuoteID names (as Shown), which must be one of owner (OwnerMessages' set: never the session's own output, never injected text, never older than the window). It returns that message.
⚠ WHAT IT GUARANTEES, AND WHAT IT DOES NOT: the quote is the owner's own recent words, verbatim. Whether those words COVER the pending action is the chief's judgement (covered_action is its claim), not something code checks.
func CheckQuoteFrom ¶ added in v0.145.0
CheckQuoteFrom is CheckQuote over the source p NAMES (QuoteSourceOf): session, the candidate session's own owner messages exactly as CheckQuote always checked them; chiefChat, the owner's TYPED Chief-chat turns in the window (nil when the Chief chat may not be quoted here — session state off — or its read could not vouch for the window: then no Chief-chat quote passes). It returns the message and the source it was found in.
🔴 ONE SOURCE, THE NAMED ONE. A quote is looked for only in the source the chief named, so a Chief-chat quote is never recorded (or gated) as a session one, and the reverse. An unknown source is refused.
func LastIsAssistant ¶
LastIsAssistant reports whether the newest user-or-assistant message of msgs is the assistant's, and returns it.
func OwnerMessages ¶
OwnerMessages is the owner's OWN messages among msgs — user-role, written at or after since, at most MaxOwnerMessages, newest last — leaving out:
a message with NO time: its age cannot be checked against since, so it authorises nothing (an older muster-mirror sends prompts without one; Untimed counts them, so the caller can say why there is no nudge);
any message carrying a muster fence (fenceOpen): text muster injected, whose words are an outside party's or muster's, never the owner's;
any message equal (after trimming) to one of injected: what muster itself pasted into this session (a routed message, a nudge, a relay — the send_queue rows muster queued and the chief_nudges rows' texts);
any message starting with one of prefixes: the openings muster's own pastes are written with (the routed preface, NudgeLabel), passed in from the constants the senders use — a second line behind injected, for a paste whose row is gone;
skipFirst: the session's very first message, when the caller knows it is a dispatched agent's kickoff (the task's text, which can be a plugin's).
🔴 THIS IS THE AUTHORITY SET FOR CheckQuote. A message that should not authorise a nudge must not get past here; a message wrongly left out only costs a nudge that becomes an ask.
func SinceOwner ¶ added in v0.245.0
SinceOwner is the owner's newest OWN message among msgs (oldest first) — OwnerMessages' rule, with no time window and no kickoff skip — and how many of muster's own user-role messages (injectedText: a nudge, a routed or relayed message, a fenced paste) come after it in the conversation. With no own message read, ok is false and after counts every injected message read. The fleet reader's loop counter (internal/api fleet_list's chief_texts_since_owner).
type PG ¶
type PG struct {
// contains filtered or unexported fields
}
PG is Store on Postgres, under row-level security.
func (*PG) ForEpisode ¶ added in v0.143.0
ForEpisode is the caller's decision taken in session-state episode id: ok false when the episode has none yet. The sweep reads it so an episode is put to the chief at most once (docs/design/session-state.md, "The Chief: nudge, leave or notify").
func (*PG) ForStreak ¶ added in v0.141.0
ForStreak is the caller's decision for (kind, key, streak): ok false when the streak has none yet. Session state's episode push reads it, so what the chief decided about a stop decides whether the stop pushes (docs/design/session-state.md, "Who decides what").
func (*PG) JevForStreak ¶ added in v0.141.0
JevForStreak is the stall classifier's answer recorded on the caller's decision for (kind, key, streak): ok false when no decision holds a usable one (none recorded, or it failed). Session state reads it so the classifier is billed once per streak whichever pass ran first.
func (*PG) Move ¶
func (p *PG) Move(ctx context.Context, id int64, from []string, m Move, action string) (bool, error)
Move implements Store.
func (*PG) NudgesForAnchor ¶
NudgesForAnchor implements Store.
func (*PG) NudgesSince ¶
NudgesSince implements Store.
func (*PG) TeamHostOwners ¶ added in v0.229.0
TeamHostOwners is every TEAM the session-state pass's team arm visits (internal/sessionstate PG.OwnerKinds, team sharing 2b.3), by id: each team holding an unrevoked mirror token (Live), and each that holds none but still has an open episode or a shown, uncleared one — its last token revoked mid-wait (#690 round 1, 🟡2), so its pass ends and withdraws them. NOT the nudge sweep's owners (Owners stays persons only: a team session gets no chief nudge until a team chief binds to team hosts).
type Proposal ¶
type Proposal struct {
Decision string `json:"decision"`
Reason string `json:"reason"`
QuoteID string `json:"quote_id"`
Quote string `json:"quote"`
CoveredAction string `json:"covered_action"`
Question string `json:"question"`
// QuoteSource is where the chief says its quote is from: SourceSession,
// SourceChiefChat, or "" (read as SourceSession). Only the prompt with
// session state on asks for it; with it off it is never read.
QuoteSource string `json:"quote_source"`
}
Proposal is the chief's answer, as parsed.
func ParseNotifyProposal ¶ added in v0.143.0
ParseNotifyProposal is ParseProposal with session state ON (step 3a): notify is a decision too, and an "ask" is read as a notify.
func ParseProposal ¶
ParseProposal reads the first JSON object in raw (a model may wrap it in prose or a code fence) and checks its decision is one of nudge, ask, leave: the stall check's answer with session state OFF, unchanged by step 3a.
type Result ¶
type Result struct {
Label string
Scores map[string]float64
AskScore float64 // P(needs_input) + P(asks_permission)
Model string // the model the response says it served
LatencyMS int
Err string
}
Result is one classification. On any failure Err is a short class (never a body or a key) and Label is "".
type Session ¶
type Session struct {
Kind string
Key string // Claude session id or "opencode:<id>" (mirror), or agent id (agent)
// Runtime is a mirrored window's agent runtime when it is not Claude Code
// (mirror.RuntimeOpenCode), "" for Claude Code and for an agent. A
// runtime window is VIEW ONLY: it is never nudged (the sweep raises the
// notice instead).
Runtime string
// Dispatched (KindMirror): the window is an agent muster spawned for the
// chief (mirror.Window.Dispatch): its first message is muster's spawn
// prompt, not the owner's, as a KindAgent's first message is its kickoff.
Dispatched bool
// Mirror address (KindMirror).
Host, TmuxSession, Window, Label string
// Name is the session's stable name (internal/sessionname) as the stall
// prompt names it to the chief, "" when it has no human one.
Name string
// Index is the window's tmux index when the sweep saw it (mirror
// Window.Index): display only, for the ask's text (mirror.Where) — tmux
// renumbers windows, so nothing is addressed by it.
Index int
// AgentID and ChatSessionID (KindAgent): the agent and the ONE conversation
// of it that stalled — an agent can hold several.
AgentID int64
ChatSessionID int64
Title string // its focus title, "" for none
// TitleAge is how old Title is, in words, for the chief's prompt
// (ui.FocusAgeLabel of ui.FocusAgeOf on the server's clock: "focus title
// set 2d ago"), "" when it shows none. Prompt only: never stored.
TitleAge string
// Status is "idle", "busy", "waiting" or "" (unknown).
Status string
// IdleFor is how long it has been idle, on muster's clock.
IdleFor time.Duration
IdleSince time.Time
// StreakKey names this idle streak: a new turn starts a new one.
StreakKey string
// Exclusion inputs.
Shell bool // a background shell or subagent of its own is running
TurnError bool // its last turn ended in a usage limit, auth or API error
Officer bool
Chief bool
OtherUser bool // not the owner's (never reaches here through row-level security; checked anyway)
OpenAsk bool // an open attention ask or chief question of its own, or an open nudge ask
Decided bool // this idle streak already has a decision
}
Session is one of an owner's sessions as the sweep saw it, before any transcript is read: everything candidate selection decides on.
type Store ¶
type Store interface {
// Owners is every user who is not disabled (system scope).
Owners(ctx context.Context) ([]Owner, error)
// Decided reports whether the caller's session (kind, key) already has a
// decision for streak.
Decided(ctx context.Context, kind, key, streak string) (bool, error)
// Insert records d for the caller, with its audit row; inserted false (and
// nothing written) when another decision for the same streak — or, with
// d.EpisodeID set, the same episode — won.
Insert(ctx context.Context, d Decision, action string) (Decision, bool, error)
// NudgesForAnchor counts the caller's nudges (would_send, queued, sent) to
// (kind, key) since the owner message anchor.
NudgesForAnchor(ctx context.Context, kind, key, anchor string) (int, error)
// NudgesSince counts every owner's LIVE nudges (queued, sent) decided at
// or after since: the global hourly cap, which bounds what is sent and
// never holds shadow mode back (system scope).
NudgesSince(ctx context.Context, since time.Time) (int, error)
// Injected is what the sweep pasted into the caller's session (kind, key):
// every live nudge, and any relay text a row from before notices holds.
Injected(ctx context.Context, kind, key string) ([]string, error)
// Pending is every owner's live decision still in flight (queued, asked,
// a notice still open; relay_queued, which only an older replica can still
// write during a rolling deploy, for the sweep to fail), system scope.
Pending(ctx context.Context, limit int) ([]Decision, error)
// Get is the caller's decision id.
Get(ctx context.Context, id int64) (Decision, error)
// ByAsk is the caller's decision that raised ask id.
ByAsk(ctx context.Context, askID int64) (Decision, error)
// ByAsks is ByAsk for several asks in ONE read: the caller's decisions
// that raised any of askIDs, by ask id (an id no decision of the caller's
// raised is absent). What the attention queue joins its notices to.
ByAsks(ctx context.Context, askIDs []int64) (map[int64]Decision, error)
// Move sets the caller's decision id from one of from to outcome, with its
// detail and (when non-zero) its ask and queued row,
// writing action's audit row when action is not ""; moved false when the
// row was not in one of from.
Move(ctx context.Context, id int64, from []string, m Move, action string) (bool, error)
// List is the caller's newest decisions.
List(ctx context.Context, limit int) ([]Decision, error)
// ForEpisode is the caller's decision taken in session-state episode id,
// ok false when it has none (the sweep judges an episode at most once; the
// 0078 unique index is the guarantee).
ForEpisode(ctx context.Context, episodeID int64) (Decision, bool, error)
}
Store is chief_nudges.