today

package
v0.210.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 17 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 today is the N3 「今天」 decision home (design docs/design/2026-10-09-n3-today-decision-home-design.md §1/§2): it folds the structured "a person must decide" signals — pending interactions, OPEN decisions, relay turns, needs_review jobs, jobs held for approval, held mail and blocked plans — into one ordered card queue (the candidates of the 「等我」 list, see internal/inbox), plus the digest counts and the status bar. It only READS existing sources: every card action maps to an existing write API, which the console calls directly.

The httpapi layer binds / validates and forwards here (G021).

Index

Constants

View Source
const (
	AdviceTextRunes   = 60
	AdviceDigestLines = 5
)

Advice limits.

View Source
const (
	WokeTime     = "time"
	WokeJob      = "job"
	WokeActivity = "activity"
)

Wake reasons (Card.WokeReason).

View Source
const (
	KindInteraction = "interaction"
	KindDecision    = "decision"
	KindRelay       = "relay"
	// KindPermission is a terminal agent's tool permission prompt waiting on the web
	// (Claude Code PermissionRequest; only the session's owner may answer it).
	KindPermission = "permission"
	KindReview     = "review"
	// KindApproval is a job held for a person's approval (gofer-9b1b, status
	// awaiting_approval): approve it (it then runs) or reject it (cancelled, never run).
	KindApproval    = "approval"
	KindPlanBlocked = "plan_blocked"
	// KindMailHeld is the single summary card for letters nobody could receive (the gofer
	// mailbox, plan M7): they wait as held until somebody readdresses or cancels them.
	KindMailHeld = "mail_held"
	// KindJobFailed is the card of a failed job a person submitted (inbox.TerminalCards builds
	// it outside this package). It enters the 「等我」 list but is not a queue card: advice
	// cannot be written for it.
	KindJobFailed = "job.failed"
	// KindChildWakeFailed is the card of a child job whose result can no longer reach the
	// resident parent job that submitted it (inbox.ChildWakeCards builds it outside this
	// package from the job.child_wake_failed events). Like KindJobFailed it enters the 「等我」
	// list but is not a queue card: advice cannot be written for it.
	KindChildWakeFailed = "job.child_wake_failed"
)

Card kinds (DecisionCard.kind).

View Source
const (
	MailHeldCardKey = KindMailHeld + ":box"
	MailHeldLink    = "/mail?state=held"
)

