Commit Graph

1944 Commits

Author SHA1 Message Date
rcourtman e4ec73a4cb feat(ai): add finding validation layer to reduce patrol noise
- Add validateAIFindings() that cross-checks AI findings against actual metrics
- Filter out low-confidence findings (CPU <50%, memory <60%, disk <70%)
- Always allow critical findings, backup issues, and reliability findings through
- Update AI system prompt with stricter thresholds and explicit noise examples
- Add 'before creating a finding' checklist for AI (the 3am test)
- Update AI.md docs with clear value proposition and expectations
- Add comprehensive tests for the validation layer

This ensures paying users get immediate value without noise.
2025-12-22 23:28:09 +00:00
rcourtman baa5f8cf6a chore: AI patrol and baseline improvements
- Enhanced patrol finding display in Alerts.tsx
- Improved baseline store with better error handling
- Added clean thinking test coverage
- Updated patrol logic for better finding management
2025-12-22 23:12:11 +00:00
rcourtman 0001d1cbbc feat: add PBS datastores to unified Storage view (#869)
PBS datastores are now displayed in the Storage overview alongside PVE
storage. Each PBS datastore is converted to a Storage entry with:
- type: 'pbs'
- content: 'backup'
- shared: true
- active: based on PBS instance status

This provides a complete picture of all storage resources in one view
while keeping detailed PBS info in the dedicated PBS section.

Closes #869
2025-12-22 22:12:04 +00:00
rcourtman 16b383ced9 fix: use configured Guest URLs for PVE/PBS/PMG navigation (#870)
- Fix PVE nodes: buildNodeUrl in ProxmoxNodesSection.tsx now prioritizes
  guestURL over host (was ignoring guestURL entirely)
- Add PBS support: GuestURL field added to PBSInstance config, model,
  and API handlers
- Add PMG support: GuestURL field added to PMGInstance config, model,
  and API handlers
- Update NodeSummaryTable to use guestURL for PBS nodes
- Frontend types updated for PBS/PMG guestURL support

The Guest URL setting in node configuration now works correctly across
all node types. When set, it takes priority over the Host URL when
clicking on node names to navigate to the Proxmox/PBS/PMG web UI.

Closes #870
2025-12-22 22:05:25 +00:00
rcourtman 86e9ce9f20 fix: default mock mode to false 2025-12-22 21:47:07 +00:00
rcourtman 2dfacfff18 chore: gitignore .gemini/ folder 2025-12-22 21:46:18 +00:00
rcourtman 039cac0e39 fix: prevent demo findings from being persisted to disk 2025-12-22 21:45:07 +00:00
rcourtman 16d43c06d7 Add clean separation between mock and real AI findings
- Add IsMockResource() helper to detect mock data resources by naming patterns
- Filter out heuristic findings from mock resources when PULSE_MOCK_MODE is off
- Mock findings still appear when demo mode is enabled
- Ensures users don't see mock data findings in production
2025-12-22 20:23:15 +00:00
rcourtman b0a278cc33 Fix demo mode detection to use PULSE_MOCK_MODE env var
The AI demo/mock findings were using a non-existent MOCK_ENABLED
env var. Changed to PULSE_MOCK_MODE which is the actual env var
used by the mock data system.
2025-12-22 20:09:56 +00:00
rcourtman d3d4379de6 fix(ci): restore arm64 Docker builds in publish workflow
The staging images in preflight are intentionally amd64-only for speed,
but the publish workflow was just copying them instead of building
multi-arch. Now builds linux/amd64,linux/arm64 from source at publish.

Related to #868
2025-12-22 20:03:39 +00:00
rcourtman e5bdd6b9f0 Unify AI patrol system: add Kubernetes analysis, enhance Docker/Podman detection
- Add AnalyzeKubernetes to PatrolConfig and enable by default
- Add analyzeKubernetesCluster() for K8s heuristic analysis
  - Detect offline clusters, nodes not ready, CrashLoopBackOff pods
  - Detect failed/pending pods and unavailable deployments
- Add K8s clusters to LLM context in buildInfrastructureSummary()
- Add kubernetes_cluster as valid resource type in AI prompt

- Enhance analyzeDockerHost() for Docker/Podman
  - Podman-aware messaging based on runtime
  - Add unhealthy container detection (health checks)
  - Add exited container with error detection
  - Add high CPU detection (>90%)
  - Add stale host detection (10+ minutes)
  - Tiered severity for restarts (>10 = critical)

- Add 20 new tests for K8s and Docker analysis
2025-12-22 18:03:46 +00:00
rcourtman 4c686ae26d feat: add CLI commands for mock mode management
New commands:
  pulse mock enable   - Enable mock mode
  pulse mock disable  - Disable mock mode
  pulse mock status   - Show current status

Makes it easy to toggle between mock and real data without
manually editing config files.
2025-12-22 17:26:57 +00:00
rcourtman 221d24360f feat: add demo AI findings for mock mode
When MOCK_ENABLED=true, Pulse now injects realistic AI patrol
findings to showcase the AI features without requiring actual
LLM API calls. This enables the demo instance to demonstrate:

- Critical/warning/info findings with realistic content
- Patrol run history
- Actionable recommendations

Also includes refinements to dismissal logic from earlier work:
- Only 'not_an_issue' creates permanent suppression
- 'expected_behavior' and 'will_fix_later' just acknowledge
2025-12-22 17:16:26 +00:00
rcourtman 3ba84e1e8f feat: make Docker host names clickable in container table
When a Docker host has a custom URL configured (e.g., Portainer link),
the host name in the container table's group headers is now a clickable
link that opens the URL in a new tab. A link icon appears next to the
host name to indicate it's clickable.

Related to #860
2025-12-22 15:05:34 +00:00
rcourtman 794bef1d73 docs: update AI.md with v5 patrol and finding management features
- Added finding management section (resolve, dismiss, suppress)
- Documented patrol service and severity levels
- Added AI-assisted remediation capabilities
- Added Ollama tool/function calling support note
- Added new troubleshooting tips for findings persistence
2025-12-22 14:43:56 +00:00
rcourtman 0469700da9 fix: clean up debug logging and fix flaky encryption test
1. Fixed TestNewConfigPersistenceFailsWhenEncryptedDataPresentWithoutKey
   - Test was picking up real encryption key from /etc/pulse during migration
   - Now temporarily moves system key during test for proper isolation
   - Uses t.Cleanup to ensure key is restored even on failure

2. Cleaned up console.log statements in production code
   - Dashboard.tsx: replaced console.log with logger.debug for metadata events
   - CompleteStep.tsx: removed verbose agent detection debug logs

These changes reduce log noise in production while maintaining debug
capability in development mode.
2025-12-22 14:35:48 +00:00
rcourtman a4fccccec2 fix: reduce WebSocket reconnection log noise in host agent
Addresses #866 - agents were logging 'WebSocket connection failed' warnings
even during normal reconnection scenarios (server restart, network blip, etc).

Changes:
- Normal close errors (1000, 1001, connection reset) now log at Debug level
- Only log Warning after 3+ consecutive failures
- Changed 'Connecting to Pulse' from Info to Debug to reduce noise
- Successful connections still log at Info level

The WebSocket is only used for AI command execution, not metrics, so
transient disconnections don't affect monitoring functionality.
2025-12-22 14:11:23 +00:00
rcourtman 288fb9a101 fix: persist finding dismissal state across restarts
User feedback fields (DismissedReason, UserNote, TimesRaised, Suppressed, Source)
were not being saved to disk, causing 'expected behavior' dismissals to be lost
after Pulse restarted.

- Add missing fields to AIFindingRecord in persistence.go
- Update FindingsPersistenceAdapter to save/load these fields
- Add comprehensive tests for dismissal persistence round-trip

Fixes issue where Frigate storage warning kept reappearing despite being
marked as expected behavior.
2025-12-22 11:18:43 +00:00
rcourtman c64c8b88e2 fix: Add missing guest filtering props to ThresholdsTable tests 2025-12-22 10:26:53 +00:00
rcourtman 53ea1fbee2 test: Add unit tests for guest tag filtering 2025-12-22 10:24:39 +00:00
rcourtman b5b98f577d feat: Add guest filtering by tag and name prefix via Alert Configuration. Resolves #863 2025-12-22 10:03:12 +00:00
rcourtman 2a363ffa05 fix: Prevent buffering and log actionable error for host agent 403s. Related to discussion #845 2025-12-22 09:51:27 +00:00
rcourtman 54aa997cfd fix: Prevent ignored container inputs from removing trailing newlines. Related to #865 2025-12-22 09:48:40 +00:00
rcourtman 50c029c044 fix: exclude watch from patrol status summary
Since watch/info findings are filtered from the UI and never shown
to users, don't include them in the patrol run status summary.
This makes the summary consistent with what users actually see.
2025-12-21 23:31:21 +00:00
rcourtman f054012c44 fix: include VMID in AI context to prevent incorrect references
The LLM was confusing VMIDs because they weren't included in the
context. Now the formatted context shows:

  ### Container: ollama (VMID 200) on minipc

This prevents the AI from referencing the wrong VMID when generating
findings and recommendations.
2025-12-21 23:13:47 +00:00
rcourtman 8546112abe perf: skip initial patrol if one ran recently
When the service restarts, it now checks if a patrol ran within the
last hour. If so, it skips the initial patrol to avoid wasting API
tokens during development/maintenance when the service is restarted
frequently.

The scheduled patrol runs (every 6 hours) are not affected.
2025-12-21 23:03:41 +00:00
rcourtman e83a6ab525 perf: reduce MetricSamples from 100 to 24 points
100 samples was causing 326k+ input tokens which is expensive.
24 samples (hourly resolution) still provides good pattern visibility
while significantly reducing token cost.

Estimated reduction: ~75% fewer metric tokens.
2025-12-21 22:56:19 +00:00
rcourtman 812df96377 feat: surface AI patrol errors as findings
When AI patrol fails due to API issues like insufficient balance, invalid
API key, or rate limiting, we now create a finding that appears in the
AI Insights tab. This makes the issue visible to users rather than hidden
in logs.

The finding includes:
- Clear description of the issue (e.g., 'Insufficient API credits')
- Recommendation for how to fix it
- Evidence showing the actual error message
2025-12-21 22:45:29 +00:00
rcourtman a4dcc1bac6 fix: don't show 'All healthy' when patrol run had errors
When a patrol run encounters errors (e.g., LLM call failed), don't
display 'All healthy' in the summary as that's misleading - the
analysis didn't complete properly.

Now shows 'Analysis incomplete (N errors)' instead, which correctly
explains why the status badge shows red/error.
2025-12-21 22:35:39 +00:00
rcourtman 49fc86c70b feat: increase MetricSamples to 100 points (~15 min resolution)
Modern LLMs have 100k+ token contexts. 100 samples over 24h gives
~15 minute resolution while adding minimal token overhead.

This lets the LLM see fine-grained patterns, short spikes, and
accurately distinguish anomalies from normal behavior.
2025-12-21 22:25:54 +00:00
rcourtman 818fbffd66 fix: increase MetricSamples to 24 points for hourly resolution
12 samples was too coarse (2-hour intervals could miss spikes).
24 samples gives ~hourly resolution while still being compact.
2025-12-21 22:24:02 +00:00
rcourtman 9176e54b80 fix: use 24h window for MetricSamples (matches in-memory retention)
The in-memory MetricsHistory only retains 24 hours of data, not 7 days.
Changed computeGuestMetricSamples to use trendWindow24h instead of
trendWindow7d, and reduced sample count from 24 to 12 points.

This ensures the LLM actually receives metric samples in the context,
which wasn't happening before because the 7-day query returned empty data.
2025-12-21 22:19:40 +00:00
rcourtman f44073a57d debug: add logging to verify MetricSamples population for LLM context 2025-12-21 22:14:54 +00:00
rcourtman 4cc74021fd feat: add 'Alert' badge to findings triggered by alert-triggered analysis
Shows a purple ' Alert' badge on findings that were discovered through
alert-triggered analysis rather than scheduled patrol runs. This gives
users visibility into how findings were discovered without cluttering
the patrol run history table.
2025-12-21 22:04:32 +00:00
rcourtman a2b3878ad2 fix: correct patrol interval logging
The log was showing QuickCheckInterval (deprecated, always 0) instead of
the actual Interval field. This caused confusing 'interval: 0' logs.
2025-12-21 21:52:57 +00:00
rcourtman 0ce6bda33b fix: AI settings persistence and UI improvements
Bug Fixes:
- Fix boolean fields with 'omitempty' not persisting false values
  - AlertTriggeredAnalysis, PatrolAnalyzeNodes/Guests/Docker/Storage
  - omitempty causes Go to skip false (zero value) when marshaling JSON
  - On reload, NewDefaultAIConfig() sets true, and missing field stays true

- Fix model dropdown losing selection after save (SolidJS reactivity issue)
  - Added explicit 'selected' attribute to option elements
  - Ensures browser maintains selection with optgroups during re-renders

Improvements:
- Change patrol type label from 'Quick' to 'Patrol' in history table
- Add chat_model and patrol_model to AI settings update log
- Add alert_triggered_analysis to AI config load log for debugging
2025-12-21 21:48:09 +00:00
rcourtman 4d7d2e42dc feat(ai): pass raw metric samples to LLM for pattern interpretation
Instead of relying on pre-computed trend heuristics (which can be misleading
for edge cases like step changes vs continuous growth), we now pass downsampled
raw data points to the LLM so it can interpret patterns directly.

Changes:
- Add MetricSamples field to ResourceContext
- Add DownsampleMetrics() to reduce data points for LLM consumption
- Add formatMetricSamples() to format data compactly (e.g., 'Disk: 26→26→31%')
- Add computeGuestMetricSamples() to gather 7-day sampled history
- Populate MetricSamples for VMs and containers during context build
- Add History section to formatted context output

The LLM now sees actual patterns like 'stable for 6 days then jumped' rather
than just '45.8%/day growth rate' - allowing for much more nuanced interpretation.

This approach:
- Leverages LLM's pattern recognition instead of hard-coded heuristics
- Provides 7 days of data (~24 samples) for context on normal behavior
- Uses minimal tokens due to compact formatting with deduplication
- Is more future-proof as LLMs improve

Example output:
  **History (7d sampled, oldest→newest)**: Disk: 26→26→26→26→26→31%

Refs: Frigate disk usage false positive investigation
2025-12-21 21:09:24 +00:00
rcourtman 17c36ed124 Add more AI test coverage
- findings_test.go: Add edge case tests for Acknowledge, Dismiss, SetUserNote, Suppress, Resolve, DeleteSuppressionRule, GetSummary, GetDismissedForContext (+20 tests)
- intelligence_test.go: Add tests for calculateResourceHealth with anomalies/predictions/notes, FormatContext with various subsystems, generateHealthPrediction, GetSummary with patterns/learning (+17 tests)

Coverage improvements:
- internal/ai: 63.1% -> 64.4%
- Overall AI module coverage now averages >80%
2025-12-21 20:31:24 +00:00
rcourtman 324ea0ca92 Improve AI test coverage
- baseline/store_test.go: Add tests for CheckResourceAnomalies, formatAnomalyDescription, formatRatio, GetAllAnomalies, floatToStr (67.9% -> 92.2%)
- memory/incidents_test.go: Add tests for RecordAlertUnacknowledged, RecordRunbook, ListIncidentsByResource, FormatForAlert, FormatForResource, FormatForPatrol (66.8% -> 81.1%)
- intelligence_test.go: Add tests for SetStateProvider, FormatGlobalContext, RecordLearning, severityOrder, CheckBaselinesForResource with baselines (61.4% -> 63.1%)
2025-12-21 20:22:47 +00:00
rcourtman 0ed453c1aa test: update GetAllFindings test to match filtering behavior
GetAllFindings now filters out info/watch severity findings,
only returning critical and warning. Update test expectation
from 3 findings to 2.
2025-12-21 19:20:27 +00:00
rcourtman 547fb65e39 fix: remove unused runbook UI code to fix TypeScript errors
- Remove unused correlations state and constants from AIOverviewTable
- Remove unused runbook-related imports, state, and functions from Alerts
- Add type annotation to Set() to fix type error
- Removes dead code left over from runbook UI removal
2025-12-21 19:12:20 +00:00
rcourtman 3e3de5325b security: allow rm on /var/tmp and /tmp with approval
Updated command policy to be more nuanced:

BLOCKED (hard block, never allowed):
- rm -rf / (root)
- rm -rf /* (root wildcard)
- rm -rf /home, /etc, /usr, /var/lib, /boot, /root, /bin, /sbin, /lib, /opt

REQUIRE APPROVAL (user must click 'Run'):
- rm -rf /var/tmp/* (Proxmox vzdump temp files)
- rm -rf /tmp/*

This allows AI to suggest cleaning up vzdump temp files while still
protecting against destructive operations on critical paths.
2025-12-21 18:53:08 +00:00
rcourtman 6fe207a094 refactor: only show critical/warning patrol findings
Filter out 'watch' and 'info' severity findings from the API response.
These lower-severity findings were mostly noise:
- 'watch': CPU is 35% instead of 11% (who cares)
- 'info': Stopped container exists (knew that)

Now only showing actionable findings:
- critical: Something is broken NOW
- warning: Something needs attention soon

Users prefer silence to noise.
2025-12-21 18:34:51 +00:00
rcourtman bc5b0d7584 refactor: remove runbook UI from frontend
Removed:
- Runbook button from finding action buttons
- Runbook Execution panel
- Fix Receipts panel (already removed)

Just showing 'Get Help' and 'I Fixed It' buttons now.
2025-12-21 18:08:47 +00:00
rcourtman 7e66423042 refactor: remove Fix Receipts UI section
Fix Receipts was showing 'No fixes logged' most of the time since:
- Runbooks were removed
- Remediation logging was inconsistent

Just adds visual clutter without value. Removed ~100 lines of UI code.
2025-12-21 18:02:35 +00:00
rcourtman 284ca0271b refactor: remove runbooks feature entirely
Runbooks were a half-built feature that provided no value:
- Only 3 runbooks existed
- AI dynamic remediation already covers the same ground
- Added UI complexity without benefit

Removed:
- runbooks.go and runbooks_test.go
- Handler functions in ai_handlers.go
- Routes in router.go
- Test cases in ai_handlers_test.go
- Auto-fix call in patrol.go

Kept (dead code but harmless):
- Frontend types/API calls (will 404)
- RecordIncidentRunbook function (unused)

Less code = easier to maintain.
2025-12-21 17:48:07 +00:00
rcourtman 3c8d264283 feat(ai): make patrol prompt stricter to reduce noise
Updated LLM prompt with explicit guidance on what NOT to report:
- Small baseline deviations (7% vs 4% is normal variance)
- Low utilization (under 50% CPU or 60% memory is fine)
- Stopped containers that aren't autostart
- 'Elevated' metrics still well under limits

Severity guidelines made more specific:
- CRITICAL: disk >95%, service down, data loss
- WARNING: disk >85%, memory >90%, failures
- WATCH: Only for trends projected to hit critical in <7 days
- INFO: Context/observations

Key message to LLM: 'Users prefer silence to noise'
Only flag things that require operator action.
2025-12-21 17:35:36 +00:00
rcourtman f7bb6d5446 feat(ai): implement metric-specific anomaly thresholds
Smarter anomaly detection to reduce false positives:

**Learning Window:** 7 days → 14 days
- Captures weekly patterns (weekday vs weekend)

**Metric-Specific Thresholds:**

CPU:
- Only report if usage >70% AND >2x baseline
- Low CPU variance (5% vs 10%) is not actionable

Memory:
- Report if >80% OR (>1.5x baseline AND >60%)
- Memory is more stable, lower threshold makes sense

Disk:
- Report if >85% usage OR +15 percentage points growth
- Disk problems are critical, use absolute thresholds

Other metrics:
- Use 2x threshold as default

This dramatically reduces 'noise' anomalies while catching
actual problems that need operator attention.
2025-12-21 17:31:30 +00:00
rcourtman 4780dd2f83 fix(ui): remove AI Intelligence Summary - patrol findings are sufficient
The AI Intelligence Summary was adding noise rather than value:
- Predictions duplicated patrol findings
- Correlations were not actionable
- 'Fixed' items were vague diagnostics
- Status changes were startup noise

The real value is in the patrol findings section which shows:
- Actual issues found (critical/warning/watch/info)
- Actionable recommendations
- Suppression rules

Keeping the patrol findings, removing the redundant summary.
2025-12-21 17:23:25 +00:00
rcourtman c8a32a7131 fix(ai): raise anomaly threshold to 2x, filter 'Ran diagnostic' noise
More aggressive noise filtering:

1. Anomaly threshold raised from 1.5x to 2x
   - 1.5x is too borderline to be actionable
   - Now requires genuinely significant deviation

2. Filter out 'Ran diagnostic' and 'Executed command' fallback items
   - These are generic summaries that provide no value
   - Only show remediations with specific, meaningful descriptions

Goal: If something shows in AI Intelligence, it should demand attention.
2025-12-21 17:19:32 +00:00