Documentation
¶
Overview ¶
Package web is the status-server backend: the embedded status page SPA, a JSON projection of Findings and FindingRollups, the three human actions (approve, suspend, resume), and an SSE change signal that tells open browsers to refetch.
The exposure contract is deliberately asymmetric: rollup statistics are public (GET /api/rollups and the SSE stream serve without a session), while the findings surface — list, detail, and every action — always requires an authenticated identity (internal/web/auth) holding the RBAC grants (internal/web/authz). The server never writes finding status and never moves a phase: approve records spec.approval and suspend/resume toggle spec.suspend, leaving every phase edge to its owning controller.
The wire types in data.go mirror the status page's TypeScript contract (ui/src/types.ts) field for field; keep the two in lockstep.
Index ¶
- Constants
- func RegisterIndexes(ctx context.Context, idx client.FieldIndexer) error
- func RunFindingIndexer(obj client.Object) []string
- type ActionRequest
- type ActiveRun
- type Alert
- type Approval
- type Attempts
- type BackfillStatus
- type Budget
- type CloudResource
- type ConfigDataset
- type Dataset
- type EnhancerConfig
- type Enrichment
- type Estimate
- type EstimateAggregate
- type Finding
- type FindingSummary
- type ForgeConfig
- type Granter
- type IntegrationConfig
- type Investigation
- type InvestigationSummary
- type Location
- type MonthlyBucket
- type PhaseTime
- type PullRequest
- type RedeliveryStatus
- type Related
- type Remediation
- type RemediationSummary
- type Repository
- type Rollup
- type RollupBucket
- type RollupScope
- type Server
- type StageAggregate
- type Tailer
- type Tracking
- type TranscriptSummary
- type Turn
- type Usage
- type User
Constants ¶
const RunFindingIndex = "patchy.web/finding"
RunFindingIndex is the cache field index the detail projection looks a finding's Investigation/Remediation children up by (the finding label), so a detail request is an index hit rather than a namespace scan.
Variables ¶
This section is empty.
Functions ¶
func RegisterIndexes ¶ added in v0.10.0
func RegisterIndexes(ctx context.Context, idx client.FieldIndexer) error
RegisterIndexes installs the child-run index on the manager's cache. Call before the manager starts; the fake-client tests install the same extractor via WithIndex.
func RunFindingIndexer ¶ added in v0.10.0
RunFindingIndexer extracts the owning finding's name from a child run.
Types ¶
type ActionRequest ¶ added in v0.5.2
ActionRequest is a recorded human retry/expedite request.
type Alert ¶
type Alert struct {
ID string `json:"id"`
URL string `json:"url,omitempty"`
Locations []Location `json:"locations,omitempty"`
}
Alert is one scanner alert folded into the finding.
type Approval ¶
type Approval struct {
By string `json:"by"`
At string `json:"at"`
Note string `json:"note,omitempty"`
}
Approval is the recorded human approval.
type Attempts ¶
type Attempts struct {
Investigation int32 `json:"investigation,omitempty"`
Remediation int32 `json:"remediation,omitempty"`
}
Attempts tallies agent runs per stage.
type BackfillStatus ¶ added in v0.10.0
type BackfillStatus struct {
LastRunAt string `json:"lastRunAt,omitempty"`
Listed int32 `json:"listed,omitempty"`
Ingested int32 `json:"ingested,omitempty"`
Truncated bool `json:"truncated,omitempty"`
Error string `json:"error,omitempty"`
// RequestedBy/RequestedAt echo spec.backfill; Pending marks a request
// the controller has not attempted yet — a failed attempt clears it so
// the trigger re-enables for a corrected request.
RequestedBy string `json:"requestedBy,omitempty"`
RequestedAt string `json:"requestedAt,omitempty"`
Pending bool `json:"pending,omitempty"`
}
BackfillStatus mirrors status.backfill plus the pending-request echo the trigger button renders.
type Budget ¶ added in v0.8.0
type Budget struct {
// Estimated is the investigation's prediction; nil when it made none.
Estimated *Estimate `json:"estimated,omitempty"`
// GrantedMaxTurns/GrantedTokenBudget are what the run was allowed.
GrantedMaxTurns int32 `json:"grantedMaxTurns,omitempty"`
GrantedTokenBudget int64 `json:"grantedTokenBudget,omitempty"`
}
Budget is one remediation run's three-way budget picture: what the investigation predicted, what the run was granted, and (via the run's NumTurns and Usage.OutputTokens) what it actually spent. The client computes the over/under from these; the server ships raw figures.
type CloudResource ¶ added in v0.8.0
type CloudResource struct {
Provider string `json:"provider"`
Name string `json:"name"`
Type string `json:"type,omitempty"`
Project string `json:"project,omitempty"`
Location string `json:"location,omitempty"`
DisplayName string `json:"displayName,omitempty"`
}
CloudResource identifies the cloud resource a finding was raised against.
type ConfigDataset ¶ added in v0.10.0
type ConfigDataset struct {
GeneratedAt string `json:"generatedAt"`
Namespace string `json:"namespace,omitempty"`
Forges []ForgeConfig `json:"forges"`
Integrations []IntegrationConfig `json:"integrations"`
Enhancers []EnhancerConfig `json:"enhancers"`
}
ConfigDataset is the payload behind GET /api/config: the configured Forges, Integrations and enhancers the configuration view renders. It mirrors ui/src/types.ts. Never public — the route requires a signed-in identity holding native get on integrations.
type Dataset ¶
type Dataset struct {
GeneratedAt string `json:"generatedAt"`
Namespace string `json:"namespace,omitempty"`
Version string `json:"version,omitempty"`
User *User `json:"user,omitempty"`
Findings []FindingSummary `json:"findings"`
Rollups []Rollup `json:"rollups,omitempty"`
}
Dataset is the payload behind GET /api/findings (the trimmed list projection) and GET /api/rollups (findings empty, no user). It mirrors ui/src/types.ts.
type EnhancerConfig ¶ added in v0.10.0
type EnhancerConfig struct {
// ID is the enhancer's attribution id, as it appears on enrichments.
ID string `json:"id"`
// Integration names the Integration carrying the enhancer's config.
Integration string `json:"integration,omitempty"`
Enabled bool `json:"enabled"`
// Ambiguous marks a singleton capability enabled by more than one
// Integration — a configuration error the enhancer chain refuses, so
// the view surfaces it rather than picking one.
Ambiguous bool `json:"ambiguous,omitempty"`
}
EnhancerConfig is one context-enhancer instance derived from the Integrations. The static-context enhancer is deliberately absent: it is a context-controller command-line flag, invisible from the cluster configuration this view projects.
type Enrichment ¶
type Enrichment struct {
Enhancer string `json:"enhancer"`
Owners []string `json:"owners,omitempty"`
Attributes map[string]string `json:"attributes,omitempty"`
Markdown string `json:"markdown,omitempty"`
AppliedAt string `json:"appliedAt,omitempty"`
}
Enrichment is one enhancer contribution.
type Estimate ¶ added in v0.8.0
type Estimate struct {
MaxTurns int32 `json:"maxTurns,omitempty"`
TokenBudget int64 `json:"tokenBudget,omitempty"`
}
Estimate is an investigation's prediction of a remediation's cost.
type EstimateAggregate ¶ added in v0.8.0
type EstimateAggregate struct {
Runs int64 `json:"runs,omitempty"`
PredictedTurns int64 `json:"predictedTurns,omitempty"`
ActualTurns int64 `json:"actualTurns,omitempty"`
PredictedOutputTokens int64 `json:"predictedOutputTokens,omitempty"`
ActualOutputTokens int64 `json:"actualOutputTokens,omitempty"`
}
EstimateAggregate is predicted-against-actual cost over the runs that carried an estimate. Predicted and actual cover the same runs, so the client's skew (actual ÷ predicted - 1) is like-for-like.
type Finding ¶
type Finding struct {
Name string `json:"name"`
CreatedAt string `json:"createdAt,omitempty"`
Integration string `json:"integration,omitempty"`
Source string `json:"source,omitempty"`
Repository *Repository `json:"repository,omitempty"`
// CloudResource is set on a finding raised against infrastructure rather
// than repository code. It is what explains a finding with no repository:
// the resource carried no ownership labels to resolve one from.
CloudResource *CloudResource `json:"cloudResource,omitempty"`
Advisories []string `json:"advisories"`
RuleID string `json:"ruleID,omitempty"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Severity string `json:"severity,omitempty"`
Alerts []Alert `json:"alerts,omitempty"`
// OverflowAlerts counts alerts dropped past the accumulation cap.
OverflowAlerts int32 `json:"overflowAlerts,omitempty"`
Related []Related `json:"related,omitempty"`
Suspend bool `json:"suspend,omitempty"`
Approval *Approval `json:"approval,omitempty"`
Retry *ActionRequest `json:"retry,omitempty"`
Expedite *ActionRequest `json:"expedite,omitempty"`
Phase string `json:"phase,omitempty"`
PhaseTimes []PhaseTime `json:"phaseTimes,omitempty"`
FirstObservedAt string `json:"firstObservedAt,omitempty"`
AccumulateUntil string `json:"accumulateUntil,omitempty"`
Tracking *Tracking `json:"tracking,omitempty"`
Owners []string `json:"owners,omitempty"`
Enrichments []Enrichment `json:"enrichments,omitempty"`
Priority string `json:"priority,omitempty"`
Investigation *Investigation `json:"investigation,omitempty"`
Remediation *Remediation `json:"remediation,omitempty"`
PullRequest *PullRequest `json:"pullRequest,omitempty"`
Attempts *Attempts `json:"attempts,omitempty"`
// TotalUsage sums token and cost accounting across every attempt of
// both stages, lifted from the Investigation/Remediation children.
TotalUsage *Usage `json:"totalUsage,omitempty"`
ActiveRun *ActiveRun `json:"activeRun,omitempty"`
LastFailureReason string `json:"lastFailureReason,omitempty"`
CompletedAt string `json:"completedAt,omitempty"`
// UserActions are the verbs the requesting user may invoke; the client
// intersects them with the state machine. Absent means read-only.
UserActions []string `json:"userActions,omitempty"`
}
Finding is the full flattened metadata+spec+status projection of one Finding — the payload behind GET /api/findings/{name}. It is the summary's superset (same JSON keys for the shared fields; the lockstep tests pin both), plus the unbounded detail the list deliberately drops.
type FindingSummary ¶ added in v0.10.0
type FindingSummary struct {
Name string `json:"name"`
CreatedAt string `json:"createdAt,omitempty"`
Integration string `json:"integration,omitempty"`
Source string `json:"source,omitempty"`
Repository *Repository `json:"repository,omitempty"`
// CloudResource is set on a finding raised against infrastructure rather
// than repository code — it is the row's identity when there is no
// repository to name.
CloudResource *CloudResource `json:"cloudResource,omitempty"`
Advisories []string `json:"advisories"`
RuleID string `json:"ruleID,omitempty"`
Title string `json:"title,omitempty"`
Severity string `json:"severity,omitempty"`
Suspend bool `json:"suspend,omitempty"`
Phase string `json:"phase,omitempty"`
FirstObservedAt string `json:"firstObservedAt,omitempty"`
AccumulateUntil string `json:"accumulateUntil,omitempty"`
Owners []string `json:"owners,omitempty"`
Priority string `json:"priority,omitempty"`
Investigation *InvestigationSummary `json:"investigation,omitempty"`
Remediation *RemediationSummary `json:"remediation,omitempty"`
PullRequest *PullRequest `json:"pullRequest,omitempty"`
Attempts *Attempts `json:"attempts,omitempty"`
ActiveRun *ActiveRun `json:"activeRun,omitempty"`
LastFailureReason string `json:"lastFailureReason,omitempty"`
CompletedAt string `json:"completedAt,omitempty"`
// UserActions are the verbs the requesting user may invoke; the client
// intersects them with the state machine. Absent means read-only.
UserActions []string `json:"userActions,omitempty"`
}
FindingSummary is the trimmed per-finding projection the list payload carries: what the findings table, filters, and stat tiles render, and nothing whose size is unbounded (description, alert snippets, enrichment markdown, run reports). The payload behind GET /api/findings scales with finding count × row size, so the row stays bounded; everything else moves to the per-finding detail route.
type ForgeConfig ¶ added in v0.10.0
type ForgeConfig struct {
Name string `json:"name"`
Provider string `json:"provider"`
BaseURL string `json:"baseURL,omitempty"`
Orgs []string `json:"orgs,omitempty"`
Repositories []string `json:"repositories,omitempty"`
SecretRef string `json:"secretRef,omitempty"`
Interval string `json:"interval,omitempty"`
Suspend bool `json:"suspend,omitempty"`
// Ready is the Ready condition's status (True/False/Unknown); empty
// when the controller has not reported yet.
Ready string `json:"ready,omitempty"`
// ReadyMessage carries the condition message when not ready.
ReadyMessage string `json:"readyMessage,omitempty"`
}
ForgeConfig is one Forge's configuration surface.
type Granter ¶
Granter resolves what an identity may do; internal/web/authz provides the SubjectAccessReview implementation and the mode-none bypass.
type IntegrationConfig ¶ added in v0.10.0
type IntegrationConfig struct {
Name string `json:"name"`
Provider string `json:"provider"`
WebhookPath string `json:"webhookPath,omitempty"`
SecretRef string `json:"secretRef,omitempty"`
Interval string `json:"interval,omitempty"`
Suspend bool `json:"suspend,omitempty"`
Ready string `json:"ready,omitempty"`
ReadyMessage string `json:"readyMessage,omitempty"`
Capabilities []string `json:"capabilities,omitempty"`
// Redelivery reports the last failed-delivery sweep.
Redelivery *RedeliveryStatus `json:"redelivery,omitempty"`
// Backfill reports the last manual backfill and any pending request.
Backfill *BackfillStatus `json:"backfill,omitempty"`
// BackfillSupported reports whether the backfill trigger can do
// anything here (github provider with code scanning enabled).
BackfillSupported bool `json:"backfillSupported,omitempty"`
}
IntegrationConfig is one Integration's configuration surface, including the backfill trigger's state.
type Investigation ¶
type Investigation struct {
InvestigationSummary
Report string `json:"report,omitempty"`
Harness string `json:"harness,omitempty"`
Model string `json:"model,omitempty"`
NumTurns int32 `json:"numTurns,omitempty"`
Usage *Usage `json:"usage,omitempty"`
// SessionID is the agent CLI's own session identifier — a correlation key
// for operators reading model-provider logs, not a handle anything can be
// fetched with (the CLI session dies with the pod).
SessionID string `json:"sessionID,omitempty"`
// Transcript summarises the captured conversation; the turns themselves
// come from the transcript endpoint.
Transcript *TranscriptSummary `json:"transcript,omitempty"`
}
Investigation is the summary plus the report markdown and run accounting lifted from the Investigation child — detail-route only.
type InvestigationSummary ¶ added in v0.10.0
type InvestigationSummary struct {
Name string `json:"name,omitempty"`
Attempt int32 `json:"attempt,omitempty"`
Outcome string `json:"outcome,omitempty"`
Recommendation string `json:"recommendation,omitempty"`
Confidence string `json:"confidence,omitempty"`
Exploitability string `json:"exploitability,omitempty"`
Likelihood string `json:"likelihood,omitempty"`
Impact string `json:"impact,omitempty"`
AwaitApproval bool `json:"awaitApproval,omitempty"`
HoldReasons []string `json:"holdReasons,omitempty"`
// Estimate is what this investigation predicted the remediation would
// cost; the remediation's Budget reports what it was granted and spent.
Estimate *Estimate `json:"estimate,omitempty"`
CompletedAt string `json:"completedAt,omitempty"`
}
InvestigationSummary mirrors the Finding's own investigation status — bounded verdict fields the list rows render (recommendation, confidence).
type Location ¶
type Location struct {
Path string `json:"path"`
StartLine int32 `json:"startLine,omitempty"`
EndLine int32 `json:"endLine,omitempty"`
Snippet string `json:"snippet,omitempty"`
}
Location is one source location an alert points at.
type MonthlyBucket ¶
type MonthlyBucket struct {
Findings int64 `json:"findings,omitempty"`
Runs int64 `json:"runs,omitempty"`
CostMicroUSD int64 `json:"costMicroUSD,omitempty"`
}
MonthlyBucket is one month of the total scope's trend line.
type PullRequest ¶
type PullRequest struct {
Number int64 `json:"number"`
URL string `json:"url,omitempty"`
State string `json:"state,omitempty"`
MergedAt string `json:"mergedAt,omitempty"`
}
PullRequest is the remediation pull request's lifecycle.
type RedeliveryStatus ¶ added in v0.10.0
type RedeliveryStatus struct {
LastSweepAt string `json:"lastSweepAt,omitempty"`
Scanned int32 `json:"scanned,omitempty"`
Redelivered int32 `json:"redelivered,omitempty"`
Truncated bool `json:"truncated,omitempty"`
Error string `json:"error,omitempty"`
}
RedeliveryStatus mirrors status.redelivery.
type Related ¶
Related is one relationship edge, named from this finding's perspective: the CRD stores {from, to}, the wire type carries the other endpoint.
type Remediation ¶
type Remediation struct {
RemediationSummary
Report string `json:"report,omitempty"`
Harness string `json:"harness,omitempty"`
Model string `json:"model,omitempty"`
NumTurns int32 `json:"numTurns,omitempty"`
Budget *Budget `json:"budget,omitempty"`
Usage *Usage `json:"usage,omitempty"`
// SessionID is the agent CLI's own session identifier; see Investigation.
SessionID string `json:"sessionID,omitempty"`
// Transcript summarises the captured conversation.
Transcript *TranscriptSummary `json:"transcript,omitempty"`
}
Remediation is the summary plus the report markdown and run accounting lifted from the Remediation child — detail-route only.
type RemediationSummary ¶ added in v0.10.0
type RemediationSummary struct {
Name string `json:"name,omitempty"`
Attempt int32 `json:"attempt,omitempty"`
Outcome string `json:"outcome,omitempty"`
Success bool `json:"success,omitempty"`
Branch string `json:"branch,omitempty"`
CompletedAt string `json:"completedAt,omitempty"`
}
RemediationSummary mirrors the Finding's own remediation status.
type Repository ¶
type Repository struct {
Type string `json:"type"`
URL string `json:"url"`
Name string `json:"name,omitempty"`
DefaultBranch string `json:"defaultBranch,omitempty"`
}
Repository locates the finding's repository.
type Rollup ¶
type Rollup struct {
Scope RollupScope `json:"scope"`
FirstProcessed string `json:"firstProcessed,omitempty"`
LastProcessed string `json:"lastProcessed,omitempty"`
Bucket RollupBucket `json:"bucket"`
Monthly map[string]MonthlyBucket `json:"monthly,omitempty"`
}
Rollup is one scope's all-time statistics, identified by scope.key ("" is the total scope) — never by object name.
type RollupBucket ¶
type RollupBucket struct {
Findings int64 `json:"findings,omitempty"`
Phases map[string]int64 `json:"phases,omitempty"`
Recommendations map[string]int64 `json:"recommendations,omitempty"`
Attempts int64 `json:"attempts,omitempty"`
Stages map[string]StageAggregate `json:"stages,omitempty"`
}
RollupBucket carries the finding-level counters; harness and model scopes carry only stages.
type RollupScope ¶
RollupScope identifies one rollup dimension value.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the status-server backend: the public rollups projection, the authenticated findings projection, the three actions, the SSE change signal, and the embedded SPA.
func NewServer ¶
func NewServer(c client.Client, namespace string, a auth.Authenticator, g Granter, log *slog.Logger) *Server
NewServer builds the backend over the manager's cached client. log may be nil.
func (*Server) Handler ¶
Handler builds the HTTP surface: the split public/authenticated API, the SSE stream, the sign-in routes (when the auth mode has any), and the embedded SPA with client-side-routing fallback.
func (*Server) StartWatch ¶
StartWatch registers change handlers on the Finding/FindingRollup and Integration/Forge informers and publishes debounced findings-changed / config-changed notifications to the SSE broker. It blocks until ctx is cancelled, so it slots straight into a manager runnable — running after the cache has synced and stopping with the manager.
func (*Server) WithTranscripts ¶ added in v0.8.2
WithTranscripts wires the uncached reader for persisted transcripts and the tailer for live ones. Without it the server still serves everything else; transcripts simply come back empty.
type StageAggregate ¶
type StageAggregate struct {
Runs int64 `json:"runs,omitempty"`
Succeeded int64 `json:"succeeded,omitempty"`
Outcomes map[string]int64 `json:"outcomes,omitempty"`
InputTokens int64 `json:"inputTokens,omitempty"`
OutputTokens int64 `json:"outputTokens,omitempty"`
CacheReadTokens int64 `json:"cacheReadTokens,omitempty"`
CacheCreationTokens int64 `json:"cacheCreationTokens,omitempty"`
CostMicroUSD int64 `json:"costMicroUSD,omitempty"`
ElapsedMilliseconds int64 `json:"elapsedMilliseconds,omitempty"`
Turns int64 `json:"turns,omitempty"`
Estimate *EstimateAggregate `json:"estimate,omitempty"`
}
StageAggregate is one stage's raw sums; the client computes rates and averages.
type Tailer ¶ added in v0.8.2
type Tailer interface {
Tail(ctx context.Context, jobName string, fn func(transcript.Turn) error) error
}
Tailer follows a running agent Job's transcript; *jobs.Tailer implements it.
type Tracking ¶
type Tracking struct {
IssueNumber int64 `json:"issueNumber,omitempty"`
URL string `json:"url,omitempty"`
State string `json:"state,omitempty"`
}
Tracking links the projected tracking issue.
type TranscriptSummary ¶ added in v0.8.2
type TranscriptSummary struct {
Turns int32 `json:"turns"`
Truncated bool `json:"truncated,omitempty"`
}
TranscriptSummary tells the client whether a run has a conversation worth opening, without shipping it inside the dataset — a finding list carrying every run's full transcript would be orders of magnitude larger than the page needs.
type Turn ¶ added in v0.8.2
type Turn struct {
Seq int `json:"seq"`
At string `json:"at,omitempty"`
Role string `json:"role"`
Kind string `json:"kind"`
Tool string `json:"tool,omitempty"`
Text string `json:"text,omitempty"`
Truncated bool `json:"truncated,omitempty"`
}
Turn is one conversation entry on the wire. It mirrors the SPA's TranscriptTurn; keep the two in lockstep.
type Usage ¶ added in v0.5.3
type Usage struct {
InputTokens int64 `json:"inputTokens,omitempty"`
OutputTokens int64 `json:"outputTokens,omitempty"`
CacheReadTokens int64 `json:"cacheReadTokens,omitempty"`
CacheCreationTokens int64 `json:"cacheCreationTokens,omitempty"`
CostMicroUSD int64 `json:"costMicroUSD,omitempty"`
}
Usage is token and cost accounting — one run's, or the finding's total across every attempt of both stages. Cost is integer micro-USD, matching the rollup wire type.
type User ¶
type User struct {
Name string `json:"name"`
LoggedIn bool `json:"loggedIn"`
// AdminActions are the granted demo-tooling verbs (replay, reset) the
// user menu renders. Absent means none.
AdminActions []string `json:"adminActions,omitempty"`
// ConfigView reports native get on integrations — whether the
// configuration view is reachable for this user.
ConfigView bool `json:"configView,omitempty"`
// IntegrationActions are the granted integration-scoped verbs
// (backfill, replay, reset) the configuration view's triggers check.
IntegrationActions []string `json:"integrationActions,omitempty"`
}
User is the signed-in identity the top bar renders.