operator

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package operator provides the stable machine-readable diagnosis and repair-hint layer consumed by the AgentPaaS CLI, dashboard, and Block 13 MCP/Hermes integrations.

The operator contract is the retroactive invariant for Blocks 1-10: every human-facing command that inspects, diagnoses, or repairs an agent project exposes a --json output backed by the versioned schemas defined in this package. The schemas are the contract; text output is a rendered view, not the source of truth.

Methods

The package defines request/response types for the seven P1 operator methods:

  • ValidateAgentProject — project readiness check
  • SummarizeRun — final result summary for a completed run
  • ExplainFailure — root-cause diagnosis for a failed run
  • ExplainPolicyDenial — identify the blocking policy rule
  • RecommendPolicyPatch — propose a safe policy patch with risk level
  • GetRunTimeline — chronological event list for a run
  • NextAction — recommend the next operator action

Error categories

Every diagnosis method returns a stable ErrorCategory from the fixed enum. Categories are part of the versioned contract: adding a new category is a backward-compatible schema extension, but renaming or removing one is a breaking change.

Evidence refs

Diagnosis responses include EvidenceRef values that point to auditable artifacts: run_id, audit sequence ranges, policy rule ids, span/log ids, redacted excerpts, and verification commands. Tools resolve these refs to retrieve the underlying data; the refs themselves never contain secret values.

Confirmation protocol

Trust-boundary changes (policy patches, credential bindings, direct leases, handoff triggers, exposed listeners, retention purges, destructive operations) cannot be applied by an agentic tool without explicit user/daemon confirmation. The confirmation protocol is encoded in the ConfirmationRequirement type: a response with RequiresConfirmation=true includes a ConfirmationID, RiskLevel, rationale, and evidence refs. The agentic tool returns the proposal; the daemon/UI/CLI confirmation path applies the change.

Index

Constants

View Source
const SchemaVersion = "1.0.0"

SchemaVersion is the versioned operator contract schema. All operator method responses include this version in their JSON output. Bumping the major version indicates a breaking change; minor bumps add backward-compatible fields.

Variables

This section is empty.

Functions

func IsValidErrorCategory

func IsValidErrorCategory(cat ErrorCategory) bool

IsValidErrorCategory returns true if cat is a defined ErrorCategory.

func IsValidNextAction

func IsValidNextAction(a NextAction) bool

IsValidNextAction returns true if a is a defined NextAction.

Types

type ConfirmationRequirement

type ConfirmationRequirement struct {
	// RequiresConfirmation is true when the proposed action crosses a trust
	// boundary and needs explicit user/daemon confirmation.
	RequiresConfirmation bool `json:"requires_confirmation"`

	// ConfirmationID is an opaque id the daemon uses to track the pending
	// confirmation. Empty when RequiresConfirmation is false.
	ConfirmationID string `json:"confirmation_id,omitempty"`

	// RiskLevel classifies the potential impact: "low", "medium", or "high".
	RiskLevel RiskLevel `json:"risk_level,omitempty"`

	// Rationale explains why the change is needed and what it does.
	Rationale string `json:"rationale,omitempty"`

	// AffectedDestinations lists network destinations affected by the change
	// (for egress/policy patches). Empty for non-network changes.
	AffectedDestinations []string `json:"affected_destinations,omitempty"`

	// CredentialIDs lists credential ids affected by the change (for
	// credential bindings and direct leases). Empty for non-credential
	// changes.
	CredentialIDs []string `json:"credential_ids,omitempty"`

	// EvidenceRefs points to audit/policy evidence supporting the proposal.
	EvidenceRefs []EvidenceRef `json:"evidence_refs,omitempty"`
}

ConfirmationRequirement encodes the trust-boundary confirmation protocol. When an operator method proposes a trust-boundary change (policy patch, credential binding, direct lease, handoff trigger, exposed listener, retention purge, destructive operation), the response includes this struct with RequiresConfirmation=true. The agentic tool cannot apply the change; only the daemon/UI/CLI confirmation path can.

type ErrorCategory

type ErrorCategory string

ErrorCategory is a stable, versioned enum identifying the category of an operator diagnosis. Categories are part of the public contract: adding a new category is backward-compatible, but renaming or removing one requires a major schema version bump.

