Documentation
¶
Overview ¶
Package seat is the business layer of the seat roster (design docs/design/2026-11-18-resident-sessions-and-team-design.md §4): a seat is a long-lived working position of a caller in a project, and sessions come and go while the seat stays.
The rows live in jobstore (seats / seat_bindings / seat_charter_history). This package adds what is derived from them: validation, binding candidates, the status of the sitting session, the commands that open a seat, and the text that tells a fresh session what the seat is. Whether a session is "waiting for me" is NOT decided here: it comes in through WaitingLookup.
Index ¶
- Constants
- Variables
- func CharterTemplate(name string) (string, bool)
- func CharterTemplateNames() []string
- func Cut(s string, max int) string
- func JoinRootPath(root, rel string) string
- func Section(in SectionInput) string
- func SplitCharter(charter string) (path, text string)
- type ACPRestarter
- type Agents
- type BindInfo
- type CreateInput
- type Deps
- type Messenger
- type OpenPlan
- type Projects
- type RestartRequest
- type Sayer
- type SectionInput
- type Service
- func (s *Service) Archive(id, by string) (jobstore.Seat, error)
- func (s *Service) Bind(id, ref string, replace bool, by string) (jobstore.Seat, error)
- func (s *Service) BindCandidate(seatID, sessionID, by string) (jobstore.Seat, error)
- func (s *Service) BindInfo(id, ref string, replace bool, by string) (jobstore.Seat, BindInfo, error)
- func (s *Service) Candidates(sessionID string) ([]jobstore.Seat, error)
- func (s *Service) ContinuationText(x jobstore.Seat) (string, error)
- func (s *Service) Create(in CreateInput) (jobstore.Seat, error)
- func (s *Service) Delete(id string) error
- func (s *Service) DeliverStageNote(ctx context.Context, workItemID, ref, step, text string) (outcome string, handled bool, err error)
- func (s *Service) DeliverToSeat(ctx context.Context, req job.SeatDeliverRequest) (job.SeatDeliverResult, error)
- func (s *Service) FlushPending(ctx context.Context) (int, error)
- func (s *Service) FlushSeatOf(ctx context.Context, ref string) (int, error)
- func (s *Service) Get(id string) (jobstore.Seat, error)
- func (s *Service) History(id string) ([]jobstore.SeatBinding, []jobstore.SeatCharterRevision, error)
- func (s *Service) List(f jobstore.SeatFilter) ([]jobstore.Seat, error)
- func (s *Service) OpenPlan(id string) (OpenPlan, error)
- func (s *Service) Restart(ctx context.Context, id string) (OpenPlan, error)
- func (s *Service) SeatOfRef(ref string) (jobstore.Seat, bool, error)
- func (s *Service) SeatsByRefs(refs []string) (map[string]jobstore.Seat, error)
- func (s *Service) Status(viewer string, x jobstore.Seat) (Status, error)
- func (s *Service) Statuses(viewer string, seats []jobstore.Seat) ([]Status, error)
- func (s *Service) TakeContinuationNotice(ref, source string, lang i18n.Lang) (text string, ok bool, err error)
- func (s *Service) Unbind(id, by string) (jobstore.Seat, error)
- func (s *Service) Update(id string, p jobstore.SeatPatch) (jobstore.Seat, error)
- type Status
- type WaitingLookup
Constants ¶
const ( ReasonVacant = "vacant" ReasonUnknownAgent = "unknown_agent" ReasonNoResumeTemplate = "no_resume_template" ReasonNoProject = "no_project" ReasonNeedsRestart = "needs_restart" )
Why a seat cannot be resumed by hand (OpenPlan.Reason).
const ( StageNoteDelivered = "delivered" StageNoteQueued = "queued" // StageNoteGone: an ACP seat whose job has ended. A reminder is not worth restarting a // session for, so nothing is sent and nothing is queued. StageNoteGone = "gone" )
Outcomes of DeliverStageNote.
const ( StateNone = "none" StateRunning = "running" StateAwaiting = "awaiting" StateOffline = "offline" StateEnded = "ended" // StateFailed is an ACP seat whose job ended on a failure (failed / timeout / any other // end that is about the work not holding up): the session is gone like StateEnded, but // the roster can show that it did not finish. Terminal sessions never read as failed. StateFailed = "failed" )
The state of the session sitting in a seat.
const CharterBudget = 4000
CharterBudget is how many bytes of a charter reach a session (the view and the injection use the same bound).
const ScheduleOperator = "schedule"
ScheduleOperator is the operator label of a message a seat schedule sends.
const SourceStartup = "startup"
SourceStartup is the SessionStart source of a brand new conversation (the other sources are resume / clear / compact; an agent that reports none sends nothing).
Variables ¶
var ErrSeatArchived = errors.New("seat is archived")
ErrSeatArchived: a schedule targets a seat that has been archived.
Functions ¶
func CharterTemplate ¶
CharterTemplate returns the built-in charter template called name.
func CharterTemplateNames ¶
func CharterTemplateNames() []string
CharterTemplateNames lists the names CharterTemplate accepts, for error messages.
func JoinRootPath ¶
JoinRootPath appends a repository-relative slash path to a root, keeping the root's own separator style (a Windows root stays backslashed).
func Section ¶
func Section(in SectionInput) string
Section renders the seat block of the SessionStart context: the heading with the name and purpose, the charter and — for the first start of a session that has just taken the seat — the continuation text. An empty name renders nothing.
func SplitCharter ¶
SplitCharter tells the two spellings of a seat's charter apart: a value starting with "@" is a repository-relative path to the file that holds it (path comes back without the "@", text is empty), anything else is the text itself.
Types ¶
type ACPRestarter ¶
type ACPRestarter interface {
RestartACP(ctx context.Context, req RestartRequest) (jobID string, err error)
}
ACPRestarter starts the replacement session job and returns its id.
type Agents ¶
type Agents interface {
Get(key string) (config.AgentConfig, bool)
}
Agents resolves an agent definition by key (*agent.Registry satisfies it).
type BindInfo ¶ added in v0.219.0
BindInfo says what a bind did beyond changing the roster row.
The CLI prints it (`gofer seat bind`): CharterSent means the session got the seat's charter as a message right away, CharterError why that message did not go out (the bind itself still succeeded, the next start carries the charter).
type CreateInput ¶
type CreateInput struct {
CallerID string
ProjectKey string
Name string
// RelCwd is the directory of the seat: project-relative, or an absolute path inside one of
// the project's roots (host or container spelling), which is converted.
RelCwd string
Purpose string
Charter string
// CharterBy is jobstore.SeatByUser (default) or "session:<sid>".
CharterBy string
Kind string
Agent string
}
CreateInput is what a new seat needs.
type Deps ¶
type Deps struct {
Projects Projects
Agents Agents
Waiting WaitingLookup
Restarter ACPRestarter
// Messenger delivers a message to a terminal session; Sayer to a live ACP session job.
// Both are only needed by DeliverToSeat (seat schedules).
Messenger Messenger
Sayer Sayer
// Lang is the language of the text injected into a session ("" = the default).
Lang func() i18n.Lang
Now func() time.Time
}
Deps are the collaborators of a Service. Every field is optional: a missing one disables the feature that needs it (no Projects: paths are not checked and open plans have no directory).
type Messenger ¶ added in v0.218.0
type Messenger interface {
SendMessage(ctx context.Context, sid, text, operator, origin string) (jobstore.SessionMessage, error)
}
Messenger sends a message to a terminal session (*sessionrelay.Service satisfies it): the one entry that reaches a running terminal session whatever state it is in. origin is the ceiling owner behind the sender.
type OpenPlan ¶
type OpenPlan struct {
SeatID string
Kind string
// Runner is the machine the sitting session registered on ("" = unknown / vacant): the
// command is typed there.
Runner string
// Cwd is the directory the command is typed in: the sitting session's own reported cwd (the
// path as the machine that runs the session sees it — a container worker reports the container
// spelling), else the seat's directory on the host (project host path + rel_cwd).
Cwd string
// Resumable is true when Sh / PowerShell continue the sitting session.
Resumable bool
// Alive: the sitting terminal session is neither ended nor offline, so resuming it would
// run two copies of one conversation.
Alive bool
// Reason says why not Resumable (the Reason* codes).
Reason string
// Sh / PowerShell are the resume command in each shell (Resumable only).
Sh, PowerShell string
// NewSh / NewPowerShell start a fresh session of the seat's agent in Cwd.
NewSh, NewPowerShell string
// ThreadID is the workbench thread of an ACP seat ("" for a terminal seat or a vacant one).
ThreadID string
// NeedsRestart: the ACP session's job ended and has to be started again; Restarted: it was,
// and JobID is the new job.
NeedsRestart, Restarted bool
JobID string
}
OpenPlan is what a person needs to get back into a seat: where to run what.
type RestartRequest ¶
type RestartRequest struct {
ProjectKey string
Agent string
Runner string
// RelCwd is the project-relative directory.
RelCwd string
SessionID string
FromJobID string
CallerID string
// Prompt is the opening input of the new job.
Prompt string
}
RestartRequest asks the host to start an ACP session job again for a seat whose current job has ended, continuing the conversation SessionID of FromJobID when the agent can load it.
type Sayer ¶ added in v0.218.0
Sayer queues the next prompt of a live ACP session job (*job.Service satisfies it).
type SectionInput ¶
type SectionInput struct {
Name string
Purpose string
Charter string
Continuation string
// StageLine is the stage-flow line of SessionStart (the current step, or the suggestion to
// start a flow), already rendered; it closes the block. Empty adds nothing.
StageLine string
Lang i18n.Lang
}
SectionInput is what a hook knows about the seat a session sits in: the name and purpose, the charter text (already read from its file when the charter is a path) and the one-time continuation text the server handed out with the registration answer.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the seat roster service.
func (*Service) Archive ¶
Archive archives a seat (it frees the name and gives up the sitting session).
func (*Service) Bind ¶
Bind seats ref (a terminal session id or an ACP job id) in the seat. The reference has to exist and belong to the seat's project and caller; a seat that already has another session is jobstore.ErrSeatOccupied unless replace is set.
func (*Service) BindCandidate ¶
BindCandidate binds a terminal session to the candidate seat, replacing a session that ended long ago. It refuses a seat that is not among the session's candidates.
func (*Service) BindInfo ¶ added in v0.219.0
func (s *Service) BindInfo(id, ref string, replace bool, by string) (jobstore.Seat, BindInfo, error)
BindInfo is Bind plus what it did beyond the roster row: an ACP seat whose job is still live gets the seat's charter said into it right away (a job bound while it is running never restarted, so the opening prompt of a restart would never reach it), once per ref.
func (*Service) Candidates ¶
Candidates lists the seats a terminal session could be bound to: seats of the session's own project (and caller) whose directory contains the session's directory, that are vacant or whose session ended more than 7 days ago. A seat whose session is only offline is not a candidate, nor is a seat of another agent kind.
func (*Service) ContinuationText ¶
ContinuationText is what a session sitting in the seat is told when nothing else carries the seat block: what the seat is, its charter, and the most recent work report (or plan handoff) of the seat's project. It is one function so that every path that puts a session into a seat (T4's SessionStart injection, an ACP restart) says the same thing. The text is cut to a budget on a rune boundary.
func (*Service) Create ¶
func (s *Service) Create(in CreateInput) (jobstore.Seat, error)
Create adds a vacant seat.
func (*Service) DeliverStageNote ¶ added in v0.220.0
func (s *Service) DeliverStageNote(ctx context.Context, workItemID, ref, step, text string) (outcome string, handled bool, err error)
DeliverStageNote hands text (already carrying its system prefix) to the session ref when it sits on a seat: handled=false when it sits on none. An offline terminal session's text is queued, replacing an earlier queued reminder of the same work item.
func (*Service) DeliverToSeat ¶ added in v0.218.0
func (s *Service) DeliverToSeat(ctx context.Context, req job.SeatDeliverRequest) (job.SeatDeliverResult, error)
DeliverToSeat implements job.SeatDeliverer: it hands the text of a due schedule to the session that sits in the seat right now. The session is read from the seat at delivery time (never from the schedule), so a seat that was rebound keeps receiving its schedule.
- A terminal session that is online gets the message through the relay's SendMessage.
- An ACP seat whose job lives gets it as a say; one whose job ended is restarted and the text is its opening turn (sent once, inside the restart).
- A vacant seat, or a terminal session that is offline or ended, takes nothing: gofer does not start a terminal for a person. The outcome is jobstore.ScheduleResultOffline, and the text is queued (jobstore.SeatPending) to go out once the seat can take it (FlushPending, and Bind) — see pending.go.
func (*Service) FlushPending ¶ added in v0.219.0
FlushPending sends the queued texts of every seat that can take them now and drops the expired ones. It returns how many texts went out; a failed send stays queued for the next pass.
func (*Service) FlushSeatOf ¶ added in v0.219.0
FlushSeatOf sends what is queued for the seat a session / job sits in, if it can take it now, and does nothing for a ref that sits in no seat or whose queue is empty. It is the immediate late send for a session that just came back (a registration / a beat after offline), so a person whose terminal was away does not wait for the periodic sweep.
The send goes through flushSeat, which claims each row conditionally: two reports for the same session (a SessionStart followed by ticks, the sweep racing this one) never send a text twice, and a report for a seat whose session still cannot take it leaves the row queued.
func (*Service) History ¶
func (s *Service) History(id string) ([]jobstore.SeatBinding, []jobstore.SeatCharterRevision, error)
History returns the binding and charter history of a seat.
func (*Service) OpenPlan ¶
OpenPlan builds the plan for opening a seat. It does NOT reuse the takeover preview of the session relay: that one prepares a gofer-run pty job (global args, takeover preconditions, the server's own path view), while this renders what a person types in their own terminal.
func (*Service) Restart ¶
Restart starts the ended ACP session of an acp seat again, from the original session id, and moves the seat to the new job. It is the only part of opening a seat that has a side effect (it submits a job), so it is separate from OpenPlan, which only reads. A seat that is not an acp seat, is vacant, or whose job still runs is jobstore.ErrSeatInvalid.
func (*Service) SeatsByRefs ¶ added in v0.219.0
SeatsByRefs maps each ref that sits in a seat to that seat, for a whole set of sessions / jobs in one query (the session list asks once instead of once per session). A ref that sits nowhere is absent.
func (*Service) Statuses ¶
Statuses computes the status of every seat for one viewer in a fixed number of queries: the sessions, the jobs, the viewer's thread prefs and the waiting lookup are each read once for the whole set.
func (*Service) TakeContinuationNotice ¶
func (s *Service) TakeContinuationNotice(ref, source string, lang i18n.Lang) (text string, ok bool, err error)
TakeContinuationNotice hands the continuation text to the session that has just taken its seat and marks it delivered for that ref in the same step: ok is false when the session sits in no seat or was already told (its second SessionStart). Only a write path (the session registration) may call it; the read views leave the notice owed.
source is the SessionStart source the agent reported (startup|resume|clear|compact, "" when it reports none): only a startup session is told that the earlier conversation is missing.
type Status ¶
type Status struct {
Seat jobstore.Seat
// State is the sitting session's state: none / running / awaiting / offline / ended / failed.
State string
// Waiting is the category WaitingLookup gave when the session is waiting for the viewer
// ("" = not waiting).
Waiting string
// Unread is true when the session was active after the viewer last looked at its thread.
Unread bool
// ActivityAt is the sitting session's last activity (unix seconds, 0 = none).
ActivityAt int64
// ThreadID is the workbench thread of the sitting session ("" = vacant).
ThreadID string
}
Status is a seat with what is derived from the session sitting in it.
type WaitingLookup ¶
type WaitingLookup interface {
WaitingSubjects(caller string, refs []string) (map[string]string, error)
}
WaitingLookup answers which of a caller's sessions are waiting for that caller. refs use the seat convention: a terminal session is its session id, an ACP session is its job id. The result maps each waiting ref to its category (a non-empty string); a ref that is not waiting is absent.