MailHeldCardKey is the stable key of the held-mail summary card; MailHeldLink is the web target its 「去指派」 action opens (the mailbox page's 待指派 tab).

View Source
const (
	UrgencyNow      = "now"
	UrgencyBlocking = "blocking"
	UrgencyNormal   = "normal"
)

Urgency values. now = will time out soon, blocking = something waits on it.

View Source
const MaxHandledDays = 30

MaxHandledDays caps GET /v1/today/handled?days=.

View Source
const (
	// MaxSnoozeSec caps until_at (30 days ahead).
	MaxSnoozeSec = 30 * 86400
)
View Source
const PermissionSubtypeQuestion = "question"

PermissionSubtypeQuestion is the Card.Subtype of a terminal permission card that carries an AskUserQuestion (an answer is wanted, not an approval).

View Source
const SnoozeActionID = "snooze"

SnoozeActionID is the today.action audit id a snooze records.

Variables

View Source
var (
	// ErrInvalidAdvice is a malformed advice (text / digest / action).
	ErrInvalidAdvice = errors.New("today: invalid advice")
	// ErrUnknownCard is advice on a card that is not in the current queue.
	ErrUnknownCard = errors.New("today: no such card in the current queue")
)
View Source
var (
	// ErrInvalidSnooze is a malformed snooze request.
	ErrInvalidSnooze = errors.New("today: invalid snooze")
	// ErrCardNotQueued is a snooze for a card that is not in the queue (any more).
	ErrCardNotQueued = errors.New("today: card not in the queue")
)
View Source
var ErrInvalidAction = errors.New("today: invalid action")

ErrInvalidAction is a malformed POST /v1/today/actions body.

Functions

func ActionKey

func ActionKey(a Action) string

ActionKey is the stable id of a card action: answer actions are told apart by value (answer:<value>), the rest by id. Advice action_id uses it.

func Advisable

func Advisable(kind string, a Action) bool

Advisable reports whether an action of a card of this kind can be 「按建议」: a one-click decision — not a reply box, not a navigation link, and never an option of a decision card (the steward only adds background there; design §5).

func CanAdvise added in v0.209.0

func CanAdvise(kind string) bool

CanAdvise reports whether advice can be written for a card of this kind: every card of the queue, but not the two kinds the 「等我」 list adds from outside it (a failed job, a child receipt that can no longer reach its resident parent).

func DiagnoseMirror

func DiagnoseMirror(recs []jobstore.TrackerRecord, now time.Time) map[string][]tracker.DoctorFinding

DiagnoseMirror runs the server-side doctor over mirrored records and returns the findings per key (keys without findings are absent).

func MirrorMemories

func MirrorMemories(recs []jobstore.TrackerRecord) []tracker.Memory

MirrorMemories decodes the live (non-tombstone) mirrored memories.

func SortCards

func SortCards(cards []Card)

SortCards orders the queue: urgency=now first (soonest deadline first), then score descending, then the longest wait first; the key breaks remaining ties.

Types

type Action

type Action struct {
	ID           string `json:"id"`
	Label        string `json:"label"`
	Style        string `json:"style,omitempty"`
	Value        string `json:"value,omitempty"`
	NeedsText    bool   `json:"needs_text,omitempty"`
	OptionalText bool   `json:"optional_text,omitempty"`
}

Action is one card button. ID names the existing write API the console calls (answer / reply / ack / accept / rerun / diff / report / park / adopt / dismiss / resume / approve / reject / open); Value is the answer token for answer actions. NeedsText asks for a text the action cannot go without; OptionalText offers a text box the person may leave empty (an approval card's 「拒绝」 reason).

type ActionInput

type ActionInput struct {
	CardKey        string `json:"card_key"`
	ActionID       string `json:"action_id"`
	AdviceActionID string `json:"advice_action_id,omitempty"`
	Title          string `json:"title,omitempty"`
	Label          string `json:"label,omitempty"`
	Kind           string `json:"kind,omitempty"`
	// T4: the advice text / its action label at that moment, and whether the person
	// clicked 「按建议」. A missing advice is filled from the stored one.
	AdviceText  string `json:"advice_text,omitempty"`
	AdviceLabel string `json:"advice_label,omitempty"`
	ViaAdvice   bool   `json:"via_advice,omitempty"`
	// Project is the card's project_key at the time of the action (7798 第二期): it is
	// what a caller ceiling filters the 「已处理」 list by. Empty for a global card
	// (capture box, held mail) — such a row is out of scope for a restricted caller.
	Project string `json:"project,omitempty"`
}

ActionInput is what the console records after a card action succeeded (design §2.3): the card, the action it took, the steward's advice action at that moment (T4), and the display bits the 「已处理」 drawer shows once the card is gone.

type Advice

type Advice struct {
	Text     string `json:"text"`
	ActionID string `json:"action_id,omitempty"`
	Digest   string `json:"digest,omitempty"`
	By       string `json:"by,omitempty"`
	At       int64  `json:"at,omitempty"`
}

Advice is the steward's one-line suggestion (T4, advice.go): ActionID (an ActionKey of the card) becomes the 「按建议:X」 button, Digest (≤5 lines) sits in 「详情」.

type AdviceInput

type AdviceInput struct {
	CardKey  string `json:"card_key"`
	Text     string `json:"text"`
	ActionID string `json:"action_id,omitempty"`
	Digest   string `json:"digest,omitempty"`
}

AdviceInput is POST /v1/today/advice and gofer_today_advise.

type Approval added in v0.137.0

type Approval struct {
	Reason        string   `json:"reason,omitempty"`
	Origin        string   `json:"origin,omitempty"`
	Command       []string `json:"command,omitempty"`
	PromptPreview string   `json:"prompt_preview,omitempty"`
	TimeoutSec    int      `json:"timeout_sec,omitempty"`
}

Approval is the hard data of an approval card's 「详情」 (gofer-9b1b): why the job is held, who submitted it, and what it would run (an exec job's argv, or the head of an agent job's prompt) — the full thing is on the job page.

type Blocks

type Blocks struct {
	Score int    `json:"score"`
	Items int    `json:"items"`
	Text  string `json:"text,omitempty"`
}

Blocks says what a card holds up (design §2.2). Score drives the ordering, Items is the count behind the short 「卡住 N」 label and Text lists the sources.

type Card

type Card struct {
	Key          string    `json:"key"`
	Kind         string    `json:"kind"`
	Tag          string    `json:"tag"`
	Urgency      string    `json:"urgency"`
	Blocks       Blocks    `json:"blocks"`
	Title        string    `json:"title"`
	ProjectKey   string    `json:"project_key,omitempty"`
	Agent        string    `json:"agent,omitempty"`
	WaitingSince int64     `json:"waiting_since"`
	ExpiresAt    int64     `json:"expires_at,omitempty"`
	ActivityAt   int64     `json:"activity_at"`
	Summary      string    `json:"summary"`
	Review       *Review   `json:"review,omitempty"`
	Approval     *Approval `json:"approval,omitempty"`
	Refs         Refs      `json:"refs"`
	Actions      []Action  `json:"actions"`
	Advice       *Advice   `json:"advice"`
	// Subtype is a structured fact of the card's source that the 「等我」 judgement needs and
	// the kind alone does not carry: an interaction card's type (permission / confirmation /
	// question / choice), "question" on a terminal permission card that is really an
	// AskUserQuestion. Never model output.
	Subtype string `json:"subtype,omitempty"`
	// Waiting / WaitingLabel are the 「等我」 category (inbox.Category) and its label in the
	// request language; only the cards of Response.Waiting carry them.
	Waiting      string `json:"waiting,omitempty"`
	WaitingLabel string `json:"waiting_label,omitempty"`
	// Column is the additive inbox projection column; empty keeps old clients unchanged.
	Column     string `json:"column,omitempty"`
	Woke       bool   `json:"woke,omitempty"`
	WokeReason string `json:"woke_reason,omitempty"`
}

Card is one DecisionCard.

type Deps

type Deps struct {
	Store   *jobstore.Store
	Work    *work.Service
	Steward StewardStatus
	Runners func() RunnerStatus
	Version func() string
	Now     func() time.Time
	// Language is the server's text language (server.language, auto resolved); nil
	// reads as the default language. It is the language of text that gets stored and of
	// reads that carry no request language.
	Language func() i18n.Lang
}

Deps are the sources the service reads.

type Digest

type Digest struct {
	SinceLast SinceLast `json:"since_last"`
	Title     string    `json:"title"`
	Text      string    `json:"text"`
}

Digest is the folded one-line digest plus today's work digest (work.BuildDigest).

type Handled

type Handled struct {
	At             int64  `json:"at"`
	Actor          string `json:"actor,omitempty"`
	CardKey        string `json:"card_key"`
	Kind           string `json:"kind,omitempty"`
	Title          string `json:"title,omitempty"`
	ActionID       string `json:"action_id"`
	Label          string `json:"label,omitempty"`
	AdviceActionID string `json:"advice_action_id,omitempty"`
	AdviceText     string `json:"advice_text,omitempty"`
	AdviceLabel    string `json:"advice_label,omitempty"`
	ViaAdvice      bool   `json:"via_advice,omitempty"`
	// Project is the card's project_key as recorded with the action; empty for a
	// global card. The project is carried in the row (not looked up from the card key)
	// so a restricted caller's filter stays a cheap read and survives the card being
	// gone.
	Project string `json:"project,omitempty"`
}

Handled is one 「已处理」 row.

type MemoryFinding

type MemoryFinding struct {
	TrackerID  string                  `json:"tracker_id"`
	ProjectKey string                  `json:"project_key,omitempty"`
	Key        string                  `json:"key"`
	Kind       string                  `json:"kind"`
	Summary    string                  `json:"summary,omitempty"`
	UpdatedAt  string                  `json:"updated_at,omitempty"`
	Age        string                  `json:"age,omitempty"`
	Findings   []tracker.DoctorFinding `json:"findings"`
	Content    string                  `json:"content,omitempty"`
}

MemoryFinding is one flagged mirrored memory (GET /v1/memory-findings, gofer_memory_findings).

type MemoryFindingsQuery

type MemoryFindingsQuery struct {
	TrackerID string
}

MemoryFindingsQuery filters MemoryFindings.

type Query

type Query struct {
	// Since is the 「自上次打开」 watermark (unix seconds); 0 = local midnight today.
	Since int64
	// IncludeExec also lists needs_review jobs of the exec agent (off by default).
	IncludeExec bool
	// ProjectAllowed, when non-nil, keeps only the cards and snoozed rows whose
	// project_key it accepts (a caller ceiling that bounds projects, 7798 第二期). A
	// card without a project_key is a global summary (capture box, held mail) and is
	// dropped for such a caller. nil = no filter, the unchanged behaviour.
	ProjectAllowed func(string) bool
	// Projects, when non-nil, narrows the digest's 「自上次打开」 job / commit counts to
	// these literal project keys — the same restriction ProjectAllowed expresses as a
	// predicate, in the form the store's count query needs. nil = the whole server.
	Projects []string
	// Lang is the language of the generated text (a request's Accept-Language);
	// "" = the server's language.
	Lang i18n.Lang
}

Query is the GET /v1/today input.

type Refs

type Refs struct {
	JobID         string `json:"job_id,omitempty"`
	InteractionID string `json:"interaction_id,omitempty"`
	DecisionID    string `json:"decision_id,omitempty"`
	// DecisionIDs (relay cards) are every unread open turn of the session, oldest
	// first: 「已读」 acks them all, since the card stands for all of them.
	DecisionIDs []string `json:"decision_ids,omitempty"`
	SessionID   string   `json:"session_id,omitempty"`
	ThreadID    string   `json:"thread_id,omitempty"`
	PlanID      string   `json:"plan_id,omitempty"`
	TodoID      string   `json:"todo_id,omitempty"`
}

Refs are the ids a card's actions and links need.

type Response

type Response struct {
	Digest Digest `json:"digest"`
	// Cards is the ordered card queue (snooze, advice and scope applied) behind Waiting. It is
	// not part of the wire payload: the HTTP layer folds it, with the failed-job source, into
	// Waiting (inbox.Waiting) and the MCP tools read Waiting.
	Cards []Card `json:"-"`
	// Waiting is the one 「等我」 list (inbox.Waiting): the inbox's action column, the
	// top-bar badge, the home page's decision area and the MCP gofer_today_* tools are all
	// taken from it. It is filled by the HTTP layer, which owns the caller's scope and the
	// failed-job source.
	Waiting []Card `json:"waiting"`
	// Snoozed counts the cards held back by an active 「稍后」 (T3, snooze.go).
	Snoozed int `json:"snoozed"`
	// Running is the 「正在跑」 line of the home page: terminal sessions in the running state
	// and jobs in the running status (the two numbers link to the workbench).
	Running     Running `json:"running"`
	Status      Status  `json:"status"`
	GeneratedAt int64   `json:"generated_at"`
}

Response is the GET /v1/today payload (design §2.1).

type Review

type Review struct {
	Commits int    `json:"commits"`
	Adds    int    `json:"adds"`
	Dels    int    `json:"dels"`
	Verify  string `json:"verify,omitempty"`
	Digest  string `json:"digest,omitempty"`
}

Review is the hard data of a review card's 「详情」.

type RunnerStatus

type RunnerStatus struct {
	Online  int      `json:"online"`
	Total   int      `json:"total"`
	Offline []string `json:"offline,omitempty"`
}

RunnerStatus is the runner part of the status bar, supplied by the server (it knows which workers are connected).

type Runners

type Runners struct {
	RunnerStatus
	RunningJobs int `json:"running_jobs"`
}

Runners is the runner part of the status bar plus the jobs running now.

type Running added in v0.208.0

type Running struct {
	Sessions int `json:"sessions"`
	Jobs     int `json:"jobs"`
}

Running counts what is executing right now.

type Service

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

Service builds the home page payloads.

func New

func New(d Deps) *Service

New returns a service over deps; a nil Now uses time.Now.

func (*Service) Advise

func (s *Service) Advise(in AdviceInput, by, jobID string) (Advice, error)

Advise validates and stores the advice for one card of the current queue. by is the speaker label (steward(<agent>) or human:<id>), jobID the steward's job when it wrote it.

func (*Service) CurrentAdvice

func (s *Service) CurrentAdvice(cardKey string) (*Advice, error)

CurrentAdvice reads one card's stored advice (nil when there is none).

func (*Service) Decisions

func (s *Service) Decisions(includeExec bool) ([]Card, error)

Decisions builds the ordered card queue.

func (*Service) DecisionsIn added in v0.205.0

func (s *Service) DecisionsIn(lang i18n.Lang, includeExec bool) ([]Card, error)

DecisionsIn is Decisions with the card text in lang ("" = the server's language).

func (*Service) HandledSince

func (s *Service) HandledSince(days int) ([]Handled, error)

HandledSince lists the today.action rows of the last `days` days, newest first.

func (*Service) HandledSinceScoped added in v0.178.0

func (s *Service) HandledSinceScoped(days int, allow func(string) bool) ([]Handled, error)

HandledSinceScoped is HandledSince restricted to the caller's项目范围 (7798 第二期): a non-nil allow keeps only rows whose recorded project it accepts. nil = every row, unchanged.

func (*Service) MemoryFindings

func (s *Service) MemoryFindings(q MemoryFindingsQuery) ([]MemoryFinding, error)

MemoryFindings runs the server-side doctor over every mirrored repository (or one).

func (*Service) Now

func (s *Service) Now() time.Time

Now is the service clock.

func (*Service) PruneAdvice

func (s *Service) PruneAdvice() (int, error)

PruneAdvice drops the advice of every card that is gone; it returns how many it removed.

func (*Service) RecordAction

func (s *Service) RecordAction(in ActionInput, actor string) (Handled, error)

RecordAction appends one today.action audit row.

func (*Service) Snooze

func (s *Service) Snooze(in SnoozeInput, actor string) (SnoozedCard, error)

Snooze takes a card out of the queue and records the today.action audit.

func (*Service) Snoozed

func (s *Service) Snoozed(includeExec bool) ([]SnoozedCard, error)

Snoozed lists the cards that are snoozed right now (wake rules applied first).

func (*Service) SnoozedScoped added in v0.178.0

func (s *Service) SnoozedScoped(includeExec bool, allow func(string) bool) ([]SnoozedCard, error)

SnoozedScoped is Snoozed narrowed to the caller's项目范围 (gofer-7798 第二期): only the rows whose card belongs to an allowed project are returned. nil = every row, unchanged.

func (*Service) SnoozedScopedIn added in v0.205.0

func (s *Service) SnoozedScopedIn(lang i18n.Lang, includeExec bool, allow func(string) bool) ([]SnoozedCard, error)

SnoozedScopedIn is SnoozedScoped with the card text (tag, title) in lang.

func (*Service) Store

func (s *Service) Store() *jobstore.Store

Store exposes the underlying store (sibling aggregations reuse it).

func (*Service) Today

func (s *Service) Today(q Query) (Response, error)

Today builds the GET /v1/today payload.

func (*Service) UnadvisedCount

func (s *Service) UnadvisedCount() (int, error)

UnadvisedCount is len(UnadvisedKeys).

func (*Service) UnadvisedKeys

func (s *Service) UnadvisedKeys() ([]string, error)

UnadvisedKeys lists the keys of the queue's cards of the advised kinds that have no advice yet (the steward's review trigger and its prompt count).

func (*Service) Unsnooze

func (s *Service) Unsnooze(cardKey string) (bool, error)

Unsnooze puts a card back in the queue; ok is false when it was not snoozed.

type SinceLast

type SinceLast struct {
	Since      int64 `json:"since"`
	JobsDone   int   `json:"jobs_done"`
	JobsFailed int   `json:"jobs_failed"`
	Commits    int   `json:"commits"`
}

SinceLast is the 「自上次打开:完成 N · 失败 M · 新提交 K」 line.

type SnoozeInput

type SnoozeInput struct {
	CardKey    string `json:"card_key"`
	UntilAt    int64  `json:"until_at,omitempty"`
	UntilJobID string `json:"until_job_id,omitempty"`
}

SnoozeInput is the POST /v1/today/snooze body: exactly one of UntilAt / UntilJobID.

type SnoozedCard

type SnoozedCard struct {
	CardKey    string `json:"card_key"`
	Kind       string `json:"kind"`
	Tag        string `json:"tag,omitempty"`
	Title      string `json:"title"`
	ProjectKey string `json:"project_key,omitempty"`
	UntilAt    int64  `json:"until_at,omitempty"`
	UntilJobID string `json:"until_job_id,omitempty"`
	ExpiresAt  int64  `json:"expires_at,omitempty"`
	CreatedAt  int64  `json:"created_at"`
}

SnoozedCard is one 「已稍后」 row.

type Status

type Status struct {
	UsageToday   *UsageToday   `json:"usage_today,omitempty"`
	StewardToday *StewardToday `json:"steward_today,omitempty"`
	Runners      Runners       `json:"runners"`
	Version      string        `json:"version"`
	Alerts       []string      `json:"alerts"`
}

Status is the bottom status bar (design §1.4): runner, today's usage, the steward and the version, plus the alerts that turn an item red and move it first.

UsageToday and StewardToday are pointers so they can be LEFT OUT (gofer-7798 第二期): a caller under a ceiling gets no server-global numbers (计划决策 2, the console hides those blocks). Both are filled for every unrestricted caller, so its payload is unchanged.

type StewardStatus

type StewardStatus interface {
	Status() steward.Status
}

StewardStatus reads the steward's live status (nil-safe through Deps).

type StewardToday

type StewardToday struct {
	Enabled   bool   `json:"enabled"`
	State     string `json:"state,omitempty"`
	Notes     int    `json:"notes"`
	Summaries int    `json:"summaries"`
	// Advice counts the cards the steward advised today (T4; a person's advice is not counted).
	Advice int    `json:"advice"`
	Review string `json:"review,omitempty"`
}

StewardToday is the steward's day: whether it runs, its state, the notes it wrote and the auto tidy-ups done today, and today's review state.

type UsageToday

type UsageToday struct {
	Jobs          int     `json:"jobs"`
	TotalTokens   int64   `json:"total_tokens"`
	CostUSD       float64 `json:"cost_usd"`
	SessionTokens int64   `json:"session_tokens"`
}

UsageToday sums today's job usage (by start time, server-local day) and today's terminal-session usage (OBS-14, tallied per UTC day).

Jump to

Keyboard shortcuts

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