const (
	// ErrDependencyConflict indicates a conflicting or missing dependency
	// declaration in the agent project.
	ErrDependencyConflict ErrorCategory = "dependency_conflict"

	// ErrDockerUnavailable indicates the Docker daemon is not running or
	// unreachable.
	ErrDockerUnavailable ErrorCategory = "docker_unavailable"

	// ErrPolicyDenied indicates a policy rule blocked an agent action.
	ErrPolicyDenied ErrorCategory = "policy_denied"

	// ErrMissingSecretBinding indicates a required credential/secret is not
	// bound to the agent project.
	ErrMissingSecretBinding ErrorCategory = "missing_secret_binding"

	// ErrBudgetExceeded indicates the run exceeded its configured budget.
	ErrBudgetExceeded ErrorCategory = "budget_exceeded"

	// ErrTriggerAuthFailed indicates a trigger (webhook/cron) failed
	// authentication.
	ErrTriggerAuthFailed ErrorCategory = "trigger_auth_failed"

	// ErrHarnessHealthFailed indicates the agent harness reported a health
	// check failure.
	ErrHarnessHealthFailed ErrorCategory = "harness_health_failed"

	// ErrAgentRuntimeException indicates the agent process crashed or
	// returned an unhandled exception.
	ErrAgentRuntimeException ErrorCategory = "agent_runtime_exception"

	// ErrPolicyValidationFailed indicates the policy compiler rejected a
	// policy.yaml change.
	ErrPolicyValidationFailed ErrorCategory = "policy_validation_failed"

	// ErrNetworkSandboxFailed indicates the network sandbox blocked or
	// failed an egress attempt.
	ErrNetworkSandboxFailed ErrorCategory = "network_sandbox_failed"

	// ErrSecretScanFailed indicates the packaging secret scanner found
	// sensitive material in the build context.
	ErrSecretScanFailed ErrorCategory = "secret_scan_failed"

	// ErrPackageVerificationFailed indicates package signature or SBOM
	// verification failed.
	ErrPackageVerificationFailed ErrorCategory = "package_verification_failed"

	// ErrDashboardUnavailable indicates the dashboard/OTel endpoint is not
	// reachable.
	ErrDashboardUnavailable ErrorCategory = "dashboard_unavailable"
)

func AllErrorCategories

func AllErrorCategories() []ErrorCategory

AllErrorCategories returns the complete set of defined error categories. Used by schema golden tests to verify every category has a fixture and by the CLI to validate --json output against the enum.

type EvidenceRef

type EvidenceRef struct {
	// Type identifies the kind of evidence.
	//   "audit_seq"     — audit log sequence number(s)
	//   "run_id"        — agent run identifier
	//   "policy_rule"   — policy rule id
	//   "span"          — OTel span id
	//   "log"           — log line id / file offset
	//   "redacted_excerpt" — sanitized excerpt of source/log/trace
	//   "verification"  — command to reproduce the finding
	Type string `json:"type"`

	// Ref is the opaque identifier for the evidence (e.g. "42" for an audit
	// seq, "run_abc123" for a run_id, "egress[2]" for a policy rule).
	Ref string `json:"ref"`

	// Detail is an optional human-readable description of what this evidence
	// proves. It is always redacted: secret values, tokens, and private keys
	// are stripped before inclusion.
	Detail string `json:"detail,omitempty"`
}

EvidenceRef points to an auditable artifact that supports a diagnosis. Evidence refs never contain secret values; they are opaque identifiers a tool can resolve to retrieve the underlying data from the audit log, run store, or policy compiler.

type ExplainFailureResponse

type ExplainFailureResponse struct {
	SchemaVersion string `json:"schema_version"`
	RunID         string `json:"run_id"`

	// ErrorCategory classifies the failure.
	ErrorCategory ErrorCategory `json:"error_category"`

	// RootCause is a concise natural-language description of the root cause.
	RootCause string `json:"root_cause"`

	// RedactedExcerpts are sanitized snippets of source/log/trace that
	// illustrate the failure. Secrets are always stripped.
	RedactedExcerpts []RedactedExcerpt `json:"redacted_excerpts,omitempty"`

	// EvidenceRefs point to the audit spans, log ids, and run state that
	// support this diagnosis.
	EvidenceRefs []EvidenceRef `json:"evidence_refs,omitempty"`

	// NextAction is the recommended operator action to resolve the failure.
	NextAction NextAction `json:"next_action"`
}

ExplainFailureResponse is the operator response for root-cause diagnosis of a failed run.

type ExplainPolicyDenialResponse

type ExplainPolicyDenialResponse struct {
	SchemaVersion string `json:"schema_version"`

	// RunID is the run that was denied (empty for pre-run policy checks).
	RunID string `json:"run_id,omitempty"`

	// DeniedAction describes what the agent tried to do.
	DeniedAction string `json:"denied_action"`

	// BlockingRuleID identifies the policy rule that denied the action
	// (e.g. "egress[2]", "default_deny").
	BlockingRuleID string `json:"blocking_rule_id"`

	// PolicyDigest is the SHA-256 digest of the compiled policy at the time
	// of denial, for audit correlation.
	PolicyDigest string `json:"policy_digest,omitempty"`

	// Rationale explains why the rule blocked the action.
	Rationale string `json:"rationale"`

	// EvidenceRefs point to the audit seq and policy decision that recorded
	// the denial.
	EvidenceRefs []EvidenceRef `json:"evidence_refs,omitempty"`

	// NextAction is always "review_policy_patch" for policy denials.
	NextAction NextAction `json:"next_action"`
}

