Commit Graph

60 Commits

Author SHA1 Message Date
rcourtman 03463c1bfe Thread per-tenant AI narrators into pulse_summarize via chat session
v1 of pulse_summarize (1fe5d6853) shipped with heuristic narrative
only. The follow-up wiring promised in that commit now lands: the
chat session carries optional report-narration providers that the
tool's handler reads when building requests, so AI-narrated synthesis
flows into chat using the same provider, sanitizer, model selection,
cost ledger, and budget gate the report PDF endpoint already uses.

Pipeline:
- pkg/reporting Narrator / FleetNarrator / FindingsProvider interfaces
  are already implemented by internal/ai.Service. No new
  implementations.
- tools.ExecutorConfig + PulseToolExecutor gain three optional fields
  (ReportNarrator, ReportFleetNarrator, ReportFindingsProvider).
  Clone() copies them so per-session executors inherit the wiring.
- chat.Config gains the same three fields; NewService threads them
  into ExecutorConfig.
- tools_summarize.go reads e.reportNarrator/FleetNarrator/
  FindingsProvider and populates MetricReportRequest /
  MultiReportRequest. The engine already accepts these on the request
  and falls back to heuristic when they are nil — no engine changes
  needed.
- AIHandler gains SetReportNarratorResolver(ctx -> narrators); both
  per-tenant and default chat.Config construction sites invoke the
  resolver. Router wires the resolver to AISettingsHandler.GetAIService
  with the same Enabled-gate the reporting handler uses.

Unconfigured tenants are unchanged: the resolver returns nil, the
tool returns heuristic narrative — identical to today. Configured
tenants get AI synthesis in chat that matches what their report PDF
already carries, billed and budget-gated the same way.
2026-05-10 22:50:17 +01:00
rcourtman 52669128e6 Drop redundant policy gates in resource-link routing
Tail of the operator-local-UI redaction sweep (abdde303a, a17f879a1).

resolveKubernetesContextForResource gated on requiresGovernedResourceDisplay
to choose between getPreferredInfrastructureDisplayName and a manual
displayName-or-name fallback. Both branches produce a raw infra name
once we trust that displayName never carries a redacted summary in
local rendering, so the gate is dead complexity. Collapse to a single
call and drop the now-unused requiresGovernedResourceDisplay import.

problemResourcePresentation.getProblemResourceDisplayName has no
production consumers today, but it still routes through the governed
helper. Reclassify it now (same as every other operator-local helper)
so the rule is consistent across the codebase if the surface ever gets
adopted.
2026-05-09 21:31:45 +01:00
rcourtman b5c8e00859 Preserve previous successful fix across regressions
Capture the prior InvestigationRecord.ProposedFix.Description into a
new Finding.PreviousResolvedFixSummary field at regression time, before
the InvestigationRecord is cleared. Without this capture the next
investigation starts from blank context whenever a finding regresses,
and operational memory of "what worked last time" is lost.

The summary propagates through:
- FindingsStore.Add regression branch (capture before clear)
- Finding.MarshalJSON / UnmarshalJSON (wire shape)
- Both Finding to UnifiedFinding conversion sites in router.go
- UnifiedFinding (struct + JSON shadow + Marshal/Unmarshal)
- UnifiedStore.AddFromAI update branch (non-empty overwrite)
- Assistant chat context as a "Previous Resolved Fix" line so the LLM
  sees what worked previously rather than blank-slate diagnosing each
  regression.

Adds a unit test that walks the full lifecycle (detect, resolve via
UpdateInvestigationRecord + ResolveWithReason, re-detect) and asserts
PreviousResolvedFixSummary is preserved while InvestigationRecord is
cleared, plus two chat-context tests covering the surfaces-when-set and
omits-when-empty cases. Adds a contract test pinning the canonical
"previous_resolved_fix_summary" JSON key. Updates the api-contracts,
ai-runtime, and the dependent agent-lifecycle, performance-and-
scalability, and storage-recovery contracts to pin the operational
memory propagation rule and its scope boundary.
2026-05-08 19:45:44 +01:00
rcourtman dd15d23a35 Hydrate Patrol requester in Assistant handoffs
- hydrate approval requester identity into backend handoff actions
- include requester provenance in refreshed finding action context
- document the backend requester authority boundary
2026-05-08 00:26:04 +01:00
rcourtman bbaa6c0a6c Cover Patrol handoff approval mode
- force non-empty Patrol finding handoffs into approval-required mode

- add direct helper coverage for finding, scoped, resource, action, and metadata handoffs

