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 Authenticating
- type Authenticator
- type CoordinationService
- type DraftRequest
- type EvidenceSource
- 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 PolicyEditor
- type ReadChecker
- type RecoveryRequest
- type RunRequest
- type RunStore
- type Server
- type SlackLinkReader
- type TaskRequest
- type WriteChecker
Constants ¶
const AudienceSystem = "agent-factory"
AudienceSystem is what a system caller's projected token carries (R23).
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 ¶
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 ¶
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
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 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
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 ¶
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 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).