ExplainPolicyDenialResponse is the operator response for identifying the blocking policy rule for a denied action.

type GetRunTimelineResponse

type GetRunTimelineResponse struct {
	SchemaVersion string          `json:"schema_version"`
	RunID         string          `json:"run_id"`
	Events        []TimelineEvent `json:"events"`
}

GetRunTimelineResponse is the operator response for a chronological event list for a run.

type NextAction

type NextAction string

NextAction is the fixed enum of operator next-action recommendations. An agentic tool returns exactly one NextAction per diagnosis. The values are part of the versioned contract.

const (
	// ActionFixCode: the agent source code has a bug; fix the code and rerun.
	ActionFixCode NextAction = "fix_code"

	// ActionInstallDependency: a dependency is missing; install it and rerun.
	ActionInstallDependency NextAction = "install_dependency"

	// ActionStartDocker: Docker is not running; start it and rerun.
	ActionStartDocker NextAction = "start_docker"

	// ActionSetSecret: a required secret is not bound; bind it and rerun.
	ActionSetSecret NextAction = "set_secret"

	// ActionReviewPolicyPatch: a policy rule blocked the run; review the
	// proposed policy patch and confirm or decline.
	ActionReviewPolicyPatch NextAction = "review_policy_patch"

	// ActionReviewHandoff: a local handoff trigger requires review.
	ActionReviewHandoff NextAction = "review_handoff"

	// ActionIncreaseBudget: the run exceeded its budget; increase the budget
	// and rerun.
	ActionIncreaseBudget NextAction = "increase_budget"

	// ActionRerun: the issue is resolved; rerun the agent.
	ActionRerun NextAction = "rerun"

	// ActionExportAudit: export the audit bundle for external review.
	ActionExportAudit NextAction = "export_audit"

	// ActionAskUser: the operator cannot determine a next action; ask the
	// human user.
	ActionAskUser NextAction = "ask_user"
)

func AllNextActions

func AllNextActions() []NextAction

AllNextActions returns the complete set of defined next-action values.

type NextActionResponse

type NextActionResponse struct {
	SchemaVersion string `json:"schema_version"`

	// RunID is the run context (empty for project-level next actions).
	RunID string `json:"run_id,omitempty"`

	// NextAction is the recommended action from the fixed enum.
	NextAction NextAction `json:"next_action"`

	// Rationale explains why this action is recommended.
	Rationale string `json:"rationale"`

	// EvidenceRefs point to the run/audit/policy state that motivates this
	// recommendation.
	EvidenceRefs []EvidenceRef `json:"evidence_refs,omitempty"`

	// Confirmation is set when NextAction requires confirmation (e.g.
	// "review_policy_patch"). Empty for non-trust-boundary actions.
	Confirmation *ConfirmationRequirement `json:"confirmation,omitempty"`
}

NextActionResponse is the operator response for the next-action recommendation. It returns exactly one NextAction from the fixed enum, with evidence supporting the recommendation.

type RecommendPolicyPatchResponse

type RecommendPolicyPatchResponse struct {
	SchemaVersion string `json:"schema_version"`

	// ProposedPatch is a unified-diff or YAML snippet showing the policy
	// change. It is a proposal, not an applied change.
	ProposedPatch string `json:"proposed_patch"`

	// RiskLevel classifies the impact of the proposed change.
	RiskLevel RiskLevel `json:"risk_level"`

	// Rationale explains why the patch is needed and what it permits.
	Rationale string `json:"rationale"`

	// AffectedDestinations lists network destinations the patch would allow.
	AffectedDestinations []string `json:"affected_destinations,omitempty"`

	// CredentialIDs lists credential ids the patch would bind.
	CredentialIDs []string `json:"credential_ids,omitempty"`

	// EvidenceRefs point to the denial event and audit evidence motivating
	// the patch.
	EvidenceRefs []EvidenceRef `json:"evidence_refs,omitempty"`

	// Confirmation encodes the trust-boundary gate. RequiresConfirmation is
	// always true for policy patches.
	Confirmation ConfirmationRequirement `json:"confirmation"`

	// NextAction is "review_policy_patch" — the human must confirm before
	// the patch is applied.
	NextAction NextAction `json:"next_action"`
}

RecommendPolicyPatchResponse is the operator response for a proposed policy patch. It recommends a change to the policy.yaml but does NOT apply it — the ConfirmationRequirement encodes the trust-boundary gate.