- align subsystem contracts with the backend-owned clamp
2026-05-07 23:08:56 +01:00
rcourtman d9331d39e4 Move Patrol run Assistant handoffs server-side
- rehydrate Patrol run context from Patrol history for chat requests and follow-up sessions
- send only browser-safe run metadata from the frontend
- classify and redact provider runtime failures in handoff prompts and briefings
2026-05-07 21:58:06 +01:00
rcourtman ff9cb5c133 Restore Patrol run Assistant session identity
Refs #1463
2026-05-07 15:53:59 +01:00
rcourtman 6b4e4d7fe6 Merge Patrol handoff context into Assistant requests 2026-05-07 11:58:02 +01:00
rcourtman a66b80ceb9 Carry structured Patrol actions into Assistant handoffs 2026-05-07 10:48:15 +01:00
rcourtman 7aaf76d03c Carry live approval lifecycle into Assistant handoffs 2026-05-07 10:25:14 +01:00
rcourtman 812c86692d Route Assistant handoffs through model context 2026-05-07 03:00:58 +01:00
rcourtman 2c913fac8e Clamp Patrol finding chat handoffs to approval mode 2026-05-07 01:31:45 +01:00
rcourtman bf0e4e16ac Align Assistant briefings with handoff actions 2026-05-07 00:38:42 +01:00
rcourtman b8bad16d80 Recover live Patrol approvals for Assistant handoffs 2026-05-07 00:31:44 +01:00
rcourtman 1fc66cf0cb Add attention reasons to Assistant briefings 2026-05-06 23:39:33 +01:00
rcourtman 6b51a15dfe Frame Assistant operator decisions 2026-05-06 23:30:11 +01:00
rcourtman eb88119a29 Add evidence cues to Assistant briefings 2026-05-06 23:17:33 +01:00
rcourtman c50f051e13 Add evidence cues to Assistant briefings 2026-05-06 23:10:32 +01:00
rcourtman 2fd85f62d3 Add related finding recency to Assistant handoffs 2026-05-06 22:50:18 +01:00
rcourtman 1f424523da Surface Assistant finding lifecycle context 2026-05-06 21:21:35 +01:00
rcourtman 6269bc2afa Enrich Assistant related finding handoffs 2026-05-06 21:14:09 +01:00
rcourtman 67974f2ada Add Assistant operator briefing handoff 2026-05-06 20:48:25 +01:00
rcourtman 2e85079263 Hydrate Assistant finding lifecycle context 2026-05-06 19:54:04 +01:00
rcourtman 2832bd321e Invalidate stale Assistant handoff context 2026-05-06 19:36:05 +01:00
rcourtman 50fee63c9e Refresh Assistant handoff finding context 2026-05-06 19:16:57 +01:00
rcourtman 5c8070c582 Persist Assistant handoff action references 2026-05-06 18:26:21 +01:00
rcourtman aeede4fb2f Hydrate Assistant handoff resource scope 2026-05-06 17:59:55 +01:00
rcourtman 7de85ff257 Keep Patrol handoff context model-only in Assistant 2026-05-06 17:37:19 +01:00
rcourtman 87ba22b0fc Surface Patrol investigation records in Assistant context 2026-05-06 17:00:05 +01:00
rcourtman f67f877f95 Clamp AI control settings to entitlements 2026-04-30 12:38:17 +01:00
rcourtman bd138beeca Improve Pulse Assistant approval continuity 2026-04-24 09:13:39 +01:00
rcourtman cc7b0980ec refactor(truenas): centralize legacy host type canonicalization 2026-03-30 13:22:50 +01:00
rcourtman 2fdf0e16c8 Support enterprise mobile approval proof backend 2026-03-29 21:52:18 +01:00
rcourtman 56c14ca19f feat(ai): add canonical truenas app config reads 2026-03-29 20:36:43 +01:00
rcourtman 298b23626b feat(ai): add canonical truenas app log reads 2026-03-29 20:13:39 +01:00
rcourtman b0ba88d541 feat(ai): add canonical truenas app control 2026-03-29 19:50:31 +01:00
rcourtman 6a0f564a10 fix(hosted): align tenant AI runtime with hosted lease bootstrap 2026-03-25 16:55:31 +00:00
rcourtman 2ac8a1fef9 fix(hosted): auto-bootstrap AI quickstart for hosted tenants 2026-03-25 16:04:49 +00:00
rcourtman cc806171dc Trim dead resource graph surface 2026-03-19 14:26:30 +00:00
rcourtman 778a2577b6 feat: Pulse v6 release 2026-03-18 16:06:30 +00:00
rcourtman e137f3fbf7 fix(ai): start chat service on first-time configure without restart
When Pulse starts before AI is configured, legacyService is nil.
Saving AI settings called Restart() which bailed immediately on the
nil check, leaving the service unstarted (503 on /api/ai/sessions)
until a full process restart.

