Commit Graph

9 Commits

Author SHA1 Message Date
rcourtman
182067027f Push alert and status changes to the agent event stream
An agent holding /api/agent/events open heard about findings, approvals
and action completions, but not about the facts it most often has to
react to: an alert firing or clearing, or a resource going down. Pulse
already records those as resource changes that list_recent_changes
reads; this publishes them live as alert.fired, alert.resolved and
resource.status_changed, so agents and Pulse MCP --emit-notifications
clients can react without polling.

The monitor adapter tells an observer about each change after the store
accepts it, with the resource ID resolved to the canonical identity it
was stored under. Registry diffs are announced after the new generation
is swapped in. Alert rows are announced only from the alert manager's
live lifecycle callback through RecordLiveChange; lifecycle replay,
active-alert reconciliation and imported history keep using RecordChange,
so a restart never re-announces old alerts. Nothing new is persisted and
nothing is read back from the store, so there are no extra disk writes.

Payloads mirror the timeline record (changeId, kind, canonical
resourceId, current name and type, from/to or alert identifier, type,
level and resolution) and never carry alert messages, change reasons or
command metadata. Only state transitions whose status field changed
count as status events. Status changes are coalesced per resource over
30 seconds: the first is immediate, later ones fold into at most one
event per window, and a flap that returns to the announced status
publishes nothing. Change events carry the recording monitor's
organization and reach only subscribers in that organization.
2026-10-29 07:09:15 +00:00
rcourtman
32d8fd308e Let agents read what changed across the fleet
Pulse keeps 30 days of observed resource changes, but the agent
capability manifest, and so Pulse MCP, only exposed the five most recent
changes per resource inside get_resource_context. An assistant asked
"what happened overnight?" had no tool to answer it.

list_recent_changes (GET /api/agent/changes, monitoring:read) reads the
existing change store with since/before/resourceId/kind/sourceType
filters, a limit capped at 200 and a truncated flag. It writes nothing,
so it adds no disk load. Each change carries the resource's current name
and type, and history for removed resources stays readable.

The raw /api/resources/timeline route returns command text and output
excerpts to read-only tokens. This route instead applies the agent
redaction rule: without ai:execute, command and runbook changes keep only
allowlisted metadata and the command is cut from the reason.

The shared projection now forwards integral JSON numbers as query
parameters, so manifest integer filters such as limit reach GET routes
through MCP instead of being dropped.
2026-10-29 06:41:57 +00:00
pulse-triage[bot]
fba39a8d4c test(api): own router worker cleanup in early API fixtures
Register router cleanup before assertions, stop workers before stores and stop the owned monitor last. Add a subtest-boundary lifecycle cancellation and worker-join regression. Focused API tests pass; this fixture isolation repair does not establish causality for historical release stress failures.

Change-source: pulse-maintainer
2026-09-08 21:29:36 +01:00
rcourtman
cd7886aa44 Enforce server-owned action approval authority 2026-07-11 19:49:17 +01:00
rcourtman
ee8a24e14a backend and governance: MCP contract, agent capabilities, API, and release-control
Manifest-backed MCP tools, prompts, and resources with surface affordance contracts; agent capability manifest and governance projection; API contract tests and capability route projection; operations-loop and intelligence-funnel telemetry; release-control subsystem documentation, registry, and tooling; licensing and configuration.
2026-06-23 17:26:15 +01:00
rcourtman
aa4a5fa631 Add agent provisioning capabilities 2026-05-28 16:31:19 +01:00
rcourtman
728c42e47b Bring action endpoints onto the agent surface with the agent-stable envelope
Closes the last known gap in the agent substrate. The three
action endpoints (POST /api/actions/plan, /api/actions/{id}/decision,
/api/actions/{id}/execute) previously emitted the platform-wide
APIError shape (stable code under "code", human under "error").
The agent surface uses the inverted shape (stable code under
"error", human under "message"), so adding action capabilities
to the manifest as-is would have forced agents to remember which
envelope each capability uses.

The slice refactors actions.go to emit the agent-stable envelope
across all 42 writeErrorResponse call sites. writeJSONError gains
a writeJSONErrorWithDetails sibling so the 13 calls that pass
field-level reasons (validation failures) preserve that
information under a new optional `details` field. The action
endpoints' JSON shape becomes:

  {"error": "<stable_code>", "message": "<human>",
   "details"?: {"<field>": "<reason>"}}