type RedactedExcerpt

type RedactedExcerpt struct {
	// Source identifies where the excerpt came from: a file path, log file
	// name, or span id.
	Source string `json:"source"`

	// StartLine is the 1-based line number where the excerpt starts (for
	// file-based sources). 0 for non-file sources.
	StartLine int `json:"start_line,omitempty"`

	// EndLine is the 1-based line number where the excerpt ends.
	EndLine int `json:"end_line,omitempty"`

	// Content is the redacted text. Secrets are replaced with "[REDACTED]".
	Content string `json:"content"`
}

RedactedExcerpt is a sanitized snippet of source code, log output, or trace data. Secret patterns (bearer tokens, API keys, private keys) are redacted before the excerpt is included in any operator response.

type RiskLevel

type RiskLevel string

RiskLevel classifies the potential impact of a trust-boundary change.

const (
	// RiskLow: the change has minimal security impact (e.g. adding an egress
	// rule for a well-known API with no credentials).
	RiskLow RiskLevel = "low"

	// RiskMedium: the change affects egress scope or credential usage but
	// does not expose secrets or broaden policy silently.
	RiskMedium RiskLevel = "medium"

	// RiskHigh: the change touches trust boundaries — direct leases, exposed
	// listeners, retention purges, or destructive operations.
	RiskHigh RiskLevel = "high"
)

type SummarizeRunResponse

type SummarizeRunResponse struct {
	SchemaVersion string    `json:"schema_version"`
	RunID         string    `json:"run_id"`
	Status        string    `json:"status"` // "completed", "failed", "running", "stopped"
	ExitCode      int       `json:"exit_code,omitempty"`
	StartedAt     time.Time `json:"started_at"`
	FinishedAt    time.Time `json:"finished_at,omitempty"`

	// DurationMS is the wall-clock run duration in milliseconds.
	DurationMS int64 `json:"duration_ms,omitempty"`

	// Summary is a concise natural-language description of the run outcome.
	Summary string `json:"summary"`

	// Invocations is the number of harness invocations during the run.
	Invocations int `json:"invocations,omitempty"`

	// PolicyDenials is the count of policy-denied events during the run.
	PolicyDenials int `json:"policy_denials,omitempty"`

	// ErrorCategory is set when Status is "failed".
	ErrorCategory ErrorCategory `json:"error_category,omitempty"`

	// EvidenceRefs point to the audit/timeline evidence for this summary.
	EvidenceRefs []EvidenceRef `json:"evidence_refs,omitempty"`
}

SummarizeRunResponse is the operator response for a run summary. It provides a structured final result for a completed (or failed) run.

type TimelineEvent

type TimelineEvent struct {
	// Timestamp is when the event occurred (RFC 3339).
	Timestamp time.Time `json:"timestamp"`

	// EventType is a short string: "run_start", "invoke", "policy_denied",
	// "invoke_complete", "run_complete", "run_failed", etc.
	EventType string `json:"event_type"`

	// AuditSeq is the audit log sequence number for this event (0 if not
	// audited).
	AuditSeq int64 `json:"audit_seq,omitempty"`

	// Detail is a concise natural-language description of the event.
	Detail string `json:"detail"`

	// EvidenceRefs point to the audit record and/or span for this event.
	EvidenceRefs []EvidenceRef `json:"evidence_refs,omitempty"`
}

TimelineEvent is a single event in a run timeline.

type ValidateAgentProjectResponse

type ValidateAgentProjectResponse struct {
	// SchemaVersion is the operator contract schema version.
	SchemaVersion string `json:"schema_version"`

	// Ready is true when the project can be packed and run without blocking
	// issues.
	Ready bool `json:"ready"`

	// ProjectDir is the absolute path of the validated project.
	ProjectDir string `json:"project_dir"`

	// Runtime is the detected agent runtime ("python", "langgraph", etc.).
	Runtime string `json:"runtime,omitempty"`

	// Issues lists readiness problems. Empty when Ready is true.
	Issues []ValidationIssue `json:"issues,omitempty"`
}

ValidateAgentProjectResponse is the operator response for project readiness validation. It reports whether the project is ready to pack/run, and if not, lists the specific issues with evidence refs and next actions.

type ValidationIssue

type ValidationIssue struct {
	// Category is the stable error category for this issue.
	Category ErrorCategory `json:"category"`

	// Message is a human-readable description of the issue.
	Message string `json:"message"`

	// EvidenceRefs point to the files/config that caused the issue.
	EvidenceRefs []EvidenceRef `json:"evidence_refs,omitempty"`

	// NextAction is the recommended operator action to resolve this issue.
	NextAction NextAction `json:"next_action"`
}

ValidationIssue is a single readiness problem found during project validation.

Jump to

Keyboard shortcuts

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