api

package
v0.41.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 40 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 api is the run-request API (§4): once SP3 ships, the only way to create an AgentRun. The principal comes from the caller's token, never from the body.

Index

Constants

View Source
const AudienceSystem = "agent-factory"

AudienceSystem is what a system caller's projected token carries (R23).

View Source
const KeyLifetime = 24 * time.Hour

KeyLifetime is how long an Idempotency-Key answers with its first run: the ledger's day.

Variables

This section is empty.

Functions

This section is empty.

Types

type Authenticating

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

Authenticating maps a request to its caller. Task 5.1's Authenticator satisfies it; the principal is always the token's, never the body's (SC-13).

type Authenticator

type Authenticator struct {
	Humans      *authn.Verifier   // ZITADEL, offline against its JWKS; nil in demo mode: every human token is refused
	Groups      policy.Groups     // the two agents groups; a human must be in one (R23)
	ClientIDs   func() []string   // rooms-proxy (the broker forwards it) and maku (the CLI)
	Systems     *authn.Verifier   // the cluster's issuer; nil when no system caller is allowed
	SystemAllow map[string]string // ServiceAccount sub → system:<component>; empty ships: none exists yet
	// Sponsored is F4's third branch; nil while api.sponsored is empty.
	Sponsored *authn.Sponsored
}