Frontend impact: zero. Verified that no frontend code consumes
the three action endpoints; the refactor is API-only.

Three new manifest entries (plan_action, decide_action,
execute_action) under a new "action" category, with their
declared error codes pinned per capability. Internal-failure 5xx
codes (audit-store outages, encode failures) are not declared
per capability; agents branch on 5xx generically.
TestContract_AgentSurfaceErrorCodesMatchManifestDeclarations now
audits actions.go alongside the existing two handler files, with
a documented internal-only allowlist for the 5xx codes.

The TestAgentSubstrate_ActionEndpointsEmitAgentStableEnvelope e2e
test exercises one error path through each endpoint via the actual
HTTP boundary, asserting the agent-stable envelope reaches the
wire and the legacy APIError fields (code, status_code, timestamp)
do NOT — drift back would mean the refactor regressed.

The TestContract_ActionDryRunOnlyExecutionErrorJSONSnapshot pin
is updated to match the new envelope shape; the manifest's
category allowlist gains "action".

api-contracts.md documents the new envelope (with details map),
the action governance loop's place in the substrate, the
ai:execute scope distinction from monitoring:write, and the
"manifest projection has a footnote" trade-off: bringing an
existing endpoint into the agent surface may require migrating
its error envelope, but the substrate keeps a single envelope
contract rather than carrying a translation wrapper layer.
agent-lifecycle.md and storage-recovery.md document the action
surface joining the agent paradigm and its zero-new-persistence
posture respectively. AGENT_SUBSTRATE.md's "what it does not do
yet" no longer lists the action surface; it now reflects the
real outstanding items (consumer feedback, an in-Pulse agent
integrations panel, a distribution path for pulse-mcp).
2026-05-10 15:16:17 +01:00
rcourtman
5156c03eed End-to-end test the operator-state write loop through HTTP
Closes the e2e contract proof on the write side. The only write
capability the manifest declares is the operator-state intent
loop (set / get / clear), and this test boots the full router
stack to walk every state of that loop through the actual HTTP
boundary — proving the manifest's declared error codes for
set_operator_state and get_operator_state reach the wire from
the handlers, the URL canonical id authoritatively wins over
body-supplied ids (no scope-confusion writes), and SetAt/SetBy
are server-populated so attribution cannot be spoofed.

The flow exercised:
  GET unset → 404 operator_state_not_set
  PUT valid → 200 with persisted state + server SetAt
  GET → round-trips
  PUT invalid criticality → 400 operator_state_invalid
  DELETE → 204
  GET → 404 operator_state_not_set (loop closed)
  DELETE again → 204 (idempotent)

Two contract pins lock the audit-honesty and error-token
contracts so a future refactor of the handler can't silently
regress either: SetAt/SetBy populated server-side, URL-id wins
over body-id, and the validator's domain error maps to the
stable wire token via errors.Is rather than message-matching.

Together with the read-side e2e (slice 47), the agent surface —
read, write, push — has now been exercised end-to-end as one
substrate.
2026-05-09 22:22:47 +01:00
rcourtman
8cf15fe639 End-to-end test the agent substrate's discovery → triage → depth flow
The unit tests cover each piece in isolation; this test boots the
full router stack and proves the discovery → triage → depth chain
works as one substrate through the actual HTTP boundary an
external agent would hit. It found two real bugs slice 40
introduced and slice 45/46 didn't surface:

- /api/agent/capabilities was documented as unauthenticated but
  was missing from the router's publicPaths list, so the global
  auth middleware was 401'ing the discovery manifest. Fixed by
  adding the path to publicPaths and pinning the contract so it
  cannot regress.

- The error-envelope shape across the agent surface is
  {"error": "<stable_code>", "message": "<human>"}, written via
  writeJSONError — not the {"code": ...} shape I had assumed in
  the docs. Pinned the wire shape on api-contracts.md so the
  documented error contract matches what writeJSONError actually
  writes.

The e2e test exercises capabilities discovery, triage via
fleet-context, and depth via resource-context with an unknown id
to confirm the resource_not_found stable error code reaches the
wire under the canonical "error" key. The subscribe_events SSE
path is probed unauthenticated to confirm it's gated (401) rather
than 404 — discovery's claim is honest.
2026-05-09 22:16:32 +01:00