Documentation
¶
Overview ¶
Package steward is the W2b steward (design 2026-10-05 §9 / §14.4): a resident ACP session that only schedules and tidies the work items — it reads, notes, reminds, suggests merges and asks sessions to report, but never decides (no done / dropped, no job submit, no config). Everything it needs lives in the database (work items, journal, request ledger, the versioned steward notes), so the session is disposable: it ends when idle, and a new one — on any agent — is rebuilt from the prime.
The package owns the lifecycle, the prime, the notes, the daily review and the event inbox. It reaches the job layer only through SessionHost (G022: httpapi adapts job.Service), and the credential that actually bounds the steward is enforced by the HTTP layer, not here.
Index ¶
- Constants
- Variables
- type AskResult
- type JobInfo
- type Notes
- type NotesInfo
- type Prime
- type ResumeSpec
- type ReviewOpts
- type ReviewResult
- type Service
- func (s *Service) Ask(ctx context.Context, text, by string) (AskResult, error)
- func (s *Service) BuildPrime(now time.Time) (Prime, error)
- func (s *Service) By() string
- func (s *Service) Close() error
- func (s *Service) GetNotes(version int) (Notes, bool, error)
- func (s *Service) NoteDue(w jobstore.WorkItem, reason string, at int64)
- func (s *Service) NotesHistory() ([]Notes, error)
- func (s *Service) NotesStatus() (NotesInfo, error)
- func (s *Service) Observations(limit int) ([]jobstore.StewardObservation, error)
- func (s *Service) Observe(method, path, body string) bool
- func (s *Service) Observing() bool
- func (s *Service) Reconcile()
- func (s *Service) Restart(ctx context.Context) (StartResult, error)
- func (s *Service) Run(stop <-chan struct{})
- func (s *Service) RunReview(ctx context.Context, o ReviewOpts) (ReviewResult, error)
- func (s *Service) SetBackgroundAgentsFn(fn func() config.BackgroundAgentsConfig)
- func (s *Service) SetConfigFn(fn func() (config.StewardConfig, config.WorkConfig))
- func (s *Service) SetLanguageFn(fn func() i18n.Lang)
- func (s *Service) SetNotes(body, by string, expectedVersion int) (Notes, error)
- func (s *Service) SetNow(fn func() time.Time)
- func (s *Service) SetReviewSummary(text string) (jobstore.StewardReview, error)
- func (s *Service) SetSettings(st Settings)
- func (s *Service) SetTodayUnadvised(fn func() ([]string, error))
- func (s *Service) Start(ctx context.Context) (StartResult, error)
- func (s *Service) Status() Status
- func (s *Service) Stop() (bool, error)
- func (s *Service) Tick(ctx context.Context, now time.Time)
- func (s *Service) WaitIdle()
- type SessionHost
- type SessionResumer
- type Settings
- type StartResult
- type StartSpec
- type Status
Constants ¶
const ( TriggerDaily = "daily" TriggerManual = "manual" TriggerEvent = "event" )
Review triggers.
const ( StateStopped = "not_started" StateRunning = "running" StateIdle = "idle" )
Session states shown in the status.
Variables ¶
var ( ErrNotesConflict = errors.New("steward notes changed since you read them; read the latest version and retry") ErrNotesTooLarge = fmt.Errorf("steward notes exceed %d KiB", jobstore.StewardNotesMaxBytes>>10) )
Errors of the notes API.
var ( ErrDisabled = errors.New("steward is not enabled (set steward.enabled in the settings)") ErrNoAgent = errors.New("no steward agent chosen (set steward.agent to an installed acp-agent)") ErrBusy = errors.New("steward is busy with another turn; try again shortly") ErrEmpty = errors.New("empty message") )
Errors surfaced to the entry layers.
Functions ¶
This section is empty.
Types ¶
type AskResult ¶
type AskResult struct {
JobID string `json:"job_id"`
// Started is true when the question opened a new session (its prime rode along).
Started bool `json:"started"`
}
AskResult is where the answer will appear.
type JobInfo ¶
type JobInfo struct {
ID string
Agent string
Status string
Live bool // not terminal
AwaitingInput bool // between turns: a message can be sent
TurnNo int
StartedAt int64
// SessionID / Usage are what the (ended) job reported: the agent-side session and its
// usage with the context level. Optional; the common runner records them.
SessionID string
Usage *runner.Usage
}
JobInfo is what the steward needs to know about its session job.
type Notes ¶
type Notes struct {
Version int `json:"version"`
Body string `json:"body"`
By string `json:"by,omitempty"`
At int64 `json:"at,omitempty"`
}
Notes is one version of the steward notes.
type NotesInfo ¶
type NotesInfo struct {
Version int `json:"version"`
Bytes int `json:"bytes"`
// NeedSlim is true when the notes outgrew the soft cap (8KB): the next review asks the
// steward to rewrite them shorter.
NeedSlim bool `json:"need_slim"`
}
NotesInfo summarises the latest version.
type ResumeSpec ¶ added in v0.208.0
type ResumeSpec struct {
// JobID is the earlier steward session job whose session is loaded.
JobID string
Prompt string
Project string
}
ResumeSpec asks the host to continue the session of an earlier steward job (the agent loads the same session) and drive Prompt as its next turn.
type ReviewOpts ¶
type ReviewOpts struct {
// Trigger is daily | manual | event ("" = manual).
Trigger string
// Force runs the review even when no work item changed since the last one.
Force bool
}
ReviewOpts selects what to review.
type ReviewResult ¶
type ReviewResult struct {
ReviewID int64 `json:"review_id"`
// Skipped is true when nothing needed reviewing: no session was started.
Skipped bool `json:"skipped"`
Reason string `json:"reason,omitempty"`
JobID string `json:"job_id,omitempty"`
Items []string `json:"items,omitempty"`
Events int `json:"events"`
}
ReviewResult says what a review run did.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the steward.
func (*Service) Ask ¶
Ask puts a question to the steward: an unstarted steward is started with the question as its first turn; a live one is waited for until it is between turns, then spoken to. The answer streams through the session job's ACP events (the panel follows JobID).
func (*Service) BuildPrime ¶
BuildPrime renders the steward's first message: role + notes + open work items (priority truncated) + the last 24h of journal + the request ledger, within primeMax bytes. The role and the notes are never cut (the notes are capped on their own); the items take up to 60% of what is left, the ledger and the journal share the rest.
func (*Service) Close ¶
Close stops the Run loop and the review watchers and waits for them, at most closeWait; it returns an error when something was still running then. Safe to call more than once, and before Run ever started. Call it before the store is closed.
func (*Service) GetNotes ¶
GetNotes returns the latest notes (version 0 = none written yet) or, with version > 0, that historical version (ok=false when it does not exist).
func (*Service) NoteDue ¶
NoteDue is the work service's due hook: a reminder / park deadline was announced.
func (*Service) NotesHistory ¶
NotesHistory lists every version, newest first (bodies included: they are small).
func (*Service) NotesStatus ¶
NotesStatus reports the latest version, its size and whether it needs slimming.
func (*Service) Observations ¶ added in v0.208.0
func (s *Service) Observations(limit int) ([]jobstore.StewardObservation, error)
Observations lists what the steward would have done, newest first.
func (*Service) Observe ¶ added in v0.208.0
Observe records one write the steward asked for during an observe-only review. It reports false (and records nothing) when the steward is not observing, so the caller applies the write.
func (*Service) Observing ¶ added in v0.208.0
Observing reports whether the steward's effectful writes are recorded instead of applied right now: a proactive review is in flight and the steward may not act on its own.
func (*Service) Reconcile ¶
func (s *Service) Reconcile()
Reconcile ends a session that no longer matches the configuration: the steward was switched off, or its agent was switched (the next need rebuilds on the new agent).
func (*Service) Restart ¶
func (s *Service) Restart(ctx context.Context) (StartResult, error)
Restart ends the live session and opens a fresh one from the prime.
func (*Service) Run ¶
func (s *Service) Run(stop <-chan struct{})
Run ticks until stop is closed. A review the server was killed in the middle of is closed as failed on the first pass.
func (*Service) RunReview ¶
func (s *Service) RunReview(ctx context.Context, o ReviewOpts) (ReviewResult, error)
RunReview runs one review: it records the run, tells the (started on demand) steward session which work items to look at, and finishes the record in the background when the turn ends. Nothing happens — and no session starts — when nothing changed.
func (*Service) SetBackgroundAgentsFn ¶ added in v0.208.0
func (s *Service) SetBackgroundAgentsFn(fn func() config.BackgroundAgentsConfig)
SetBackgroundAgentsFn supplies the live server.background_agents block (unified rotation thresholds and budget hard stops). nil keeps the defaults.
func (*Service) SetConfigFn ¶
func (s *Service) SetConfigFn(fn func() (config.StewardConfig, config.WorkConfig))
SetConfigFn supplies the live steward: and work: blocks (read on every use, so a hot reload applies to the next one).
func (*Service) SetLanguageFn ¶ added in v0.198.0
SetLanguageFn supplies the language for steward prompts. Nil uses the deployment default.
func (*Service) SetNotes ¶
SetNotes writes a new version if expectedVersion is the current one (0 = the first write). The previous versions stay.
func (*Service) SetReviewSummary ¶
func (s *Service) SetReviewSummary(text string) (jobstore.StewardReview, error)
SetReviewSummary stores the steward's point of view on the running (or today's finished) review: what the daily digest appends as 管家点评.
func (*Service) SetSettings ¶ added in v0.179.0
SetSettings injects the extension settings. nil (or a nil service) means "registry defaults", so a steward built without one sends exactly the code prompts.
func (*Service) SetTodayUnadvised ¶
SetTodayUnadvised supplies the keys of the 「今天」 cards without advice. A review with no changed work item still runs when one of them was never put before the steward (a card it already saw and chose to skip does not wake it again); nil (or an error) leaves the advice step in every review and never forces one.
func (*Service) Start ¶
func (s *Service) Start(ctx context.Context) (StartResult, error)
Start opens the steward session when none lives (a no-op otherwise).
func (*Service) Status ¶
Status reports the current state. It reads the recorded session job and asks the host whether it still lives (a session that ended by itself reads as not_started).
func (*Service) Stop ¶
Stop ends the live session (the next need rebuilds it from the prime). It reports whether there was one.
type SessionHost ¶
type SessionHost interface {
// StartSession submits the steward's resident session job and returns its id.
StartSession(StartSpec) (string, error)
// Say sends the next turn to the live session.
Say(jobID, text string) error
// End asks the session to end after the current turn.
End(jobID string) error
Job(jobID string) (JobInfo, bool)
// CheckAgent says why the agent cannot run as steward ("" nil = usable).
CheckAgent(agent string) error
}
SessionHost is the seam to the job layer (httpapi adapts job.Service).
type SessionResumer ¶ added in v0.208.0
type SessionResumer interface {
ResumeSession(ResumeSpec) (string, error)
}
SessionResumer is the optional face of a SessionHost that can load an earlier steward session. A host without it always rebuilds.
type Settings ¶ added in v0.179.0
Settings is the slice of the extension-settings service the prompts read. An interface keeps this package off the entry layers and lets a test supply its own values (G022).
type StartResult ¶
type StartResult struct {
JobID string `json:"job_id"`
// Started is true when this call opened a new session (false = it was already live).
Started bool `json:"started"`
}
StartResult is what a start did.
type StartSpec ¶
type StartSpec struct {
Agent string
Project string
Title string
// Prompt is the first turn: the prime (plus the first question or task).
Prompt string
// IdleSec ends the session after that long without a turn.
IdleSec int
// Approval is the session job's approval gate (gofer-j0aq): the steward's OWN policy
// (steward.approval), so its tidy-up does not park on a human for every gofer write.
// Nil = steward.approval is not configured: the host uses the project's own policy
// with the steward's writes released (config.StewardApprovalOver).
Approval *config.ApprovalConfig
}
StartSpec describes the steward's session job.
type Status ¶
type Status struct {
Enabled bool `json:"enabled"`
Agent string `json:"agent"`
Project string `json:"project"`
// State is not_started | running (a turn in progress) | idle (waiting for input).
State string `json:"state"`
JobID string `json:"job_id,omitempty"`
// JobAgent is the agent of the live session (differs from Agent right after a switch,
// until the next reconcile ends it).
JobAgent string `json:"job_agent,omitempty"`
StartedAt int64 `json:"started_at,omitempty"`
LastActiveAt int64 `json:"last_active_at,omitempty"`
TurnNo int `json:"turn_no,omitempty"`
IdleEndMin int `json:"idle_end_min"`
ReviewTime string `json:"review_time"`
EventWake bool `json:"event_wake"`
// AgentError says why the chosen agent cannot run ("" = usable or none chosen).
AgentError string `json:"agent_error,omitempty"`
NotesVersion int `json:"notes_version"`
NotesBytes int `json:"notes_bytes"`
NotesNeedSlim bool `json:"notes_need_slim"`
PendingEvents int `json:"pending_events"`
LastReview *jobstore.StewardReview `json:"last_review,omitempty"`
}
Status is the steward's state for the settings page, the panel and the CLI.