Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Add /api/agent/capabilities discovery manifest for agent integrations

rcourtman71797f9b2117
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index f534aed2b4..fadb03c0b1 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -917,6 +917,13 @@ profile and assignment columns, but embedded table framing must route through
## Current State
+`/api/agent/capabilities` is the discovery document any external
+agent reads to learn what Pulse exposes. The manifest is
+unauthenticated and cacheable; the underlying capabilities keep
+their own auth scopes. Adding a capability is a deliberate "this
+is part of the agent surface" commitment so the agent contract
+stays curated, not auto-derived from every internal endpoint.
+
`/api/agent/resource-context/{id}` is the agent-paradigm substrate
endpoint: any agent (in-process Patrol/Assistant or external) reads
the full situated picture of a resource — identity, operator state,
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 2fa5a05ee8..ad86d4f664 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -1343,6 +1343,22 @@ the canonical monitored-system blocked payload.
## Current State
+`/api/agent/capabilities` is the discovery document for Pulse's
+agent surface. The manifest declares each agent-consumable
+capability with stable name (snake_case agent identifier),
+description, category (`context` / `operator-state` / `finding`),
+HTTP method + path, required auth scope, response shape name, and
+the closed set of stable error codes the response may carry. Agents
+fetch this once at startup to learn what's available; future
+MCP-server slices read the manifest to register tools. The manifest
+itself is unauthenticated and cacheable (`Cache-Control: public,
+max-age=300`); the underlying capabilities keep their own auth
+scopes. Adding a capability is a deliberate "this is part of the
+agent surface" commitment — the manifest is hand-authored rather
+than auto-generated so contract decisions (which capabilities are
+agent-stable, what the stable error codes are, what category each
+belongs to) cannot drift behind code changes.
+
`/api/agent/resource-context/{id}` is the agent-consumable bundled
context endpoint. One read returns the full situated picture of a
resource — identity, operator-set state (with server-computed
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index a2b95ca80a..cd6b44f614 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -947,6 +947,11 @@ bypass the API fail-closed execution gate.
## Current State
+The agent capabilities manifest at `/api/agent/capabilities` is
+read-only and stateless — no persistence is involved. The manifest
+is hand-authored in `internal/api/agent_capabilities.go`; storage
+flows are not affected.
+
The agent-consumable bundled context endpoint
`/api/agent/resource-context/{id}` reads the same durable
`resource_operator_state` table and `action_audits` table through the
diff --git a/internal/api/agent_capabilities.go b/internal/api/agent_capabilities.go
new file mode 100644
index 0000000000..0d2da200f0
--- /dev/null
+++ b/internal/api/agent_capabilities.go
@@ -0,0 +1,194 @@
+package api
+
+import (
+ "encoding/json"
+ "net/http"
+)
+
+// AgentCapability declares one agent-consumable capability Pulse
+// exposes — a single point of "here's what you can do and how." The
+// shape is intentionally narrow so a future MCP-server slice can
+// consume the manifest to register tools, and so external agents
+// (Claude Code, custom integrations) can introspect Pulse without
+// reading documentation. Each capability names the canonical REST
+// path, the method, the scope required, and the stable error
+// codes the response may carry — agents branch on those, not on
+// human messages.
+type AgentCapability struct {
+ // Name is the agent-stable identifier for this capability.
+ // snake_case to match the convention agents use for tool names.
+ // MUST be stable across releases — renaming breaks integrations.
+ Name string `json:"name"`
+
+ // Description is a single-sentence explanation an agent can
+ // surface to a user when it's deciding whether to call this
+ // capability. Phrased imperatively ("Get the situated context for
+ // a resource") rather than narratively.
+ Description string `json:"description"`
+
+ // Category groups capabilities for agent UIs. Stable values:
+ // "context" (read-only situated reads), "operator-state"
+ // (per-resource intent writes), "finding" (per-finding lifecycle
+ // actions). Agents can filter the manifest by category.
+ Category string `json:"category"`
+
+ // Method + Path describe the canonical REST surface. Path
+ // segments in `{braces}` are agent-supplied parameters; agents
+ // percent-encode them when they substitute (the canonical IDs
+ // commonly contain colons).
+ Method string `json:"method"`
+ Path string `json:"path"`
+
+ // Scope names the auth scope required to call this capability.
+ // Agents that lack the scope must ask the operator to widen
+ // their token rather than retrying.
+ Scope string `json:"scope"`
+
+ // ResponseShape is the agent-stable name of the response type
+ // (e.g. "AgentResourceContext", "ResourceOperatorState"). Agents
+ // branch on this to know what to parse; future MCP integrations
+ // can map it to tool result schemas.
+ ResponseShape string `json:"responseShape,omitempty"`
+
+ // ErrorCodes is the closed set of stable error codes this
+ // capability may return on failure. Agents branch on these
+ // (e.g. "operator_state_not_set", "operator_state_invalid",
+ // "resource_remediation_locked", "plan_drift") rather than
+ // parsing human messages. Empty list = the capability uses only
+ // generic HTTP-status error responses.
+ ErrorCodes []string `json:"errorCodes,omitempty"`
+
+ // RequestBodyShape, when non-empty, names the agent-stable
+ // request body shape for non-GET capabilities so agents can
+ // validate before sending.
+ RequestBodyShape string `json:"requestBodyShape,omitempty"`
+}
+
+// AgentCapabilitiesManifest is the discovery document for Pulse's
+// agent surface. Any agent that wants to integrate with Pulse fetches
+// this once at startup, learns what's available, and calls the named
+// capabilities. The manifest itself is read-only and unauthenticated
+// (the Pulse capabilities it describes have their own auth scopes).
+type AgentCapabilitiesManifest struct {
+ // Version pins the manifest contract. Agents validate they
+ // understand this version before using the manifest. Bumping
+ // version is reserved for breaking shape changes; additive
+ // capabilities ship under the same version.
+ Version string `json:"version"`
+
+ // Capabilities is the canonical list. Order is stable across
+ // requests so agents can diff snapshots cheaply.
+ Capabilities []AgentCapability `json:"capabilities"`
+}
+
+// agentCapabilitiesManifest is the v1 declaration of Pulse's
+// agent-consumable surface. Hand-authored rather than auto-generated
+// because the contract decisions (which capabilities are
+// agent-stable, what the stable error codes are, what category each
+// belongs to) are product-shaping and must not drift behind code
+// changes. Adding a capability here is a deliberate "this is part of
+// the agent surface" commitment.
+var agentCapabilitiesManifest = AgentCapabilitiesManifest{
+ Version: "v1",
+ Capabilities: []AgentCapability{
+ {
+ Name: "get_resource_context",
+ Description: "Return the situated picture of a resource — identity, operator-set state with maintenance-window-active flag, active findings, recent actions including refused dispatches.",
+ Category: "context",
+ Method: http.MethodGet,
+ Path: "/api/agent/resource-context/{resourceId}",
+ Scope: "monitoring:read",
+ ResponseShape: "AgentResourceContext",
+ ErrorCodes: []string{"resource_not_found"},
+ },
+ {
+ Name: "get_operator_state",
+ Description: "Read the operator-set state for a resource (intentionally offline, never auto-remediate, maintenance window, criticality).",
+ Category: "operator-state",
+ Method: http.MethodGet,
+ Path: "/api/resources/{resourceId}/operator-state",
+ Scope: "monitoring:read",
+ ResponseShape: "ResourceOperatorState",
+ ErrorCodes: []string{"operator_state_not_set"},
+ },
+ {
+ Name: "set_operator_state",
+ Description: "Replace the operator-set state for a resource. URL canonicalId wins over body; server populates setAt and setBy from the authenticated identity.",
+ Category: "operator-state",
+ Method: http.MethodPut,
+ Path: "/api/resources/{resourceId}/operator-state",
+ Scope: "monitoring:write",
+ RequestBodyShape: "ResourceOperatorStateInput",
+ ResponseShape: "ResourceOperatorState",
+ ErrorCodes: []string{"operator_state_invalid"},
+ },
+ {
+ Name: "clear_operator_state",
+ Description: "Remove any operator-set state for a resource. Idempotent — succeeds whether or not an entry was present.",
+ Category: "operator-state",
+ Method: http.MethodDelete,
+ Path: "/api/resources/{resourceId}/operator-state",
+ Scope: "monitoring:write",
+ },
+ {
+ Name: "list_findings",
+ Description: "List all Patrol findings (active, dismissed, resolved). Filter client-side on returned shape.",
+ Category: "finding",
+ Method: http.MethodGet,
+ Path: "/api/ai/patrol/findings",
+ Scope: "monitoring:read",
+ ResponseShape: "Finding[]",
+ },
+ {
+ Name: "acknowledge_finding",
+ Description: "Mark a finding as seen but keep it visible. Auto-resolves when the underlying condition clears.",
+ Category: "finding",
+ Method: http.MethodPost,
+ Path: "/api/ai/patrol/acknowledge",
+ Scope: "monitoring:write",
+ RequestBodyShape: "{ finding_id: string }",
+ },
+ {
+ Name: "snooze_finding",
+ Description: "Hide a finding for a defined duration in hours.",
+ Category: "finding",
+ Method: http.MethodPost,
+ Path: "/api/ai/patrol/snooze",
+ Scope: "monitoring:write",
+ RequestBodyShape: "{ finding_id: string, duration_hours: number }",
+ },
+ {
+ Name: "dismiss_finding",
+ Description: "Dismiss a finding with a reason: not_an_issue (permanent suppression), expected_behavior (acknowledged forever), or will_fix_later (7-day reminder commitment).",
+ Category: "finding",
+ Method: http.MethodPost,
+ Path: "/api/ai/patrol/dismiss",
+ Scope: "monitoring:write",
+ RequestBodyShape: "{ finding_id: string, reason: \"not_an_issue\"|\"expected_behavior\"|\"will_fix_later\", note?: string }",
+ },
+ {
+ Name: "resolve_finding",
+ Description: "Manually mark a finding as resolved when the underlying issue has been fixed out-of-band.",
+ Category: "finding",
+ Method: http.MethodPost,
+ Path: "/api/ai/patrol/resolve",
+ Scope: "monitoring:write",
+ RequestBodyShape: "{ finding_id: string }",
+ },
+ },
+}
+
+// HandleAgentCapabilitiesManifest serves
+// `GET /api/agent/capabilities` — the discovery document for Pulse's
+// agent surface. Cacheable, unauthenticated (the underlying
+// capabilities have their own scopes); agents fetch this once and
+// learn what's available.
+func HandleAgentCapabilitiesManifest(w http.ResponseWriter, r *http.Request) {
+ if r.Method != http.MethodGet {
+ http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
+ return
+ }
+ w.Header().Set("Content-Type", "application/json")
+ w.Header().Set("Cache-Control", "public, max-age=300")
+ _ = json.NewEncoder(w).Encode(agentCapabilitiesManifest)
+}
diff --git a/internal/api/agent_capabilities_test.go b/internal/api/agent_capabilities_test.go
new file mode 100644
index 0000000000..884d68a816
--- /dev/null
+++ b/internal/api/agent_capabilities_test.go
@@ -0,0 +1,146 @@
+package api
+
+import (
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "testing"
+)
+
+func TestHandleAgentCapabilitiesManifest_ReturnsStableShape(t *testing.T) {
+ rec := httptest.NewRecorder()
+ req := httptest.NewRequest(http.MethodGet, "/api/agent/capabilities", nil)
+ HandleAgentCapabilitiesManifest(rec, req)
+
+ if rec.Code != http.StatusOK {
+ t.Fatalf("expected 200; got %d", rec.Code)
+ }
+ if got := rec.Header().Get("Content-Type"); got != "application/json" {
+ t.Errorf("Content-Type: got %q want application/json", got)
+ }
+ // Cacheable so agents can hold the manifest in memory across
+ // requests; 5 minutes mirrors the typical agent session length.
+ if got := rec.Header().Get("Cache-Control"); got == "" {
+ t.Error("manifest must be cacheable; Cache-Control header missing")
+ }
+
+ var manifest AgentCapabilitiesManifest
+ if err := json.Unmarshal(rec.Body.Bytes(), &manifest); err != nil {
+ t.Fatalf("unmarshal manifest: %v", err)
+ }
+
+ if manifest.Version != "v1" {
+ t.Errorf("version pin: got %q want v1", manifest.Version)
+ }
+ if len(manifest.Capabilities) == 0 {
+ t.Fatal("manifest must declare at least one capability")
+ }
+}
+
+func TestHandleAgentCapabilitiesManifest_RejectsNonGet(t *testing.T) {
+ rec := httptest.NewRecorder()
+ req := httptest.NewRequest(http.MethodPost, "/api/agent/capabilities", nil)
+ HandleAgentCapabilitiesManifest(rec, req)
+ if rec.Code != http.StatusMethodNotAllowed {
+ t.Fatalf("expected 405; got %d", rec.Code)
+ }
+}
+
+func TestAgentCapabilitiesManifest_NamesAreUniqueAndSnakeCase(t *testing.T) {
+ // Capability names are agent-stable identifiers — duplicates
+ // would silently mask one capability behind another, and
+ // non-snake_case would break the convention agents use for tool
+ // names. Pin both invariants.
+ seen := map[string]bool{}
+ for _, cap := range agentCapabilitiesManifest.Capabilities {
+ if seen[cap.Name] {
+ t.Errorf("duplicate capability name %q — names are agent-stable identifiers", cap.Name)
+ }
+ seen[cap.Name] = true
+
+ if cap.Name == "" {
+ t.Error("capability name must not be empty")
+ continue
+ }
+ for _, ch := range cap.Name {
+ if !(ch == '_' || (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')) {
+ t.Errorf("capability name %q must be snake_case (lowercase letters, digits, underscores only); got rune %q", cap.Name, ch)
+ break
+ }
+ }
+ }
+}
+
+func TestAgentCapabilitiesManifest_EveryCapabilityDeclaresMethodPathScope(t *testing.T) {
+ // Without method/path/scope, an agent can't actually call the
+ // capability. These three are the minimum viable contract.
+ for _, cap := range agentCapabilitiesManifest.Capabilities {
+ if cap.Method == "" {
+ t.Errorf("capability %q missing method", cap.Name)
+ }
+ if cap.Path == "" {
+ t.Errorf("capability %q missing path", cap.Name)
+ }
+ if cap.Scope == "" {
+ t.Errorf("capability %q missing scope", cap.Name)
+ }
+ if cap.Description == "" {
+ t.Errorf("capability %q missing description", cap.Name)
+ }
+ if cap.Category == "" {
+ t.Errorf("capability %q missing category — agents filter the manifest by category", cap.Name)
+ }
+ }
+}
+
+func TestAgentCapabilitiesManifest_CategoriesAreClosed(t *testing.T) {
+ // Agents filter the manifest by category. Keep the set closed
+ // so a typo in a future capability doesn't fragment the surface
+ // (e.g. "operator-state" vs "operator_state" would split into
+ // two categories an agent might miss).
+ allowed := map[string]bool{
+ "context": true,
+ "operator-state": true,
+ "finding": true,
+ }
+ for _, cap := range agentCapabilitiesManifest.Capabilities {
+ if !allowed[cap.Category] {
+ t.Errorf("capability %q has unknown category %q — extend the allowlist deliberately", cap.Name, cap.Category)
+ }
+ }
+}
+
+func TestAgentCapabilitiesManifest_CarriesStableErrorCodes(t *testing.T) {
+ // The error-code surface is the agent-branching contract. The
+ // codes I've shipped this session must appear on the
+ // corresponding capability so agents can branch on them. Pin a
+ // few of the most consequential codes.
+ wantErrorCodes := map[string][]string{
+ "get_resource_context": {"resource_not_found"},
+ "get_operator_state": {"operator_state_not_set"},
+ "set_operator_state": {"operator_state_invalid"},
+ }
+ byName := map[string]AgentCapability{}
+ for _, cap := range agentCapabilitiesManifest.Capabilities {
+ byName[cap.Name] = cap
+ }
+ for name, expected := range wantErrorCodes {
+ cap, ok := byName[name]
+ if !ok {
+ t.Errorf("capability %q missing from manifest", name)
+ continue
+ }
+ for _, code := range expected {
+ found := false
+ for _, declared := range cap.ErrorCodes {
+ if declared == code {
+ found = true
+ break
+ }
+ }
+ if !found {
+ t.Errorf("capability %q must declare error code %q so agents can branch on it; declared codes: %v", name, code, cap.ErrorCodes)
+ }
+ }
+ }
+}
diff --git a/internal/api/contract_test.go b/internal/api/contract_test.go
index 6014203879..943c6130b2 100644
--- a/internal/api/contract_test.go
+++ b/internal/api/contract_test.go
@@ -13233,6 +13233,38 @@ func assertJSONSnapshot(t *testing.T, got []byte, want string) {
}
}
+// TestContract_AgentCapabilitiesManifestVersionIsPinned pins the
+// manifest's version contract: bumping it is reserved for breaking
+// shape changes, additive capabilities ship under the same version.
+// Pinning the version string here means a refactor that accidentally
+// bumps it shows up as a test failure rather than silently breaking
+// every external agent that validates compatibility on startup.
+func TestContract_AgentCapabilitiesManifestVersionIsPinned(t *testing.T) {
+ source, err := os.ReadFile("agent_capabilities.go")
+ if err != nil {
+ t.Fatalf("read agent_capabilities.go: %v", err)
+ }
+ src := string(source)
+ if !strings.Contains(src, `Version: "v1"`) {
+ t.Error("agent capabilities manifest must pin Version to v1; bumping is a breaking-change decision and should not happen silently")
+ }
+ // Capability surface anchors — these names are agent-stable
+ // identifiers and renaming any of them breaks every external
+ // integration. Pin them here so renames must be deliberate.
+ required := []string{
+ "\"get_resource_context\"",
+ "\"get_operator_state\"",
+ "\"set_operator_state\"",
+ "\"clear_operator_state\"",
+ "\"list_findings\"",
+ }
+ for _, name := range required {
+ if !strings.Contains(src, name) {
+ t.Errorf("agent capabilities manifest must declare canonical capability %s", name)
+ }
+ }
+}
+
// TestContract_AgentResourceContextEndpointSurfacesStableShape pins
// the agent-paradigm substrate contract: the bundled endpoint must
// return arrays (never null) for activeFindings and recentActions so
diff --git a/internal/api/route_inventory_test.go b/internal/api/route_inventory_test.go
index 873dcc8255..32d53a2a32 100644
--- a/internal/api/route_inventory_test.go
+++ b/internal/api/route_inventory_test.go
@@ -411,6 +411,7 @@ var allRouteAllowlist = []string{
"/api/resources/{id}/timeline",
"/api/resources/{id}/operator-state",
"/api/agent/resource-context/{id}",
+ "/api/agent/capabilities",
"POST /api/actions/plan",
"POST /api/actions/{id}/decision",
"POST /api/actions/{id}/execute",
diff --git a/internal/api/router_routes_monitoring.go b/internal/api/router_routes_monitoring.go
index 8bd95f6233..c91a43d4b0 100644
--- a/internal/api/router_routes_monitoring.go
+++ b/internal/api/router_routes_monitoring.go
@@ -63,6 +63,11 @@ func (r *Router) registerMonitoringResourceRoutes(
// situated picture of a resource in one read instead of chaining
// resource + operator-state + findings + audit calls.
r.mux.HandleFunc("/api/agent/resource-context/{id}", RequireAuth(r.config, RequireScope(config.ScopeMonitoringRead, r.agentContextHandler.HandleResourceContext)))
+ // Agent capabilities manifest — discovery document. Unauthenticated
+ // because it only describes the agent surface; the capabilities
+ // themselves keep their own auth scopes. Agents fetch this once at
+ // startup to learn what's available.
+ r.mux.HandleFunc("/api/agent/capabilities", HandleAgentCapabilitiesManifest)
r.mux.HandleFunc("POST /api/actions/plan", RequireAuth(r.config, RequireScope(config.ScopeAIExecute, r.resourceHandlers.HandlePlanAction)))
r.mux.HandleFunc("POST /api/actions/{id}/decision", RequireAuth(r.config, RequireScope(config.ScopeAIExecute, r.resourceHandlers.HandleDecideAction)))
r.mux.HandleFunc("POST /api/actions/{id}/execute", RequireAuth(r.config, RequireScope(config.ScopeAIExecute, r.resourceHandlers.HandleExecuteAction)))