Authenticator maps a run-request to its caller: a human through one of the two rooms clients (the broker forwards rooms-proxy's token, maku sends its own), or an allowlisted system caller on the cluster's issuer.

func (*Authenticator) Authenticate

func (a *Authenticator) Authenticate(r *http.Request) (authn.Principal, error)

Authenticate maps r to its caller's principal, from the bearer token alone. A valid token for a rejected caller is not mistaken for an invalid one: an unadmitted human and an unlisted system caller are ErrForbidden, every other refusal ErrUnauthenticated.

type CoordinationService added in v0.39.0

type CoordinationService interface {
	Draft(ctx context.Context, actor coordination.Actor, p factoryv1.CoordinationPlan, hash string, planning coordination.PlanningReconciliation) (coordination.CoordinationConfirmation, error)
	Confirm(ctx context.Context, actor coordination.Actor, in coordination.CoordinationConfirmation) (coordination.CoordinationConfirmation, error)
	RecoveryRepository(ctx context.Context, parentTask string) (string, error)
	Recover(ctx context.Context, actor coordination.Actor, parentTask, code string, planVersion int32) error
}

CoordinationService is the coordination flow the API serves (v4 MR4, MR5); *coordination.Service implements it.

type DraftRequest added in v0.39.0

type DraftRequest struct {
	Plan       factoryv1.CoordinationPlan          `json:"plan"`
	PlanHash   string                              `json:"planHash"`
	Planning   coordination.PlanningReconciliation `json:"planning"`
	OnBehalfOf string                              `json:"onBehalfOf,omitempty"`
}

DraftRequest is PUT /v1/coordinations/{task}/draft's body: a CoordinationConfirmation's plan, hash and planning, and for a sponsored principal the user it drafts for. No confirmation, actor or AgentRun id is accepted: unknown fields are refused.

type EvidenceSource added in v0.40.0

type EvidenceSource interface {
	Report(ctx context.Context, repository string) (evidence.Report, error)
}

EvidenceSource is each repository's promotion evidence (merge policy stage 6); *evidence.Service implements it.

type GitHubAccess

type GitHubAccess struct {
	Identity interface {
		Login(ctx context.Context, sub, repository string) (string, error)
	}
	Perms interface {
		CanWrite(ctx context.Context, repository, login string) (bool, error)
	}
}

GitHubAccess is v2 D4's WriteChecker: the principal's GitHub login from their ZITADEL link (the broker forwards the token, never a login), then that login's permission on the repository. No link is no write; a lookup that fails is an error, which the server refuses.

func (GitHubAccess) CanRead added in v0.40.0

func (a GitHubAccess) CanRead(ctx context.Context, p authn.Principal, repository string) (bool, error)

CanRead implements ReadChecker: read or higher, through the same link CanWrite resolves. A Perms without CanRead reads nothing.

func (GitHubAccess) CanWrite

func (a GitHubAccess) CanWrite(ctx context.Context, p authn.Principal, repository string) (bool, error)

CanWrite implements WriteChecker.

func (GitHubAccess) CanWriteLogin added in v0.39.0

func (a GitHubAccess) CanWriteLogin(ctx context.Context, repository, login string) (bool, error)

CanWriteLogin is write or higher for an already-resolved login: a sponsored principal's onBehalfOf maintainer, who drafts a coordination plan on the primary (v4 MR4) as the planner requires of the effective requester.

func (GitHubAccess) Person

func (a GitHubAccess) Person(ctx context.Context, p authn.Principal, repository string) (string, error)

Person implements PersonResolver (v2 per-person caps D1): github:<login> from the same link CanWrite reads, "" with no sub or no link.

type Incident

type Incident struct {
	Alert      string  `json:"alert"`
	Resource   string  `json:"resource"`
	Severity   string  `json:"severity"`
	Cluster    string  `json:"cluster"`
	Verdict    string  `json:"verdict"`
	Confidence float64 `json:"confidence"`
}

Incident is RunLore's finding, as an internal principal sends it (RA3, RA6): identifiers for the stub issue and the gates' inputs. The finding itself is the request's text.

type IssueFiler

type IssueFiler interface {
	CreateIssue(ctx context.Context, title, body string, labels []string) (forge.Issue, error)
}

IssueFiler files an issue as the factory App: RunLore's CreateIssue, whose answer is a forge.Issue since the splitter (#195).

type LoginResolver

type LoginResolver interface {
	Login(ctx context.Context, sub, repository string) (string, error)
}

LoginResolver is a ZITADEL sub's current GitHub login, "" when it has none; ghidentity.ErrInactive when the user is not active. *ghidentity.Resolver implements it.

type PersonResolver

type PersonResolver interface {
	Person(ctx context.Context, p authn.Principal, repository string) (string, error)
}

PersonResolver names the person a human principal is charged as (v2 per-person caps D1): github:<login> through their ZITADEL link, "" with no link. An error is no answer.

type PolicyEditor added in v0.40.0

type PolicyEditor interface {
	Preview(ctx context.Context, repository, file string) (any, error)
	Timeline(ctx context.Context, repository string, pr int) (any, error)
}

PolicyEditor is the settings editor's check and the decision timeline (stage 6), each answered as the JSON document it is; app wires *policyview.Service through it. The documents are any so this package does not import the reconciler: intake's tests import this package, and the reconciler imports intake.

type ReadChecker added in v0.40.0

type ReadChecker interface {
	CanRead(ctx context.Context, p authn.Principal, repository string) (bool, error)
}

ReadChecker answers whether a human may read a repository on GitHub, as WriteChecker answers write; GitHubAccess implements both.

type RecoveryRequest added in v0.39.0

type RecoveryRequest struct {
	Code        string `json:"code"`
	PlanVersion int32  `json:"planVersion"`
}

RecoveryRequest is POST /v1/coordinations/{task}/recovery's body: the one proposed action and the plan version it was proposed under. Unknown fields are refused.

type RunRequest

type RunRequest struct {
	Role       string `json:"role"`
	Repository string `json:"repository"`
	BaseRef    string `json:"baseRef"`
	Task       struct {
		Text string `json:"text"`
		URL  string `json:"url"`
	} `json:"task"`
	DataClass      string   `json:"dataClass"`
	RoomRef        string   `json:"roomRef"`
	Model          string   `json:"model"`
	MaxTokens      int64    `json:"maxTokens"`
	EgressProfiles []string `json:"egressProfiles"`
	// R35: a stopped run's branch, to resume on. Never a task's or a live run's.
	ResumeBranch string `json:"resumeBranch"`
}

RunRequest is the POST /v1/runs body (§4). Unknown fields — principal and branch included — are ignored: the principal is the token's (SC-13) and the branch the factory's (C3).

type RunStore

type RunStore interface {
	Create(ctx context.Context, s runs.Spec) error
	List(ctx context.Context) ([]runs.Run, error)
}

RunStore creates the claim and lists the live runs the room and branch checks read. Since R50 the daily budget does not come from List: it is admitted through the day's ledger.

type Server

type Server struct {
	Auth Authenticating
	// Groups names the two agents groups: policy's StartRun rule is the room UI's rule, so
	// the CLI grants nothing the UI refuses (SP2 §1).
	Groups policy.Groups
	Cfg    config.Source
	Runs   RunStore
	// Rooms is the manager's client: it reads Rooms and Tasks (rights, R35), and R50's
	// ledger reservation writes ConfigMaps, so a client.Reader would not do.
	Rooms     client.Client
	Namespace string
	Stopped   func(context.Context) bool // the stop object (§6.1); true on doubt
	NewRunID  func() string
	Now       func() time.Time
	Metrics   *fmetrics.Set
	// Owned is v2 D7's fence: whether the repository's default branch names this factory. nil owns
	// nothing.
	Owned func(repository string) bool
	// Access is v2 D4: whether a human may write the repository on GitHub. nil refuses every
	// human: GitHub is the one answer to who may change a repository, and there is no bypass.
	Access WriteChecker
	// SlackLinks is the broker's self-serve link records (GET /v1/links/slack) and Logins the
	// ZITADEL resolver that turns a linked sub into its current GitHub login: read only for a
	// sponsored principal with onBehalfOf.slackLinks. Either nil makes every such link not_linked.
	SlackLinks SlackLinkReader
	Logins     LoginResolver
	// People is D1's identity link, read only while budgets.perPerson is on: the person a human
	// token is charged as. nil charges every human as their own principal.
	People PersonResolver
	// Forges files an api task's issue as the factory App on its repository (R10): nil files none;
	// a nil filer for a repository refuses a titled request.
	Forges func(repository string) IssueFiler
	// Log records the causes the intake never answers; nil records none.
	Log *slog.Logger
	// Redact is the broker's secret redactor (*redact.Redactor), applied to an api task's issue
	// before it is filed; nil refuses a titled request.
	Redact interface {
		String(s string) (string, []string)
	}
	// Coordination is the multi-repository draft and confirmation flow (v4 MR4, MR5), served only
	// while coordination.mode is plan or execute; nil or off serves no coordination route.
	Coordination CoordinationService
	// Evidence is each repository's promotion evidence (merge policy stage 6), served only while
	// policyManagement.promotion is on; nil or off serves no policy route.
	Evidence EvidenceSource
	// Editor is the settings editor's check and the decision timeline, served beside Evidence.
	Editor PolicyEditor
}

Server is the run-request API (§4). It serves on every replica (NeedLeaderElection is false), and admission is atomic across replicas through the day's ledger (R50).

func (*Server) Handler

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

Handler is the API's mux: POST /v1/runs, admission in §4's order, POST /v1/tasks while a sponsored principal is declared, and the coordination routes while the switch is on.

func (*Server) NeedLeaderElection

func (s *Server) NeedLeaderElection() bool

NeedLeaderElection is false: every replica serves intake.

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start serves on api.listen until ctx ends, then drains for at most apiDrain, and returns only once the drain has (F-7): the manager waits on Start, so a handler between its Task's create and its issue finishes before the process exits.

type SlackLinkReader

type SlackLinkReader interface {
	SlackLink(ctx context.Context, team, user string) (sub string, found bool, err error)
}

SlackLinkReader is the broker's self-serve link records: the ZITADEL sub a Slack user linked; *rooms.Client implements it.

type TaskRequest

type TaskRequest struct {
	Repository string  `json:"repository"`
	Title      string  `json:"title,omitempty"`
	Text       string  `json:"text"`
	DataClass  string  `json:"dataClass"`
	MaxCostUSD float64 `json:"maxCostUSD"`
	OnBehalfOf string  `json:"onBehalfOf,omitempty"`
	Ref        string  `json:"ref,omitempty"`
	// Incident is an internal principal's finding (RA3); a sponsored principal's request refuses it.
	Incident *Incident `json:"incident,omitempty"`
}

TaskRequest is POST /v1/tasks's body (F4). Unknown fields are refused: class, tier, template, auto-merge and egress are never the caller's (F8, R11).

type WriteChecker

type WriteChecker interface {
	CanWrite(ctx context.Context, p authn.Principal, repository string) (bool, error)
}

WriteChecker answers v2 D4 for a human principal: write or higher on repository, from GitHub. An error is no answer, and the caller refuses.

Jump to

Keyboard shortcuts

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