askattempt

package
v0.267.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 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 askattempt is the answer-attempt log: one row (table ask_attempts, migration 0113) for every Submit or Dismiss of a question card — a mirrored Claude Code AskUserQuestion picker, or an opencode question or permission request — from every door that answers one, with how it ended and why (docs/mirroring.md#answer-attempts).

🔴 ONE ENUMERATED SET OF REASONS, ONE PLACE: Reasons. Every refusal before anything is typed (a stale sign-in, an unknown card, a closed one, an invalid form, a host that cannot type…), every outcome the host reports of typing (internal/api's askTypingResult), an opencode relay's, a dismissal's and a send-as-message's is one of its keys; the store refuses any other. Each reason says how it ends (Outcome) and how a card recovers from it (Recovery) — the recoverable-reason table the docs print.

🔴 NEVER THE QUESTION'S OR THE ANSWER'S TEXT. A row holds the question's shape (Shape) only. The one exception is Snapshot, the terminal pane the host read at a failure: redacted (redact.Secrets) and capped (MaxSnapshot) by the store, the one writer, so no caller can store it raw.

Index

Constants

View Source
const (
	RuntimeClaudeCode = "claude-code"
	RuntimeOpenCode   = "opencode"
)

The runtimes (ask_attempts.runtime).

View Source
const (
	// DoorCard: the question card in a session's rendered view, in a browser.
	DoorCard = "card"
	// DoorAttention: the Attention list's own answer form (an opencode ask's
	// option buttons). A Claude question there links to its card.
	DoorAttention = "attention"
	// DoorPhone: the card, in the Android app's shell (the page's
	// window.musterApp bridge says so).
	DoorPhone = "phone"
)

The doors a card is answered from (ask_attempts.door).

View Source
const (
	ActionSubmit  = "submit"
	ActionDismiss = "dismiss"
)

The actions (ask_attempts.action): a person's Submit or Dismiss.

View Source
const (
	// MethodTyped: keys typed into the Claude Code picker (internal/askdrive).
	MethodTyped = "typed"
	// MethodRelayed: an opencode ask answered through its host's API.
	MethodRelayed = "relayed"
	// MethodEscape: the picker dismissed with one Escape.
	MethodEscape = "escape"
	// MethodMessage: the choice sent to the session as an ordinary message
	// through the send queue ("Send as a message").
	MethodMessage = "message"
)

How the answer was to reach the session (ask_attempts.method).

View Source
const (
	// OutcomeOK: it did what it was asked.
	OutcomeOK = "ok"
	// OutcomeRefused: refused before anything reached the host.
	OutcomeRefused = "refused"
	// OutcomeFailed: it reached the host (or was being sent) and did not
	// work.
	OutcomeFailed = "failed"
	// OutcomeNoop: nothing to do (the same answers again, already typed).
	// Not counted in a success rate.
	OutcomeNoop = "noop"
)

The outcomes (ask_attempts.outcome): what a reason means for the attempt.

View Source
const (
	// RecoverRetry: the card offers Try again. Before its first key the host
	// re-reads the picker and, when it still shows this question, resets it
	// to the first option (askq.Progress.Reset), then types the answer again.
	RecoverRetry = "retry"
	// RecoverMessage: the picker is gone or cannot be read, so typing again
	// cannot work: the card offers "Send as a message" — the picker dismissed
	// if it is still there, then the choice queued as an ordinary message.
	RecoverMessage = "message"
	// RecoverNone: nothing muster can do — answer in the terminal (or there is
	// nothing to recover: it worked).
	RecoverNone = "none"
)

How a card recovers from a reason (Reason.Recovery).

View Source
const (
	MaxSnapshot  = 8000
	MaxNameRunes = 200
	MaxWindow    = 32
	MaxQuestions = 64
)

The bounds of a row's columns (each also a CHECK in 0113).

View Source
const MaxList = 5000

MaxList bounds List.

View Source
const RowTTL = 30 * 24 * time.Hour

Retention: a row is deleted RowTTL after it was written (Store.Prune, from the attention sweep).

Variables

View Source
var ErrBadAttempt = errors.New("askattempt: not a valid attempt")

ErrBadAttempt: a write refused before it reached the database.

View Source
var Reasons = map[string]Reason{

	"typed":     {OutcomeOK, RecoverNone, "Typed into the terminal's picker."},
	"relayed":   {OutcomeOK, RecoverNone, "Answered through opencode's API."},
	"dismissed": {OutcomeOK, RecoverNone, "Dismissed with Esc."},
	"queued":    {OutcomeOK, RecoverNone, "Sent to the session as a message (queued)."},
	"duplicate": {OutcomeNoop, RecoverNone, "The same answers again: already typed, or being typed."},

	"too-large":      {OutcomeRefused, RecoverNone, "The form was too large to read."},
	"not-found":      {OutcomeRefused, RecoverNone, "Muster had no such card for this window (it may have restarted)."},
	"read-only":      {OutcomeRefused, RecoverNone, "The host is read-only (not started with -interactive)."},
	"step-up":        {OutcomeRefused, RecoverRetry, "The sign-in was stale: a fresh sign-in was asked for."},
	"invalid":        {OutcomeRefused, RecoverNone, "The answers were not ones the question takes."},
	"closed":         {OutcomeRefused, RecoverNone, "The question was no longer open."},
	"in-progress":    {OutcomeRefused, RecoverRetry, "Another answer was being typed into it."},
	"unsupported":    {OutcomeRefused, RecoverNone, "The host's muster-mirror cannot do this."},
	"not-waiting":    {OutcomeRefused, RecoverNone, "opencode was no longer waiting on that ask."},
	"unanswerable":   {OutcomeRefused, RecoverNone, "The card could not be answered here (the host is offline, or cannot relay answers)."},
	"not-offered":    {OutcomeRefused, RecoverNone, "Send as a message was not offered for this card."},
	"queue-refused":  {OutcomeRefused, RecoverNone, "The send queue refused the message (the window cannot be queued for, or the queue is full)."},
	"dismiss-failed": {OutcomeFailed, RecoverNone, "The picker could not be dismissed, so no message was sent."},

	"not-sent":     {OutcomeFailed, RecoverRetry, "The answer never reached the host."},
	"no-picker":    {OutcomeFailed, RecoverMessage, "The picker was not on the terminal's screen."},
	"unreadable":   {OutcomeFailed, RecoverMessage, "The question could not be read off the terminal's screen."},
	"touched":      {OutcomeFailed, RecoverNone, "Someone was answering it in the terminal."},
	"lost":         {OutcomeFailed, RecoverRetry, "The picker changed part-way through typing."},
	"unrecognised": {OutcomeFailed, RecoverMessage, "The picker's layout was not recognised (Claude Code may have changed)."},
	"busy":         {OutcomeFailed, RecoverRetry, "Another answer was being typed into that terminal."},
	"timeout":      {OutcomeFailed, RecoverRetry, "The host did not report back in time."},
	"error":        {OutcomeFailed, RecoverRetry, "Something else went wrong."},

	"gone":           {OutcomeFailed, RecoverNone, "opencode had moved on from that ask."},
	"unreachable":    {OutcomeFailed, RecoverRetry, "The host could not reach opencode."},
	"answer-unknown": {OutcomeFailed, RecoverNone, "opencode did not say whether it took the answer."},
	"answer-refused": {OutcomeFailed, RecoverNone, "opencode refused the answer."},
}

Reasons is EVERY reason an attempt can end with — THE LEDGER. A new path in any door must name one of these (the store refuses anything else, and internal/api's ledger test pins the set it can produce to this one).

Functions

func OutcomeOf

func OutcomeOf(reason string) string

OutcomeOf is reason's outcome ("" for an unknown one).

func ReasonCodes

func ReasonCodes() []string

ReasonCodes is every key of Reasons, sorted.

func Recovery

func Recovery(reason string) string

Recovery is reason's recovery (RecoverNone for an unknown one).

func RedactSnapshot

func RedactSnapshot(s string) string

RedactSnapshot is a pane snapshot as a row keeps it: redacted (redact.Secrets, the one redactor) and cut to MaxSnapshot characters. 🔴 Redaction BEFORE the cut, so a cut cannot split a secret into a fragment the redactor no longer recognises; the tail is kept, not the head — the picker is at the bottom of the pane.

func ShapeKey

func ShapeKey(s Shape) string

ShapeKey names a shape for grouping: its question count, whether its questions are single- or multi-select (or mixed), and whether "Other" was used. Never its text.

Types

type Attempt

type Attempt struct {
	ID    int64
	Owner int64
	At    time.Time
	// Runtime, Door, Action and Method are their constants.
	Runtime, Door, Action, Method string
	// Where: the mirrored window.
	Host, Session, Window string
	// CardID is the card's own id: a Claude call's tool_use id, an opencode
	// ask's prompt id.
	CardID string
	Shape  Shape
	// Outcome is Reasons[Reason].Outcome (the store sets it).
	Outcome, Reason string
	// Keys is how many keys of the answer reached the picker; Duration how
	// long the attempt took.
	Keys     int
	Duration time.Duration
	// Number is which attempt on CardID this is, from 1 (the store numbers it).
	Number int
	// Snapshot is the terminal pane at a failure the host reported: redacted
	// and capped by the store.
	Snapshot string
}

Attempt is one row of ask_attempts.

type Keyed

type Keyed struct {
	Key  string
	Rate Rate
}

Keyed is a rate under a key.

type Mem

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

Mem is Store in memory, each principal's rows its own (its owner is ctx's principal's user id, as row-level security keys a row): for tests, and the e2e fixture servers that have no database.

func (*Mem) All

func (m *Mem) All() []Attempt

All is every row, every owner's, in order written (tests).

func (*Mem) ForCard

func (m *Mem) ForCard(ctx context.Context, cardID string) ([]Attempt, error)

ForCard implements Store.

func (*Mem) List

func (m *Mem) List(ctx context.Context, since time.Time, limit int) ([]Attempt, error)

List implements Store.

func (*Mem) Prune

func (m *Mem) Prune(_ context.Context, before time.Time) (int, error)

Prune implements Store.

func (*Mem) Record

func (m *Mem) Record(ctx context.Context, a Attempt) (Attempt, error)

Record implements Store.

type PG

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

PG is Store on Postgres.

func NewPG

func NewPG(pool *pgxpool.Pool) *PG

NewPG is Store over pool.

func (*PG) ForCard

func (p *PG) ForCard(ctx context.Context, cardID string) ([]Attempt, error)

ForCard implements Store.

func (*PG) List

func (p *PG) List(ctx context.Context, since time.Time, limit int) ([]Attempt, error)

List implements Store.

func (*PG) Prune

func (p *PG) Prune(ctx context.Context, before time.Time) (int, error)

Prune implements Store.

func (*PG) Record

func (p *PG) Record(ctx context.Context, a Attempt) (Attempt, error)

Record implements Store.

The attempt number is counted in the INSERT, under the caller's row-level security: the caller's earlier rows on the same card, plus one.

type Rate

type Rate struct {
	OK, Total int
}

Rate is a success rate: of Total counted attempts, OK worked. A no-op (OutcomeNoop) is not counted, and neither is a Dismiss: the rate is of answers.

func (Rate) Percent

func (r Rate) Percent() int

Percent is the rate in whole percent, rounded down; 0 for none.

type Reason

type Reason struct {
	// Outcome is one of the Outcome constants.
	Outcome string
	// Recovery is one of the Recover constants.
	Recovery string
	// Text says what happened, as the Answers page shows it.
	Text string
}

Reason is one reason code's meaning.

type ReasonCount

type ReasonCount struct {
	Reason string
	Count  int
}

ReasonCount is how many attempts ended with Reason.

type Shape

type Shape struct {
	// Options is each question's option count; Multi whether each is
	// multi-select. Both have one entry per question.
	Options []int
	Multi   []bool
	// Other: an answer of one's own was given to some question.
	Other bool
}

Shape is a question set's shape: never its text.

func (Shape) Questions

func (s Shape) Questions() int

Questions is how many questions the shape has.

type Store

type Store interface {
	// Record writes a, numbered after the caller's earlier attempts on the
	// same card, and returns it as stored (ID, At, Outcome, Number, the
	// redacted and capped Snapshot).
	Record(ctx context.Context, a Attempt) (Attempt, error)
	// List is the caller's attempts at or after since, newest first, at most
	// limit.
	List(ctx context.Context, since time.Time, limit int) ([]Attempt, error)
	// ForCard is the caller's attempts on card id, oldest first: its timeline.
	ForCard(ctx context.Context, cardID string) ([]Attempt, error)
	// Prune is the retention sweep, for every owner (the system scope): it
	// deletes rows written before before, and returns how many.
	Prune(ctx context.Context, before time.Time) (int, error)
}

Store is the answer-attempt log, under row-level security: every method but Prune acts as ctx's principal, on its rows only.

type Summary

type Summary struct {
	Overall   Rate
	ByRuntime []Keyed
	ByShape   []Keyed
	// Failures is every reason that was not OK (refused, failed), with its
	// count, most first.
	Failures []ReasonCount
}

Summary is one window's numbers.

func Summarise

func Summarise(as []Attempt, since time.Time) Summary

Summarise is the summary of the attempts in as at or after since.

Jump to

Keyboard shortcuts

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