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
- type ActRequest
- type ActResult
- type AnswerForge
- type AnswerRequest
- type Authenticating
- type Authenticator
- type CancelRequest
- type CoordinationService
- type DraftRequest
- type EvidenceSource
- type ForgeThreads
- type GitHubAccess
- func (a GitHubAccess) CanRead(ctx context.Context, p authn.Principal, repository string) (bool, error)
- func (a GitHubAccess) CanWrite(ctx context.Context, p authn.Principal, repository string) (bool, error)
- func (a GitHubAccess) CanWriteLogin(ctx context.Context, repository, login string) (bool, error)
- func (a GitHubAccess) Person(ctx context.Context, p authn.Principal, repository string) (string, error)
- type Incident
- type IssueFiler
- type LoginResolver
- type PersonResolver
- type PlanRequest
- type PolicyEditor
- type PolicySource
- type ReadChecker
- type RecoveryRequest
- type RunRequest
- type RunStore
- type Server
- type SlackLinkReader
- type SplitRequest
- type TaskRequest
- type WriteChecker
Constants ¶
const ( ActStopped = "stopped" ActRetried = "retried" ActSteppedUp = "stepped_up" ActNoDeeperWorkflow = "no_deeper_workflow" ActDeeperOverCap = "deeper_over_cap" ActNotLinked = "not_linked" ActNotMaintainer = "not_maintainer" ActNotRunning = "not_running" ActNotEscalated = "not_escalated" ActUnknownTask = "unknown_task" ActNoPlan = "no_plan" ActNotAllowed = "not_allowed" ActPlanApproved = "plan_approved" ActPlanRevised = "plan_revised" ActPlanSplit = "plan_split" ActSplitAccepted = "split_accepted" ActSplitDeclined = "split_declined" ActNoSplit = "no_split" )
Closed result codes answered by POST /v1/tasks/{task}/stops and /retries.
const ( AnswerRestarted = "answered_restarted" AnswerWritten = "answered" AnswerNotLinked = "not_linked" AnswerNotAllowed = "not_allowed" AnswerNoQuestion = "no_question" AnswerUnknownTask = "unknown_task" )
Closed result codes answered by POST /v1/tasks/{task}/answers.
const ( ActCancelled = "cancelled" ActDiscarded = "discarded" )
Closed result codes the cancellations route answers beside not_linked, not_maintainer, not_running and unknown_task.
const AudienceSystem = "agent-factory"
AudienceSystem is what a system caller's projected token carries (R23).
const BrokerPrincipal = config.BrokerPrincipal
BrokerPrincipal is the room broker's system principal on this API (HR35): the api.systemPrincipals value its ServiceAccount maps to, the one caller the forge-read route admits.
const CancelRoute = "POST /v1/tasks/{task}/cancellations"
CancelRoute is a task's cancel or discard by a human (#644). It is mounted whenever the API is, unlike the sponsored /stops: the room page, maku cancel and the cancel tool reach it through the broker with the person's own token, and it needs no issue, so it ends a task whose issue was deleted.
const DrillPrincipal = config.DrillPrincipal
DrillPrincipal is the drill planter's system principal on this API (HR38): the api.systemPrincipals value its CronJob's ServiceAccount maps to, the one caller the drill manifest route admits.
const DrillsRoute = "POST /v1/hardening/drills"
DrillsRoute is the route a drill planter posts its manifest to.
const ForgeReadRoute = "POST /v1/runs/{run}/forge-read"
ForgeReadRoute is the route the broker's forge_read forwards to.
const InstallPrivateCodeUnacknowledged = "private_code_unacknowledged"
InstallPrivateCodeUnacknowledged is the factory's banner code: a served repository is private code without spec.privateCode.acknowledged (v4 D3, step 7 R1). The broker's config names it config.UnsafePrivateCodeUnacknowledged.
const InstallRoute = "GET /v1/install"
InstallRoute is the factory's part of the install's state (GET /api/install on the broker, v4 D3): bounded codes, the web UI's banner.
const KeyLifetime = 24 * time.Hour
KeyLifetime is how long an Idempotency-Key answers with its first run: the ledger's day.
const ReadFilterOff = "read_filter_off"
ReadFilterOff is the forge-read route's 409: the run's repository is not in hardening mode enforce, so its reads are not filtered and none is served.
const ReadinessRoute = "GET /v1/hardening/readiness"
ReadinessRoute lists each hardened repository's readiness (H5, HR41).
const VouchLabel = "factory/vouch"
VouchLabel is a maintainer's vouch on an issue or pull request (UH6): its body reads approved.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActRequest ¶ added in v0.53.0
type ActRequest struct {
OnBehalfOf string `json:"onBehalfOf,omitempty"`
Deeper bool `json:"deeper,omitempty"`
}
ActRequest is the POST /v1/tasks/{task}/stops and /retries body (SI23, WR4). Unknown fields are refused: the actor is resolved from the link onBehalfOf names (for sponsored callers) or the caller's own GitHub link (for human callers on /retries), never supplied as a login.
type ActResult ¶ added in v0.53.0
type ActResult struct {
Result string `json:"result"`
Workflow string `json:"workflow,omitempty"`
CeilingMicroUSD int64 `json:"ceilingMicroUSD,omitempty"`
}
ActResult is the closed result vocabulary of POST /v1/tasks/{task}/stops and /retries.
type AnswerForge ¶ added in v0.53.0
type AnswerForge interface {
Issue(ctx context.Context, number int) (forge.Issue, error)
EditIssueBody(ctx context.Context, number int, body string) error
}
AnswerForge reads and updates an issue's body as the factory App for POST /v1/tasks/{task}/answers.
type AnswerRequest ¶ added in v0.53.0
type AnswerRequest struct {
OnBehalfOf string `json:"onBehalfOf,omitempty"`
Text string `json:"text"`
}
AnswerRequest is the POST /v1/tasks/{task}/answers body. Unknown fields — login included — are refused: the actor is resolved from the link onBehalfOf names (for sponsored callers) or the caller's own GitHub link (for human callers), never supplied in the body.
type Authenticating ¶
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
// TokenUse is what the broker forwards and maku sends (v4 D8): "" or access, a JWT access
// token; id, an ID token whose aud holds the client it was issued to.
TokenUse string
// RolesClaim names the claim holding the groups, or an RFC 6901 pointer; "" is the zitadel
// preset's groups, else the project roles' keys.
RolesClaim string
// Generic is the generic preset: a one-element aud may name the client, and the roles claim
// is judged by RoleNames. Unset is the zitadel preset, byte for byte.
Generic bool
// Audience is the aud value a generic access token must hold; nil or "" refuses. Unread under
// the zitadel preset, whose human path pins the client alone, and under token use id.
Audience func() string
// RolesRefused counts a roles claim that gave no group, by its reason. Optional.
RolesRefused func(ctx context.Context, reason string)
}
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 ¶
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 CancelRequest ¶ added in v0.53.10
type CancelRequest struct {
Discard bool `json:"discard"`
}
CancelRequest is the cancellations body: discard also closes the pull request, deletes the agent/<task> branch and closes the issue as not planned.
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 ForgeThreads ¶ added in v0.47.0
type ForgeThreads interface {
Issue(ctx context.Context, number int) (forge.Issue, error)
AllComments(ctx context.Context, number int) ([]forge.Comment, error)
PullRequest(ctx context.Context, number int) (forge.PR, error)
PullRequestChecks(ctx context.Context, number int) (forge.Checks, error)
FailedJobLog(ctx context.Context, jobID int64) (string, error)
LabelEvents(ctx context.Context, number int, label string) ([]forge.LabelEvent, error)
}
ForgeThreads is what forge_read reads of a repository with the factory App (HR35): the task's own issue, pull request and checks. *forge.GitHub 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
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.
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 ¶
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 PlanRequest ¶ added in v0.54.0
type PlanRequest struct {
OnBehalfOf string `json:"onBehalfOf,omitempty"`
Decision string `json:"decision"`
Note string `json:"note,omitempty"`
}
PlanRequest is the POST /v1/tasks/{task}/plans body (phase F3): approve, revise (with a one-line note), or split.
type PolicyEditor ¶ added in v0.40.0
type PolicyEditor interface {
Preview(ctx context.Context, repository, file string) (any, error)
// PreviewBindings and PreviewPolicy are the binding and policy edits (B16): one repository's
// mergePolicies, and a MergePolicy with its consumers the caller reads (readable).
PreviewBindings(ctx context.Context, repository string, bindings []config.Binding) (any, error)
PreviewPolicy(ctx context.Context, name string, spec config.PolicySpec, readable func(repository string) bool) (any, error)
Timeline(ctx context.Context, repository string, pr int) (any, error)
Recent(ctx context.Context, repository, since string) (any, error)
Backtest(ctx context.Context, repository, kind, file string, bindings []config.Binding, policy string, spec *config.PolicySpec, since string) (any, error)
Promote(ctx context.Context, repository, class string, minimum int) (any, error)
PromotionStatus(ctx context.Context, repository, class string, number int) (any, error)
Drill(ctx context.Context, repository string, number 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 PolicySource ¶ added in v0.47.0
type PolicySource interface {
Policies(ctx context.Context) []evidence.PolicyReport
Policy(ctx context.Context, name string) (evidence.PolicyReport, error)
}
PolicySource is the class-shape MergePolicies the factory serves (B16); *evidence.Service implements it.
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
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"`
Harness string `json:"harness,omitempty"`
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
// APIReader, when set, reads a Task uncached after an AlreadyExists race (mgr.GetAPIReader()),
// avoiding informer cache lag; nil falls back to Rooms.
APIReader client.Reader
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
// PrivateRefused is v4 D3: whether the repository is private code without its acknowledgement,
// refused new tasks (403 private_code_unacknowledged). nil refuses none.
PrivateRefused 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
// Answers reads and edits an issue's body for POST /v1/tasks/{task}/answers (SI24); when nil,
// Forges or Readers is used when it implements AnswerForge.
Answers func(repository string) AnswerForge
// 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
// Policies are the class-shape MergePolicies (B16), served beside the evidence; nil lists none.
Policies PolicySource
// PolicySnapshot is a repository's file as last read (mergepolicy.Watch.Snapshot): a cut-over
// repository's file bindings make it a consumer for the policy pages. nil reads none.
PolicySnapshot func(repository string) (mergepolicy.Snapshot, bool)
// Readers reads a repository's issues, pull requests and checks with the factory App for the
// broker's forge_read (HR35); nil, or nil for a repository, answers forge_unavailable.
// Readiness is each repository's hardening readiness (H5, HR41), served to operators and on the
// Evidence page; nil serves neither.
Readiness hardening.Readiness
Readers func(repository string) ForgeThreads
// Trust is each repository's fence-file hardening block, its trust floor; nil reads the floor
// and the central minAuthorTrust.
Trust *hardening.RepositoryPolicies
// Writers is v2 D5's write check on a login, read for a factory/vouch label whose labeller is
// not a maintainer; nil vouches for maintainers' labels only.
Writers func(ctx context.Context, repository, login string) (bool, error)
// InstallUnsafe is the factory's banner codes (GET /v1/install, v4 D3); nil lists none.
InstallUnsafe func() []string
// StagesCache holds each repository's folded stage report for the catalogue's typical cost (WR5).
StagesCache *stages.Cache
// contains filtered or unexported fields
}
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 ¶
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 ¶
NeedLeaderElection is false: every replica serves intake.
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 SplitRequest ¶ added in v0.54.0
type SplitRequest struct {
OnBehalfOf string `json:"onBehalfOf,omitempty"`
Decision string `json:"decision"`
}
SplitRequest is the POST /v1/tasks/{task}/splits body (phase G1): accept or decline a proposed split.
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"`
// Class and Suggested are a planned task's: the plan's class and the planner's suggested profile
// (P7, P13), copied to spec.intake with the sponsor's resolved login. Neither is authority: triage
// declares the class only when that login maintains the repository.
Class string `json:"class,omitempty"`
Suggested string `json:"suggested,omitempty"`
// Profile is the profile the plan pinned (P5): a pin only when the sponsor's login maintains the
// repository, which triage checks again with the rest of the pin rule (P6).
Profile string `json:"profile,omitempty"`
// StepUpShown is true when the confirmed plan showed the "if it steps up" cost figure (WR4).
StepUpShown bool `json:"stepUpShown,omitempty"`
// Outcome is the task outcome the confirmed plan carried (phase F); empty is change.
Outcome string `json:"outcome,omitempty"`
// DependsOn lists earlier issue numbers in the same repository that must merge first (phase H2).
DependsOn []int32 `json:"dependsOn,omitempty"`
// Harness is an optional maintainer harness pin (openhands or opencode).
Harness string `json:"harness,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).