team

package
v0.220.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 16 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 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

View Source
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).

View Source
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.

View Source
const (
	RoleLeader = "leader"
	RoleMember = jobstore.TeamRoleMember
)

Role of a roster row.

View Source
const AttentionMissingEval = "missing_eval"

Fact kinds.

View Source
const MissingEvalLimit = 3

MissingEvalLimit is how many consecutive turns without an evaluation raise the 「等我」 card.

Variables

View Source
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.

func (Decision) KeyFor

func (d Decision) KeyFor(seatID string) string

KeyFor is the route key of the letter to one recipient seat ("" = the letter has no source identity to dedupe on).

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 Failure

type Failure struct {
	Team   jobstore.Team
	Member jobstore.Seat
	Leader jobstore.Seat
}

Failure is a failed member job and the team around 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

func NewProtocol(store *jobstore.Store, svc *Service, router *Router) *Protocol

NewProtocol builds the engine over the store, the team service (for the roster) and the router (for leader identity).

func (*Protocol) BeginTurn

func (p *Protocol) BeginTurn(lang i18n.Lang, ref string, human bool) string

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

func (p *Protocol) CheckSend(origin Party) error

CheckSend refuses a team letter from the leader in a turn that already recorded idle.

func (*Protocol) EndTurn

func (p *Protocol) EndTurn(ref string) bool

EndTurn closes the open turn of ref (false: it had none).

func (*Protocol) IsLeader

func (p *Protocol) IsLeader(o Party) (jobstore.Team, bool, error)

IsLeader reports whether ref (a job or session id) sits in a leader seat right now.

func (*Protocol) NoteSent

func (p *Protocol) NoteSent(origin Party)

NoteSent records that the leader sent a team letter in its open turn.

func (*Protocol) OnChainEnd

func (p *Protocol) OnChainEnd(f func(ChainEnd) error)

OnChainEnd installs the sink that puts a chain end in front of a person (the mailbox writes the creator a letter).

func (*Protocol) PeekNote

func (p *Protocol) PeekNote(lang i18n.Lang, ids ...string) string

PeekNote is TurnNote without opening a turn: the block of a say that is sent again.

func (*Protocol) RecordEval

func (p *Protocol) RecordEval(origin Party, outcome, reason string) (jobstore.TeamEval, error)

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

func (p *Protocol) SetBoundary(f func() string)

SetBoundary replaces the random boundary tag generator (tests).

func (*Protocol) SetClock

func (p *Protocol) SetClock(f func() time.Time)

SetClock replaces the clock (tests).

func (*Protocol) TurnEnded

func (p *Protocol) TurnEnded(ids ...string)

TurnEnded ends the open turn of the first of ids that has one.

func (*Protocol) TurnNote

func (p *Protocol) TurnNote(lang i18n.Lang, ids ...string) string

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.

func NewRouter

func NewRouter(store *jobstore.Store) *Router

NewRouter builds the routing engine.

func (*Router) Decide

func (r *Router) Decide(in Input) (Decision, error)

Decide applies the ten rules (plan §2.3) in order. See the package comment.

func (*Router) IsLeader

func (r *Router) IsLeader(o Party) (jobstore.Team, bool, error)

IsLeader reports whether the origin is, right now, the session / job sitting in the leader seat of an active team, and returns that team. It is the one judgement every leader-only privilege uses (rule 8): it reads the seat table, never a letter.

func (*Router) MemberFailure

func (r *Router) MemberFailure(jobID string) (Failure, bool, error)

MemberFailure says whether a job is the one sitting in a member seat of an active team (rule 9). The leader's own jobs are not covered: a leader that fails has nobody above it to tell.

type Service

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

Service is the team service.

func New

func New(store *jobstore.Store, d Deps) *Service

New builds a Service over the metadata store.

func (*Service) AddMember

func (s *Service) AddMember(teamID, seatRef string) (jobstore.Seat, error)

AddMember adds a seat (id or name) as a member.

func (*Service) Archive

func (s *Service) Archive(id string) (jobstore.Team, error)

Archive archives a team (idempotent): it frees the name and its seats.

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) ByName

func (s *Service) ByName(projectKey, name string) (jobstore.Team, error)

ByName reads the active team of a project by name.

func (*Service) Create

func (s *Service) Create(in CreateInput) (jobstore.Team, error)

Create adds a team with its leader and initial members.

func (*Service) Evals

func (s *Service) Evals(teamID string, limit int) ([]jobstore.TeamEval, error)

Evals lists a team's evaluations, newest first.

func (*Service) Find

func (s *Service) Find(projectKey, ref string) (jobstore.Team, error)

Find reads a team by id, or — when ref is not an id — by name inside project.

func (*Service) Get

func (s *Service) Get(id string) (jobstore.Team, error)

Get reads a team by id.

func (*Service) List

func (s *Service) List(f jobstore.TeamFilter) ([]jobstore.Team, error)

List lists teams.

func (*Service) RecordEval

func (s *Service) RecordEval(e jobstore.TeamEval) (jobstore.TeamEval, error)

RecordEval appends one leader evaluation.

func (*Service) RecordRoute

func (s *Service) RecordRoute(r jobstore.TeamRoute) (jobstore.TeamRoute, error)

RecordRoute appends one routing decision. It is the writer the routing engine calls.

func (*Service) RemoveMember

func (s *Service) RemoveMember(teamID, seatRef string) (bool, error)

RemoveMember removes a member seat (id or name); the seat itself is untouched. It reports whether the seat was a member.

func (*Service) Roster

func (s *Service) Roster(viewer, teamID string) (Roster, error)

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) Routes

func (s *Service) Routes(teamID string, limit int) ([]jobstore.TeamRoute, error)

Routes lists a team's routing decisions, newest first.

func (*Service) SeatRef

func (s *Service) SeatRef(callerID, projectKey, ref string) (jobstore.Seat, error)

SeatRef resolves a seat reference (id, or name inside the project of the caller) to a seat.

func (*Service) SetBrief

func (s *Service) SetBrief(id, brief string) (jobstore.Team, error)

SetBrief replaces the team description.

func (*Service) SetLeader

func (s *Service) SetLeader(id, seatRef string) (jobstore.Team, error)

SetLeader makes the seat (id or name) the leader.

func (*Service) TeamOfSeat

func (s *Service) TeamOfSeat(seatID string) (jobstore.Team, bool, error)

TeamOfSeat returns the active team a seat belongs to (ok=false: none).

func (*Service) Update

func (s *Service) Update(id string, in UpdateInput) (jobstore.Team, error)

Update patches a team (name, leader, brief, relay limits, merge window).

type StageBriefer

type StageBriefer func(ref string) *stagenote.Brief

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).

type UpdateInput

type UpdateInput struct {
	Name            *string
	Leader          *string
	Brief           *string
	RelayMode       *string
	RelayRoundLimit *int
	RelayDailyLimit *int
	MergeWindowSec  *int
}

UpdateInput is a partial update; nil / empty fields are left alone. Leader is a seat reference.

Jump to

Keyboard shortcuts

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