Merged the nil and !IsRunning checks so first-time configure now
starts the service inline, same as the already-handled stopped case.

Also: bare model names that ParseModelString routes to Ollama (e.g.
"qwen3-omni") now fall back to a configured custom OpenAI base URL
when Ollama is not explicitly configured — handles manually-typed
model names on self-hosted OpenAI-compatible endpoints.

Fixes #1339, #1296
2026-03-13 11:13:27 +00:00
rcourtman 743ef17b79 Fix AI and config profile handlers broken in v5 single-tenant mode
The single-tenant lockdown (499ab812e) set mtPersistence to nil but
only patched AISettingsHandler with a legacy fallback. AIHandler (chat
service) and ConfigProfileHandler were missed, so AI features (Patrol,
Chat) failed with "chat service not available" and config profiles
would panic on nil dereference. Wire legacy persistence into both
handlers and add the same fallback to ProfileSuggestionHandler.

Fixes #1322
2026-03-06 11:05:01 +00:00
rcourtman d1f76982ec fix: finding drawer actions (notes persist, acknowledge visual, discuss context)
- Sync UserNote, AcknowledgedAt, SnoozedUntil, DismissedReason, Suppressed,
  and TimesRaised from ai.Finding to unified store in both callback and
  startup sync paths. Mirror note writes to unified store immediately.
- Dim acknowledged findings (opacity-60), add "Acknowledged" badge, hide
  acknowledge button once acknowledged, sort below unacknowledged in
  severity mode.
- Pass finding_id through frontend chat API → backend ChatRequest →
  ExecuteRequest. Look up full finding from unified store (mutex-guarded)
  and prepend structured context to the prompt.
2026-02-02 15:18:51 +00:00
rcourtman 95a0d7a6bd feat(backend): implement AI Patrol, Investigation, and system-wide refactors 2026-01-30 19:02:14 +00:00
rcourtman 9dcd859056 Update API handlers for AI and discovery endpoints
API layer updates:

AI Handlers:
- Better streaming response handling
- Improved error responses
- Session management improvements

Discovery Handlers:
- New discovery endpoint handlers
- Storage config handler
- Better router organization

Removed deprecated aidiscovery handlers in favor of unified approach.
2026-01-28 16:51:35 +00:00
rcourtman 7f7edfceb4 test: expand backend coverage 2026-01-25 21:08:44 +00:00
rcourtman 27f1a11acb feat: add AI Intelligence system with investigation and forecasting
Major new AI capabilities for infrastructure monitoring:

Investigation System:
- Autonomous finding investigation with configurable autonomy levels
- Investigation orchestrator with rate limiting and guardrails
- Safety checks for read-only mode enforcement
- Chat-based investigation with approval workflows

Forecasting & Remediation:
- Trend forecasting for resource capacity planning
- Remediation engine for generating fix proposals
- Circuit breaker for AI operation protection

Unified Findings:
- Unified store bridging alerts and AI findings
- Correlation and root cause analysis
- Incident coordinator with metrics recording

New Frontend:
- AI Intelligence page with patrol controls
- Investigation drawer for finding details
- Unified findings panel with actions

Supporting Infrastructure:
- Learning store for user preference tracking
- Proxmox event ingestion and correlation
- Enhanced patrol with investigation triggers
2026-01-24 22:41:43 +00:00
rcourtman 8bf31214f5 feat: enhance API handlers and router with new endpoints
- Add new AI handler endpoints
- Enhance diagnostics API
- Improve router configuration
2026-01-22 22:31:24 +00:00
rcourtman 289d95374f feat: add multi-tenancy foundation (directory-per-tenant)
Implements Phase 1-2 of multi-tenancy support using a directory-per-tenant
strategy that preserves existing file-based persistence.

Key changes:
- Add MultiTenantPersistence manager for org-scoped config routing
- Add TenantMiddleware for X-Pulse-Org-ID header extraction and context propagation
- Add MultiTenantMonitor for per-tenant monitor lifecycle management
- Refactor handlers (ConfigHandlers, AlertHandlers, AIHandlers, etc.) to be
  context-aware with getConfig(ctx)/getMonitor(ctx) helpers
- Add Organization model for future tenant metadata
- Update server and router to wire multi-tenant components

All handlers maintain backward compatibility via legacy field fallbacks
for single-tenant deployments using the "default" org.
2026-01-22 13:39:06 +00:00
rcourtman ecc31730f6 Remove OpenCode references 2026-01-20 16:56:41 +00:00