strawberry/app/tray_state.cpp
trvon 76ec40e4f5
Replace web UI with a Qt tray app
Remove the browser UI, its Python server and the web API contract test.
Add the Qt6 tray app (status, findings, process search, policy
controls, notifications) and EvidenceStore, the read-only view of the
daemon's evidence that the app and MCP server share. The GUI demo
config becomes strawberry.demo.conf.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 18:17:03 -06:00

99 lines
3.2 KiB
C++

#include "tray_state.hpp"
namespace strawberry::app {
int severity_rank(const std::string& severity) {
if (severity == "critical") return 4;
if (severity == "high") return 3;
if (severity == "medium") return 2;
if (severity == "low") return 1;
return 0;
}
bool is_alert_severity(const std::string& severity) {
return severity_rank(severity) >= 3;
}
bool is_unseen(const FindingSummary& finding, const AckMap& seen) {
const auto it = seen.find(finding.id);
return it == seen.end() || finding.last_seen > it->second;
}
TrayState evaluate_tray(const DaemonSnapshot& snapshot,
const std::vector<FindingSummary>& findings,
const AckMap& seen,
uint64_t previous_scan_errors) {
TrayState state;
for (const auto& finding : findings) {
if (!is_unseen(finding, seen)) {
continue;
}
if (is_alert_severity(finding.severity)) {
++state.unseen_alerts;
} else {
++state.unseen_other;
}
}
std::string findings_line;
if (state.unseen_alerts > 0) {
findings_line = std::to_string(state.unseen_alerts) + " new high-severity finding"
+ (state.unseen_alerts == 1 ? "" : "s");
} else if (state.unseen_other > 0) {
findings_line = std::to_string(state.unseen_other) + " new finding"
+ (state.unseen_other == 1 ? "" : "s");
} else {
findings_line = "No new findings";
}
if (!snapshot.reachable) {
state.level = TrayLevel::unknown;
state.tooltip = "Strawberry: scanner not reachable";
if (!snapshot.unreachable_reason.empty()) {
state.tooltip += " (" + snapshot.unreachable_reason + ")";
}
// Stored findings still matter even when the daemon is down.
if (state.unseen_alerts > 0) {
state.level = TrayLevel::alert;
}
state.tooltip += "\n" + findings_line;
return state;
}
state.problems = scanner_problems(snapshot, previous_scan_errors);
if (state.unseen_alerts > 0) {
state.level = TrayLevel::alert;
} else if (!state.problems.empty() || state.unseen_other > 0) {
state.level = TrayLevel::warning;
} else {
state.level = TrayLevel::ok;
}
state.tooltip = "Strawberry: ";
state.tooltip += state.problems.empty() ? "scanner healthy" : "scanner degraded";
state.tooltip += "\n" + findings_line;
for (const auto& problem : state.problems) {
state.tooltip += "\n- " + problem;
}
return state;
}
std::vector<FindingSummary> findings_to_notify(const std::vector<FindingSummary>& findings,
const AckMap& seen,
const AckMap& notified) {
std::vector<FindingSummary> result;
for (const auto& finding : findings) {
if (!is_alert_severity(finding.severity) || !is_unseen(finding, seen)) {
continue;
}
if (const auto it = notified.find(finding.id); it != notified.end() && finding.last_seen <= it->second) {
continue;
}
result.push_back(finding);
}
return result;
}
} // namespace strawberry::app