Documentation
¶
Overview ¶
Package humanapi is the broker's human listener, :8080, reached only through oauth2-proxy (§3): the UI, the room list, and one WebSocket per open room. Every API and WebSocket request is authenticated and admitted by group first; a room's reads then go through admits (D7: the caller can read the room's repository on GitHub) and policy.Allowed. The UI's static files are not: oauth2-proxy fronts the listener. Live events come from the fan-out hub.
Index ¶
- Constants
- type ActLog
- type Action
- type Actor
- type Authenticator
- type Dashboard
- type Hub
- type Intake
- type Log
- type Redactor
- type Runs
- type Server
- type SlackDecideStore
- type SlackDecider
- type SlackDecision
- type SlackLinkFinder
- type SlackLinkStore
- type SlackLinker
- type SponsoredAuthenticator
- type TaskCreator
Constants ¶
const ( ViaWeb = "web" ViaRoomctl = "roomctl" ViaMCP = "mcp" )
The clients a human's act comes through (factory interfaces F8). Only the web UI's standing may steer and decide (ruling P18), and only its text is stored as typed: a local agent can drive maku and the MCP server on its human's token.
const ForkedFrom = roomctrl.ForkedFrom
ForkedFrom annotates a forked Room with <source room>@<seq>; roomctrl owns it, since the Room's task status must skip the copied prefix.
const SlackLinkTTL = 10 * time.Minute
SlackLinkTTL is how long a code may be confirmed.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActLog ¶
type ActLog interface {
Room(ctx context.Context, id string) (store.RoomState, error)
Append(ctx context.Context, d envelope.Draft) (envelope.Event, bool, error)
AppendAsDriver(ctx context.Context, driver string, epoch int64, d envelope.Draft) (envelope.Event, bool, error)
Enqueue(ctx context.Context, d envelope.Draft, author, text string) (envelope.Event, error)
PromoteQueued(ctx context.Context, roomID string, ref int64, driver string, epoch int64, runID string, d envelope.Draft) (envelope.Event, error)
RemoveQueued(ctx context.Context, roomID string, ref int64, d envelope.Draft) (envelope.Event, error)
ChangeDriver(ctx context.Context, roomID string, expect int64, to, reason string, d envelope.Draft) (envelope.Event, bool, error)
DriverSeen(ctx context.Context, roomID, principal string, acted bool) error
CloseRoom(ctx context.Context, roomID, reason string) error
// start_run checks for a pending run, reads the brief's sources, then records
// the run with what it consumed.
PendingRuns(ctx context.Context, roomID string, within time.Duration) ([]string, error)
BriefSources(ctx context.Context, roomID string) ([]envelope.Event, error)
Queue(ctx context.Context, roomID string) ([]store.Queued, error)
Stored(ctx context.Context, d envelope.Draft) (envelope.Event, bool, error)
RecordRunRequest(ctx context.Context, d envelope.Draft, runID string, refs []int64, fields map[string]any) (envelope.Event, error)
// decide reads the approval, then records the first valid decision (phase 5).
Approval(ctx context.Context, id string) (store.Approval, error)
Decide(ctx context.Context, approvalID, decision, by, reason string, d envelope.Draft) (envelope.Event, store.Approval, error)
// fork reads the commit at its seq, then copies the prefix (phase 6); a
// forked room's start_run reads its forked_from for the brief.
BriefSourcesThrough(ctx context.Context, roomID string, seq int64) ([]envelope.Event, error)
Fork(ctx context.Context, src string, upTo int64, r store.NewRoom, d envelope.Draft, fields map[string]any) (envelope.Event, error)
Range(ctx context.Context, roomID string, afterSeq int64, limit int) ([]envelope.Event, error)
}
ActLog is the part of the store the actions write; *store.Store implements it.
type Action ¶
type Action struct {
Kind string `json:"kind"`
Text string `json:"text,omitempty"`
Delivery string `json:"delivery,omitempty"`
Ref int64 `json:"ref,omitempty"`
To string `json:"to,omitempty"`
Reason string `json:"reason,omitempty"`
Role string `json:"role,omitempty"`
PRURL string `json:"prUrl,omitempty"`
EgressProfiles []string `json:"egressProfiles,omitempty"`
Principal string `json:"principal,omitempty"` // invite
MemberRole string `json:"memberRole,omitempty"` // invite
Approver bool `json:"approver,omitempty"` // invite
ApprovalID string `json:"approvalId,omitempty"` // decide
Decision string `json:"decision,omitempty"` // decide: approved | denied
Seq int64 `json:"seq,omitempty"` // fork: the last event copied
Note string `json:"note,omitempty"` // fork
Approvals string `json:"approvals,omitempty"` // fork: attended (the default) | unattended
}
Action is an act frame's action (docs/api.md, Actions).
type Actor ¶
type Actor struct {
Log ActLog
Groups policy.Groups
Runs Runs
Redactor Redactor
Rooms client.Client
Requester runrequest.Requester
OnReject func(ctx context.Context, reason string)
// OnDecided observes a human decision's wait since its request
// (rooms_approval_decision_seconds).
OnDecided func(time.Duration)
// Now is the clock OnDecided's wait is measured on; nil means time.Now. Server.Routes
// hands it the Server's own when this one is unset.
Now func() time.Time
// Logger records one line per act, accepted or refused (nil: none).
Logger *slog.Logger
// contains filtered or unexported fields
}
Actor serves humans' act frames: every write a human makes to a room. Log, Groups, Runs and Redactor are required; Rooms is required for invite and new rooms, Requester for start_run.
func (*Actor) Handle ¶
func (a *Actor) Handle(ctx context.Context, p authn.Principal, webUI bool, session string, room *v1alpha1.Room, f wire.ClientFrame) wire.ServerFrame
Handle serves one act frame of p in room, through the web UI or maku (ruling P18), on the connection session, and returns its ack.
func (*Actor) HandleVia ¶
func (a *Actor) HandleVia(ctx context.Context, p authn.Principal, via, session string, room *v1alpha1.Room, f wire.ClientFrame) (out wire.ServerFrame)
HandleVia is Handle for an act that came through via: ViaWeb, ViaRoomctl or ViaMCP. Only the web UI's standing may steer and decide (P18), and only its text is stored as typed (F8).
type Authenticator ¶
Authenticator maps a request to a human principal; *authn.Humans implements it, Origin check included. authn.ErrForbidden means a foreign Origin.
type Dashboard ¶
Dashboard is one link template the room page fills with a room's ids (human.dashboards): {room}, {run} and {task}, each URL-encoded, and a link whose value is missing hidden.
type Hub ¶
type Hub interface {
Subscribe(ctx context.Context, roomID string) (*fanout.Sub, error)
Unsubscribe(*fanout.Sub)
}
Hub is the fan-out hub's subscription side; *fanout.Hub implements it.
type Intake ¶ added in v0.35.0
type Intake struct {
Classes map[string]intake.Class
Allow map[string]bool
Model *intake.Model
// Public answers whether GitHub reports a repository public: the guard's public-only read.
Public intake.Publicity
// Links resolves a Slack user to the account it is linked to. Nil refuses every sponsored plan.
Links SlackLinkFinder
// Daily is the per-requester cap in a UTC day. Below one, no plan is made: a floor of zero would
// otherwise read as "no cap", which is the opposite of what an operator typed.
Daily int
// Fallback is the config's fallback: `off` leaves the degraded composer unreachable, `composer`
// makes it the answer when the call fails rather than a plan.
Fallback string
// Now is the clock the daily cap and the plan's composition read; nil means time.Now.
Now func() time.Time
// contains filtered or unexported fields
}
Intake is the planner as the broker serves it (human.intake.plan): the class table and the allowlist from config, the one bounded model call, the visibility read the public-only guard asks, the link tables a sponsored plan resolves its requester through, the daily cap, the degraded composer's switch and the clock. Nil on the server means the switch is off: neither tool exists on any list, so the list a deployment sees is the list it has.
It carries no channel ceiling: a channel is the caller's to state (the Slack App passes its channel's maxCostUSD as the tool's ceiling argument, as it passes max_cost to run_create), and Compose takes the lower of it and the class's.
type Log ¶
type Log interface {
Range(ctx context.Context, roomID string, afterSeq int64, limit int) ([]envelope.Event, error)
Room(ctx context.Context, id string) (store.RoomState, error)
// Queue is the room's still-queued messages, for the state frame: a page's tail
// of events rarely reaches back to them (review 4.5 I1).
Queue(ctx context.Context, roomID string) ([]store.Queued, error)
// OpenApprovals is the room's pending approvals, for the state frame, likewise.
OpenApprovals(ctx context.Context, roomID string) ([]store.Approval, error)
// LastTaskState is the room's last task facts above seq after, for the room list's hold
// need (#78): its wait reason is not projected into the Room status.
LastTaskState(ctx context.Context, roomID string, after int64) (json.RawMessage, error)
// TaskStateAt is the task facts as they stood at seq upTo, above after: room_changes' baseline.
TaskStateAt(ctx context.Context, roomID string, after, upTo int64) (json.RawMessage, error)
// TaskReasons is the reason code of each room's last task facts above its bound, in one
// read: the room list's failed rows say why they failed.
TaskReasons(ctx context.Context, after map[string]int64) (map[string]string, error)
// LastEventAt is when each listed room's log last moved, for the room list.
LastEventAt(ctx context.Context, roomIDs []string) (map[string]time.Time, error)
}
Log is the part of the store the API reads.
type Redactor ¶
type Redactor interface {
Payload(ctx context.Context, raw json.RawMessage) (json.RawMessage, []string, error)
}
Redactor removes secrets from a JSON payload before it is appended (§4); *redact.Redactor implements it.
type Server ¶
type Server struct {
// Sponsored authenticates a sponsored principal's bearer on /mcp (factory interfaces F4, R13);
// nil while human.mcp.sponsored is empty, and then every sponsored token is refused.
Sponsored SponsoredAuthenticator
// Tasks is run_create's factory; nil answers no_factory.
Tasks TaskCreator
Humans Authenticator
Groups policy.Groups
// HumanMode is the human listener's mode ("oidc", "local"), which maku's discovery reports so
// `configure --url` knows whether an IdP and a token are needed. Empty reads as OIDC: the
// deployment every broker before local mode carried.
HumanMode string
// Origins are the origins requests may come from, set in local mode alone (authn.LoopbackOrigins
// of publicURL): there is no token there, so an every-route check on Origin is the only CSRF
// gate, and it covers the public and static routes too. Nil installs no such gate; an OIDC
// install relies on its authenticator's own Origin check, which every authenticated route calls.
Origins []string
// WebClient is the web UI's client id, read at use (Ruling AS-a): a session
// through it is the web UI, which may steer and decide (ruling P18).
WebClient func() string
// PublicURL, Issuer, RoomctlClient and ProjectID are what `maku
// configure` needs (GET /api/roomctl); the ids are read at use like WebClient.
PublicURL string
Issuer string
RoomctlClient func() string
ProjectID func() string
Rooms client.Reader
// FactoryPrincipal is the system principal whose task facts name a closed room's repository,
// once the factory has deleted its Room; "" leaves a closed room unreadable.
FactoryPrincipal string
Namespace string
Log Log
Hub Hub
Runs Runs
Metrics *metrics.Set
UI fs.FS // Task 2.5; nil serves 404
Actor *Actor // serves act frames (phase 4); nil refuses every one
// Identity and Access are D7's GitHub check: who the caller is on GitHub, and
// whether they may read a room's repository. Either nil shows rooms to admins only.
// SessionStart holds the repositories, lowercased owner/name, whose issue_draft says canStart
// (human.mcp.sessionStart). Empty: none does.
SessionStart map[string]bool
Identity *ghidentity.Resolver
Access *repoaccess.Checker
Logger *slog.Logger
// Dashboards are the room page's link templates (human.dashboards), served on GET
// /api/roomctl; none shows no group.
Dashboards []Dashboard
// MCP serves POST /mcp, the MCP server maku mcp relays (human.mcp.enabled). Off, /mcp is a 404.
MCP bool
// Needs serves GET /api/needs, needs/v1's human door (CD28; human.needs.enabled, on unless a file
// turns it off). Off, /api/needs is a 404 and the App's own door is needs_list on /mcp.
Needs bool
// SlackLink is the Slack self-serve link (human.slackLink): its two tools for the Slack App and
// the /link/slack page. Nil serves neither.
SlackLink *SlackLinker
// SlackDecide is human.slackDecide: the App's one route that records a decision, for forge.push
// only (v3.x Slack push approval D2, D13). Nil serves nothing: the path is the mux's 404.
SlackDecide *SlackDecider
// Intake is the governed planner (human.intake.plan). Nil is the switch off: neither intake_plan
// nor plan_check exists on any /mcp list, so the list a deployment sees is the list it has.
Intake *Intake
// Connection bounds; zero takes the default.
HelloWait time.Duration // the first frame must arrive within it (10 s)
WriteWait time.Duration // one frame to the socket (10 s)
PingEvery time.Duration // the keep-alive period (30 s)
PongWait time.Duration // a ping's pong must arrive within it (10 s)
// MaxLifetime caps a connection below its token's expiry (1 h): ZITADEL's
// tokens live 12 h by default, and this bounds a revoked member's socket.
MaxLifetime time.Duration
// Now is the clock the token-expiry check and the summary read, and the session
// lifetime is computed from it (min of the token's remaining life and MaxLifetime) before
// being handed to Timer; nil means time.Now.
// Deadlines handed to the runtime (the route's write deadline, a context's) stay on
// its own clock: a fake one there would expire a request before it starts, or never.
Now func() time.Time
// Timer starts the lifetime cap and each ping's wait: it returns the channel that
// fires after d and a stop. Nil means time.NewTimer; tests step their own.
Timer func(d time.Duration) (fired <-chan time.Time, stop func() bool)
// contains filtered or unexported fields
}
Server is the :8080 API. Humans, Groups, WebClient, Rooms, Namespace, Log, Hub and Runs are required; the rest is optional.
type SlackDecideStore ¶ added in v0.35.0
type SlackDecideStore interface {
SlackLink(ctx context.Context, team, user string) (sub string, found bool, err error)
Approval(ctx context.Context, id string) (store.Approval, error)
Decide(ctx context.Context, approvalID, decision, by, reason string, d envelope.Draft) (envelope.Event, store.Approval, error)
Room(ctx context.Context, id string) (store.RoomState, error)
}
SlackDecideStore is the part of the store the route reads and writes; *store.Store has it.
type SlackDecider ¶ added in v0.35.0
type SlackDecider struct {
Store SlackDecideStore
Principal string // "system:slack-app"
TeamID string
Rooms client.Reader
Namespace string
Groups policy.Groups
Identity *ghidentity.Resolver
Access *repoaccess.Checker
Runs Runs
Metrics *metrics.Set
OnDecided func(time.Duration)
Logger *slog.Logger
// contains filtered or unexported fields
}
SlackDecider is human.slackDecide: who may call, for which workspace, and the readings standing is resolved from. Groups is left zero on purpose (D15): the broker holds no token for the linked human, so standing is exactly the Room CR's, and an agents-admin who is neither the room's owner nor one of its approvers is refused here and decides on the room page.
type SlackDecision ¶ added in v0.35.0
type SlackDecision struct {
Team string `json:"team"`
User string `json:"user"`
Channel string `json:"channel"`
MessageTS string `json:"messageTS"`
ApprovalID string `json:"approvalId"`
Branch string `json:"branch"`
Decision string `json:"decision"`
}
SlackDecision is §1's body. Every field is checked against its shape before any read.
type SlackLinkFinder ¶ added in v0.35.0
type SlackLinkFinder interface {
SlackLink(ctx context.Context, team, user string) (sub string, found bool, err error)
}
SlackLinkFinder is the part of the store a sponsored plan resolves its requester through: the ZITADEL account a Slack user is linked to. *store.Store has it; nil refuses every sponsored plan as not_linked, which is the one reason that sends the person somewhere they can act.
type SlackLinkStore ¶
type SlackLinkStore interface {
MintSlackCode(ctx context.Context, codeSHA256 []byte, c store.SlackCode, now time.Time) error
SlackCode(ctx context.Context, codeSHA256 []byte, now time.Time) (store.SlackCode, error)
LinkSlack(ctx context.Context, codeSHA256 []byte, team, sub string, now time.Time) (store.SlackCode, error)
SlackLinksOf(ctx context.Context, sub string) ([]store.SlackLink, error)
UnlinkSlack(ctx context.Context, team, user, sub string) (bool, error)
}
SlackLinkStore is the part of the store the link reads and writes; *store.Store has it.
type SlackLinker ¶
type SlackLinker struct {
Store SlackLinkStore
Principal string
TeamID string
Repository string
Rand io.Reader // nil: crypto/rand
}
SlackLinker is human.slackLink: who may mint codes (the Slack App's sponsored principal, system:<name>), for which workspace, and the repository whose installation names a login.
type SponsoredAuthenticator ¶
type SponsoredAuthenticator interface {
Authenticate(ctx context.Context, raw string) (authn.Principal, error)
}
SponsoredAuthenticator maps a bearer to its sponsored principal; *authn.Sponsored is the broker's.
type TaskCreator ¶
type TaskCreator interface {
CreateTask(ctx context.Context, r runrequest.TaskRequest) (runrequest.TaskResult, error)
}
TaskCreator is the factory's intake api, as the broker reaches it with the caller's own token.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package ui embeds the built web UI: web/ builds it (`task ui:build`) into dist/, which is committed, and `task ui:check` fails when the two differ.
|
Package ui embeds the built web UI: web/ builds it (`task ui:build`) into dist/, which is committed, and `task ui:check` fails when the two differ. |