humanapi

package
v0.30.4 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 57 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 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

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

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

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

type Authenticator interface {
	Authenticate(*http.Request) (authn.Principal, error)
}

Authenticator maps a request to a human principal; *authn.Humans implements it, Origin check included. authn.ErrForbidden means a foreign Origin.

type Dashboard

type Dashboard struct {
	Label string `json:"label"`
	URL   string `json:"url"`
}

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 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 Runs

type Runs interface {
	InRoom(room string) []runwatch.Run
}

Runs lists a room's runs; *runwatch.Watcher 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
	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
	// 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

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

func (*Server) Routes

func (s *Server) Routes() http.Handler

Routes is the :8080 handler.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, ln net.Listener, drain time.Duration) error

Serve serves the API on ln until ctx ends, then drains for at most drain. WebSockets end at once, 1001: their clients re-dial another replica.

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.

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.

Jump to

Keyboard shortcuts

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