Documentation
¶
Overview ¶
Package team is the business layer of the Team entity (design docs/design/2026-11-18-resident-sessions-and-team-design.md §7, plan docs/plans/2026-11-26-team-plan.md): a team is one leader seat plus member seats of one project. The rows live in jobstore (teams / team_members / team_routes / team_evals); this package adds validation, seat-name resolution, the roster (members joined with their seat status) and the route / eval record writers.
The routing engine and the leader protocol are not here: they build on this package. It imports neither httpapi nor commands (G022).
Index ¶
- Constants
- Variables
- type AttentionFact
- type ChainEnd
- type CreateInput
- type Decision
- type Deps
- type Failure
- type Input
- type Party
- type Protocol
- func (p *Protocol) BeginTurn(lang i18n.Lang, ref string, human bool) string
- func (p *Protocol) CheckSend(origin Party) error
- func (p *Protocol) EndTurn(ref string) bool
- func (p *Protocol) IsLeader(o Party) (jobstore.Team, bool, error)
- func (p *Protocol) NoteSent(origin Party)
- func (p *Protocol) OnChainEnd(f func(ChainEnd) error)
- func (p *Protocol) PeekNote(lang i18n.Lang, ids ...string) string
- func (p *Protocol) RecordEval(origin Party, outcome, reason string) (jobstore.TeamEval, error)
- func (p *Protocol) SetBoundary(f func() string)
- func (p *Protocol) SetClock(f func() time.Time)
- func (p *Protocol) TurnEnded(ids ...string)
- func (p *Protocol) TurnNote(lang i18n.Lang, ids ...string) string
- type Roster
- type RosterEntry
- type Router
- type Service
- func (s *Service) AddMember(teamID, seatRef string) (jobstore.Seat, error)
- func (s *Service) Archive(id string) (jobstore.Team, error)
- func (s *Service) Attention(allow func(project string) bool) ([]AttentionFact, error)
- func (s *Service) ByName(projectKey, name string) (jobstore.Team, error)
- func (s *Service) Create(in CreateInput) (jobstore.Team, error)
- func (s *Service) Evals(teamID string, limit int) ([]jobstore.TeamEval, error)
- func (s *Service) Find(projectKey, ref string) (jobstore.Team, error)
- func (s *Service) Get(id string) (jobstore.Team, error)
- func (s *Service) List(f jobstore.TeamFilter) ([]jobstore.Team, error)
- func (s *Service) RecordEval(e jobstore.TeamEval) (jobstore.TeamEval, error)
- func (s *Service) RecordRoute(r jobstore.TeamRoute) (jobstore.TeamRoute, error)
- func (s *Service) RemoveMember(teamID, seatRef string) (bool, error)
- func (s *Service) Roster(viewer, teamID string) (Roster, error)
- func (s *Service) Routes(teamID string, limit int) ([]jobstore.TeamRoute, error)
- func (s *Service) SeatRef(callerID, projectKey, ref string) (jobstore.Seat, error)
- func (s *Service) SetBrief(id, brief string) (jobstore.Team, error)
- func (s *Service) SetLeader(id, seatRef string) (jobstore.Team, error)
- func (s *Service) TeamOfSeat(seatID string) (jobstore.Team, bool, error)
- func (s *Service) Update(id string, in UpdateInput) (jobstore.Team, error)
- type StageBriefer
- type UpdateInput
Constants ¶
const ( // RuleSelf: the leader wrote to the team or to itself — recorded, never delivered (1). RuleSelf = "self" // RuleHumanNamed / RuleHumanDefault: a human (or anyone outside the team) wrote to the // team; `@member` in the body picks the members, else the leader gets it (2). RuleHumanNamed = "human_named" RuleHumanDefault = "human_default" // RuleMemberResult: a member's result letter goes to the leader (3). RuleMemberResult = "member_result" // RuleRelay: a member names another member (4); over the loop guard it is handed to the // leader instead (outcome handed_to_leader). RuleRelay = "relay" // RuleLeaderDispatch: the leader writes to a member; it only breaks relay runs. RuleLeaderDispatch = "leader_dispatch" // RulePeerLeader: the leader of another team wrote; only this team's leader gets it (10). RulePeerLeader = "peer_leader" // RuleMemberFailed: the system letter a failed member job sends the leader (9). RuleMemberFailed = "member_failed" // RuleChainEnd: the system letter that puts a finished chain's last result in front of the // team creator (leader protocol, plan §2.4). RuleChainEnd = "chain_end" // RuleOutbound: a team seat wrote to somebody outside the team; recorded so the ledger // run is broken. RuleOutbound = "outbound" // RuleDirect: somebody outside the team addressed a member seat by name; delivered as // addressed. RuleDirect = "direct" )
Rule names (team_routes.rule).
const ( SystemMemberFailed = "member_failed" SystemChainEnd = "chain_end" )
SystemMemberFailed is mail.system_kind of the letter a failed member job produces; SystemChainEnd that of the letter a chain end produces.
const ( RoleLeader = "leader" RoleMember = jobstore.TeamRoleMember )
Role of a roster row.
const AttentionMissingEval = "missing_eval"
Fact kinds.
const MissingEvalLimit = 3
MissingEvalLimit is how many consecutive turns without an evaluation raise the 「等我」 card.
Variables ¶
var ( // ErrNotLeader: the caller is not the session / job sitting in the leader seat of a team. ErrNotLeader = errors.New("team: only the session or job sitting in a team's leader seat may do this") // ErrIdleTurn: the leader already recorded idle in this turn, so it may not send a team // letter (or evaluate again) before the turn ends. ErrIdleTurn = errors.New("team: this turn already recorded idle, so no team letter may be sent in it; a new turn starts when the next message or letter wakes you") )
Functions ¶
This section is empty.
Types ¶
type AttentionFact ¶
type AttentionFact struct {
TeamID string
Name string
ProjectKey string
Kind string
// Since is when the newest missing_eval was written.
Since int64
}
AttentionFact is a team that needs a person: its leader missed MissingEvalLimit evaluations in a row. It is derived from the stored evaluations on every read, so it goes away by itself when the leader records a real one (or the team is archived).
type ChainEnd ¶
type ChainEnd struct {
Team jobstore.Team
Leader jobstore.Seat
// Member is the name of the member whose result it was ("" = unknown).
Member string
// Trigger is the result letter that woke the leader (the newest one when several did).
Trigger jobstore.Mail
TurnRef string
}
ChainEnd is the fact "a leader turn woken by a member result ended with nothing sent, nothing dispatched and no wakeup left": the result that started it must reach a person.
type CreateInput ¶
type CreateInput struct {
CallerID string
ProjectKey string
Name string
// Leader is the leader seat; Members the initial member seats.
Leader string
Members []string
Brief string
// RelayMode is leader (default) or direct.
RelayMode string
RelayRoundLimit *int
RelayDailyLimit *int
MergeWindowSec *int
}
CreateInput is what a new team needs. Seat references are a seat id or a seat name of the caller in the project. A nil limit takes the default.
type Decision ¶
type Decision struct {
Applies bool
// Team is the team whose ledger records the decision (the recipient's, or the sender's
// for an outbound letter); Ledgers lists every ledger to write (a peer letter lands in
// both leaders' teams).
Team jobstore.Team
Ledgers []jobstore.Team
Rule string
// FromRef is who the ledger says sent it.
FromRef string
// Recipients are the seats to deliver to; empty keeps the address's own recipient.
Recipients []jobstore.Seat
// Handed: the loop guard redirected the letter to the leader (outcome handed_to_leader).
Handed bool
// Drop: record only, deliver nothing (rule self).
Drop bool
// SenderLeader: the sender is, right now, the session / job sitting in the leader seat of
// the team that sends (the leader protocol's eval binding keys on it).
SenderLeader bool
// Hold is set when the letter must be parked instead of delivered (a peer pair over the
// loop limit: there is nobody to redirect to but the leader that is already the target).
Hold string
// Hop is the hop the letter carries; Tag the source line to prefix to its body ("" none).
Hop int
Tag string
// Note tells the recipient why it got a letter it was not addressed with (a redirect).
Note string
// contains filtered or unexported fields
}
Decision is what the engine decided. Applies=false means the letter is not a team matter and goes through the mailbox exactly as before.
type Deps ¶
type Deps struct {
Seats *seat.Service
StageBrief StageBriefer
}
Deps are the collaborators of a Service. Seats is required for the roster; StageBrief is optional (no flow information in the roster without it).
type Input ¶
type Input struct {
Origin Party
// ToRaw is the address as written ("" = none: the sender's own box).
ToRaw string
// ViaTeamAddr says the address was `team:` (the letter was addressed to the team itself).
ViaTeamAddr bool
// TeamID is the team the address resolved through (team: or the seat: of a team seat).
TeamID string
// Target* is the resolved recipient: the session / job (empty when the seat is vacant) and
// the seat it sits in when the address named one.
TargetKind, TargetID, TargetSeatID string
Body string
// ReplyHop is the hop of the letter this one answers (0 = none).
ReplyHop int
// SourceMailID is the letter this one forwards or answers (0 = none); with IdemKey it
// forms the route key.
SourceMailID int64
// IdemKey is an idempotency key the sender (or the server for a job) supplied.
IdemKey string
Now time.Time
}
Input is one letter about to be stored.
type Party ¶
type Party struct {
// Kind is jobstore.MailKindSession / MailKindJob / MailKindCaller / MailKindGofer.
Kind string
ID string
Caller string
}
Party is a sender as the entry layer vouched for it.
type Protocol ¶
type Protocol struct {
// contains filtered or unexported fields
}
Protocol is the leader protocol engine. The zero value is unusable; build it with NewProtocol.
func NewProtocol ¶
NewProtocol builds the engine over the store, the team service (for the roster) and the router (for leader identity).
func (*Protocol) BeginTurn ¶
BeginTurn opens a turn for ref when it sits in a leader seat and returns the injection text; "" when it does not. human says a person typed the prompt that starts the turn.
func (*Protocol) CheckSend ¶
CheckSend refuses a team letter from the leader in a turn that already recorded idle.
func (*Protocol) IsLeader ¶
IsLeader reports whether ref (a job or session id) sits in a leader seat right now.
func (*Protocol) OnChainEnd ¶
OnChainEnd installs the sink that puts a chain end in front of a person (the mailbox writes the creator a letter).
func (*Protocol) PeekNote ¶
PeekNote is TurnNote without opening a turn: the block of a say that is sent again.
func (*Protocol) RecordEval ¶
RecordEval records the leader's evaluation of its turn. Only the session / job sitting in a leader seat may (rule 8); once a turn recorded idle it is final.
func (*Protocol) SetBoundary ¶
SetBoundary replaces the random boundary tag generator (tests).
func (*Protocol) TurnNote ¶
TurnNote starts a turn of the leader known by the first of ids that sits in a leader seat and returns the text to put in front of it: "" when none of them does (no team ⇒ no change). ids are the names a resident session is known by (its job id, the agent's own session id); the first one is the turn's key.
type Roster ¶
type Roster struct {
Team jobstore.Team
Entries []RosterEntry
}
Roster is a team with its leader and members, leader first.
type RosterEntry ¶
type RosterEntry struct {
Role string
Status seat.Status
// Stage is where the flow of the sitting session stands (nil: none, or not wired).
Stage *stagenote.Brief
}
RosterEntry is one seat of a team with what is derived from the session sitting in it.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router decides routes over the metadata store.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the team service.
func (*Service) Attention ¶
func (s *Service) Attention(allow func(project string) bool) ([]AttentionFact, error)
Attention lists the active teams whose newest MissingEvalLimit evaluations are all missing_eval. allow narrows by project (nil = every project).
func (*Service) Create ¶
func (s *Service) Create(in CreateInput) (jobstore.Team, error)
Create adds a team with its leader and initial members.
func (*Service) Find ¶
Find reads a team by id, or — when ref is not an id — by name inside project.
func (*Service) RecordEval ¶
RecordEval appends one leader evaluation.
func (*Service) RecordRoute ¶
RecordRoute appends one routing decision. It is the writer the routing engine calls.
func (*Service) RemoveMember ¶
RemoveMember removes a member seat (id or name); the seat itself is untouched. It reports whether the seat was a member.
func (*Service) Roster ¶
Roster reads the roster of a team for one viewer (the viewer decides "waiting" and "unread"). It costs a fixed number of queries plus one stage lookup per seated member.
func (*Service) SeatRef ¶
SeatRef resolves a seat reference (id, or name inside the project of the caller) to a seat.
func (*Service) TeamOfSeat ¶
TeamOfSeat returns the active team a seat belongs to (ok=false: none).
type StageBriefer ¶
StageBriefer returns where the flow of the work item the session `ref` is on stands, or nil (it must read stored rows only: the roster is built per request).