#![windows_subsystem = "windows"]
use eframe::egui::{self, Color32, RichText};
use omega_cognitive_kernel::api::{Kernel, TrajectoryReplaySummary};
use omega_cognitive_kernel::audit::{AuditEvent, AuditLog, AuditRecord};
use omega_cognitive_kernel::config::KernelConfig;
use std::path::PathBuf;
fn setup_cjk_fonts(ctx: &egui::Context) {
let mut fonts = egui::FontDefinitions::default();
let candidates = [
r"C:\Windows\Fonts\msyh.ttc",
r"C:\Windows\Fonts\msyhbd.ttc",
r"C:\Windows\Fonts\simhei.ttf",
r"C:\Windows\Fonts\simsun.ttc",
r"C:\Windows\Fonts\msjh.ttc",
r"C:\Windows\Fonts\seguiemj.ttf",
r"C:\Windows\Fonts\segoeui.ttf",
"/System/Library/Fonts/PingFang.ttc",
"/usr/share/fonts/truetype/noto/NotoSansCJK-Regular.ttc",
];
let mut loaded = false;
for path in candidates {
if let Ok(data) = std::fs::read(path) {
let name = if path.contains("seguiemj") || path.contains("segoeui") {
"emoji_font"
} else {
"cjk_font"
};
fonts
.font_data
.insert(name.to_owned(), egui::FontData::from_owned(data));
if name == "cjk_font" {
fonts
.families
.entry(egui::FontFamily::Proportional)
.or_default()
.insert(0, "cjk_font".to_owned());
fonts
.families
.entry(egui::FontFamily::Monospace)
.or_default()
.insert(0, "cjk_font".to_owned());
loaded = true;
} else {
fonts
.families
.entry(egui::FontFamily::Proportional)
.or_default()
.push("emoji_font".to_owned());
}
}
}
if loaded {
ctx.set_fonts(fonts);
}
}
#[derive(PartialEq, Clone, Copy)]
enum Tab {
Dashboard,
Run,
Audit,
Replay,
Strategies,
Settings,
}
struct WorkspaceSlot {
label: String,
path: PathBuf,
}
#[derive(Clone, Debug)]
struct FixedPointEvent {
kind: &'static str,
timestamp: String,
step: u64,
alignment_score: f64,
dwell_steps: Option<u64>,
}
fn fixed_point_events_from_rows(rows: &[AuditRecord]) -> Vec<FixedPointEvent> {
rows.iter()
.filter_map(|r| match &r.event {
AuditEvent::FixedPointEntered {
step,
alignment_score,
} => Some(FixedPointEvent {
kind: "entered",
timestamp: r.ts.to_rfc3339(),
step: *step,
alignment_score: *alignment_score,
dwell_steps: None,
}),
AuditEvent::FixedPointExited {
step,
alignment_score,
dwell_steps,
} => Some(FixedPointEvent {
kind: "exited",
timestamp: r.ts.to_rfc3339(),
step: *step,
alignment_score: *alignment_score,
dwell_steps: Some(*dwell_steps),
}),
_ => None,
})
.collect()
}
struct DashboardApp {
tab: Tab,
kernel: Kernel,
goal: String,
steps_to_run: u32,
last_log: Vec<String>,
status_msg: String,
error: Option<String>,
config_path: Option<PathBuf>,
self_modify: bool,
dump_trajectory: bool,
replay_tail: usize,
replay_summary: Option<TrajectoryReplaySummary>,
workspaces: Vec<WorkspaceSlot>,
active_workspace: usize,
audit_offset: u64,
audit_follow: bool,
audit_live: Vec<String>,
fixed_point_events: Vec<FixedPointEvent>,
}
impl DashboardApp {
fn new(cc: &eframe::CreationContext<'_>) -> Self {
setup_cjk_fonts(&cc.egui_ctx);
let mut visuals = egui::Visuals::dark();
visuals.window_rounding = 8.0.into();
visuals.panel_fill = Color32::from_rgb(16, 18, 24);
cc.egui_ctx.set_visuals(visuals);
let state = std::env::temp_dir().join("omega-dashboard-state.json");
let mut kernel = Kernel::with_state_path(&state);
if state.exists() {
let _ = kernel.load();
}
kernel.autosave = true;
kernel.dump_trajectory = true;
kernel.inner.l1.self_modify_enabled = false;
let slot = WorkspaceSlot {
label: "default".into(),
path: state.clone(),
};
Self {
tab: Tab::Dashboard,
kernel,
goal: "maintain coherent self-model while acting in world".into(),
steps_to_run: 8,
last_log: Vec::new(),
status_msg: "ready".into(),
error: None,
config_path: None,
self_modify: false,
dump_trajectory: true,
replay_tail: 20,
replay_summary: None,
workspaces: vec![slot],
active_workspace: 0,
audit_offset: 0,
audit_follow: false,
audit_live: Vec::new(),
fixed_point_events: Vec::new(),
}
}
fn refresh_flags_from_kernel(&mut self) {
self.self_modify = self.kernel.inner.l1.self_modify_enabled;
self.dump_trajectory = self.kernel.dump_trajectory;
}
fn apply_flags_to_kernel(&mut self) {
self.kernel.inner.l1.self_modify_enabled = self.self_modify;
self.kernel.dump_trajectory = self.dump_trajectory;
}
fn refresh_fixed_point_events(&mut self) {
match self.kernel.audit_tail(100) {
Ok(rows) => self.fixed_point_events = fixed_point_events_from_rows(&rows),
Err(e) => self.error = Some(format!("fixed-point events: {e}")),
}
}
fn poll_audit_once(&mut self) {
let log = AuditLog::beside_state(&self.kernel.state_path);
match log.poll_after(self.audit_offset) {
Ok((rows, next)) => {
for r in &rows {
self.audit_live
.push(format!("{} {:?}", r.ts.to_rfc3339(), r.event));
}
self.refresh_fixed_point_events();
if self.audit_live.len() > 200 {
let drop_n = self.audit_live.len() - 200;
self.audit_live.drain(0..drop_n);
}
self.audit_offset = next;
if !rows.is_empty() {
self.status_msg = format!("audit +{} @{}", rows.len(), next);
}
}
Err(e) => self.error = Some(format!("audit poll: {e}")),
}
}
fn remember_workspace(&mut self, path: PathBuf, label: Option<String>) {
if let Some(i) = self.workspaces.iter().position(|w| w.path == path) {
self.active_workspace = i;
return;
}
let label = label.unwrap_or_else(|| {
path.file_stem()
.and_then(|s| s.to_str())
.unwrap_or("workspace")
.to_string()
});
self.workspaces.push(WorkspaceSlot { label, path });
self.active_workspace = self.workspaces.len() - 1;
}
fn switch_workspace(&mut self, idx: usize) {
if idx >= self.workspaces.len() {
return;
}
let path = self.workspaces[idx].path.clone();
let _ = self.kernel.save();
match Kernel::open(path.to_str()) {
Ok(mut k) => {
k.autosave = true;
self.kernel = k;
self.active_workspace = idx;
self.refresh_flags_from_kernel();
self.replay_summary = None;
self.last_log.clear();
self.fixed_point_events.clear();
self.status_msg = format!("switched → {}", path.display());
self.error = None;
}
Err(e) => self.error = Some(format!("switch failed: {e}")),
}
}
fn new_workspace(&mut self) {
if let Some(path) = rfd::FileDialog::new()
.set_title("New workspace state.json")
.set_file_name("state.json")
.save_file()
{
let _ = self.kernel.save();
let mut k = Kernel::with_state_path(&path);
k.autosave = true;
k.dump_trajectory = self.dump_trajectory;
k.inner.l1.self_modify_enabled = self.self_modify;
let _ = k.save();
self.kernel = k;
self.remember_workspace(path.clone(), None);
self.replay_summary = None;
self.last_log.clear();
self.fixed_point_events.clear();
self.status_msg = format!("new workspace {}", path.display());
self.error = None;
}
}
fn run_steps(&mut self) {
self.apply_flags_to_kernel();
self.last_log.clear();
self.error = None;
let goal = self.goal.clone();
let n = self.steps_to_run;
let mut ok = 0u32;
for i in 1..=n {
match self.kernel.step(&goal) {
Ok(r) => {
ok += 1;
let act = r
.trajectory
.actions
.first()
.map(|a| a.name.as_str())
.unwrap_or("-");
let line = format!(
"step {i:>2} act={act:<10} patched={} damp={:.2} err={:.3} fp={}",
r.l1.patched,
self.kernel.inner.l0.memory.cognitive_effect.error_damping,
self.kernel.inner.l0.memory.cas.avg_prediction_error,
r.l2.in_fixed_point
);
self.last_log.push(line);
}
Err(e) => {
self.error = Some(format!("step {i} failed: {e}"));
break;
}
}
}
let _ = self.kernel.save();
self.status_msg = format!("done {ok}/{n}");
self.refresh_flags_from_kernel();
}
fn load_replay(&mut self) {
match self.kernel.replay_trajectory(self.replay_tail) {
Ok(sum) => {
self.status_msg = format!("replay rows={}", sum.rows);
self.replay_summary = Some(sum);
self.error = None;
}
Err(e) => {
self.replay_summary = None;
self.error = Some(format!("replay failed: {e}"));
}
}
}
fn load_state_dialog(&mut self) {
if let Some(path) = rfd::FileDialog::new()
.set_title("Open state.json")
.add_filter("JSON", &["json"])
.pick_file()
{
match Kernel::open(path.to_str()) {
Ok(mut k) => {
k.autosave = true;
self.kernel = k;
self.remember_workspace(path.clone(), None);
self.refresh_flags_from_kernel();
self.replay_summary = None;
self.fixed_point_events.clear();
self.status_msg = format!("loaded {}", path.display());
self.error = None;
}
Err(e) => self.error = Some(format!("load failed: {e}")),
}
}
}
fn load_config_dialog(&mut self) {
if let Some(path) = rfd::FileDialog::new()
.set_title("Open omega.toml")
.add_filter("TOML", &["toml"])
.pick_file()
{
match KernelConfig::load(&path) {
Ok(cfg) => {
self.kernel.apply_config(&cfg);
self.config_path = Some(path.clone());
self.refresh_flags_from_kernel();
self.status_msg = format!("config {}", path.display());
self.error = None;
}
Err(e) => self.error = Some(format!("config failed: {e}")),
}
}
}
}
impl eframe::App for DashboardApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::TopBottomPanel::top("top").show(ctx, |ui| {
ui.add_space(6.0);
ui.horizontal(|ui| {
ui.heading(RichText::new("Omega Kernel").strong().size(22.0));
ui.label(RichText::new("operator console").weak().size(14.0));
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
ui.label(
RichText::new(&self.status_msg)
.small()
.color(Color32::from_rgb(140, 180, 255)),
);
});
});
ui.add_space(4.0);
ui.horizontal(|ui| {
ui.selectable_value(&mut self.tab, Tab::Dashboard, "Dashboard");
ui.selectable_value(&mut self.tab, Tab::Run, "Run");
ui.selectable_value(&mut self.tab, Tab::Audit, "Audit");
ui.selectable_value(&mut self.tab, Tab::Replay, "Replay");
ui.selectable_value(&mut self.tab, Tab::Strategies, "Strategies");
ui.selectable_value(&mut self.tab, Tab::Settings, "Settings");
});
ui.add_space(4.0);
});
egui::TopBottomPanel::bottom("bottom").show(ctx, |ui| {
ui.horizontal(|ui| {
ui.label(format!("state: {}", self.kernel.state_path.display()));
ui.separator();
let st = self.kernel.status();
ui.label(format!(
"schema={} steps={} err={:.3} self_modify={}",
st.schema_version,
st.total_steps,
st.avg_prediction_error,
st.self_modify_enabled
));
if let Some(ref e) = self.error {
ui.colored_label(Color32::from_rgb(255, 120, 120), e);
}
});
});
egui::CentralPanel::default().show(ctx, |ui| match self.tab {
Tab::Dashboard => self.ui_dashboard(ui),
Tab::Run => self.ui_run(ui),
Tab::Audit => self.ui_audit(ui),
Tab::Replay => self.ui_replay(ui),
Tab::Strategies => self.ui_strategies(ui),
Tab::Settings => self.ui_settings(ui),
});
}
}
impl DashboardApp {
fn stat_card(&self, ui: &mut egui::Ui, title: &str, value: &str, accent: Color32) {
egui::Frame::none()
.fill(Color32::from_rgb(28, 30, 38))
.rounding(8.0)
.inner_margin(14.0)
.show(ui, |ui| {
ui.set_min_width(120.0);
ui.vertical(|ui| {
ui.label(RichText::new(title).small().weak());
ui.label(RichText::new(value).size(22.0).color(accent).strong());
});
});
}
fn ui_dashboard(&mut self, ui: &mut egui::Ui) {
let st = self.kernel.status();
ui.heading("Dashboard");
ui.add_space(8.0);
ui.horizontal(|ui| {
self.stat_card(
ui,
"Schema",
&st.schema_version.to_string(),
Color32::from_rgb(160, 200, 255),
);
ui.add_space(10.0);
self.stat_card(
ui,
"Steps",
&st.total_steps.to_string(),
Color32::from_rgb(80, 160, 255),
);
ui.add_space(10.0);
self.stat_card(
ui,
"Pred err",
&format!("{:.3}", st.avg_prediction_error),
Color32::from_rgb(255, 180, 80),
);
ui.add_space(10.0);
self.stat_card(
ui,
"Damping",
&format!("{:.3}", st.error_damping),
Color32::from_rgb(100, 200, 140),
);
ui.add_space(10.0);
self.stat_card(
ui,
"Strategies",
&st.strategy_count.to_string(),
Color32::from_rgb(180, 140, 255),
);
ui.add_space(10.0);
self.stat_card(
ui,
"Self-mod",
if st.self_modify_enabled { "ON" } else { "OFF" },
if st.self_modify_enabled {
Color32::from_rgb(255, 120, 100)
} else {
Color32::from_rgb(100, 200, 140)
},
);
});
ui.add_space(16.0);
ui.heading("L2 / fixed-point");
ui.label(format!(
"in_fp={} dwell={} align={:.3} max_risk={:.2}",
st.in_fixed_point, st.dwell_steps, st.last_alignment_score, st.max_risk
));
ui.label(format!(
"explore_bonus={:.3} risk_tolerance={:.3} modules={} cases={}",
st.explore_bonus, st.risk_tolerance, st.active_modules, st.case_count
));
ui.add_space(10.0);
ui.heading("Recent fixed-point events");
if self.fixed_point_events.is_empty() {
ui.label("(none loaded — click Refresh or poll Audit)");
} else {
egui::ScrollArea::vertical()
.max_height(130.0)
.show(ui, |ui| {
for event in self.fixed_point_events.iter().rev() {
let detail = match event.dwell_steps {
Some(dwell) => format!("dwell={dwell}"),
None => "dwell=-".into(),
};
let color = if event.kind == "entered" {
Color32::from_rgb(100, 220, 150)
} else {
Color32::from_rgb(255, 180, 80)
};
ui.colored_label(
color,
format!(
"{} step={} align={:.3} {}",
event.kind, event.step, event.alignment_score, detail
),
);
ui.label(RichText::new(&event.timestamp).small().weak());
}
});
}
ui.add_space(16.0);
ui.horizontal(|ui| {
if ui.button("Refresh").clicked() {
self.refresh_flags_from_kernel();
self.refresh_fixed_point_events();
self.status_msg = "refreshed".into();
}
if ui.button("Save state").clicked() {
match self.kernel.save() {
Ok(()) => self.status_msg = "saved".into(),
Err(e) => self.error = Some(format!("{e}")),
}
}
if ui.button("Run").clicked() {
self.tab = Tab::Run;
}
if ui.button("Replay").clicked() {
self.tab = Tab::Replay;
}
});
}
fn ui_run(&mut self, ui: &mut egui::Ui) {
ui.heading("Run loop");
ui.label(RichText::new("self_modify defaults OFF — enable in Settings.").weak());
ui.add_space(10.0);
ui.horizontal(|ui| {
ui.label("goal:");
ui.add(
egui::TextEdit::singleline(&mut self.goal)
.desired_width(520.0)
.hint_text("high-level goal"),
);
});
ui.horizontal(|ui| {
ui.label("steps:");
ui.add(egui::DragValue::new(&mut self.steps_to_run).range(1..=200));
if ui
.button(RichText::new(format!("Run {} steps", self.steps_to_run)).strong())
.clicked()
{
self.run_steps();
}
});
ui.add_space(12.0);
ui.heading("Batch output");
egui::ScrollArea::vertical()
.max_height(360.0)
.show(ui, |ui| {
if self.last_log.is_empty() {
ui.label("(empty)");
} else {
for line in &self.last_log {
ui.monospace(line);
}
}
});
}
fn ui_audit(&mut self, ui: &mut egui::Ui) {
ui.heading("Audit");
let log = AuditLog::beside_state(&self.kernel.state_path);
match log.summarize() {
Ok(s) => {
ui.label(format!("log: {}", log.path.display()));
ui.label(format!(
"events={} steps={} patches_ok={} patches_rej={} ckpts={} rollbacks={}",
s.total_events,
s.steps,
s.patches_accepted,
s.patches_rejected,
s.checkpoints,
s.rollbacks
));
if !s.action_counts.is_empty() {
ui.add_space(8.0);
ui.label("actions:");
for (name, n) in &s.action_counts {
ui.label(format!(" {name:<12} {n}"));
}
}
}
Err(e) => {
ui.colored_label(Color32::from_rgb(255, 120, 120), format!("{e}"));
}
}
ui.add_space(10.0);
ui.horizontal(|ui| {
ui.checkbox(&mut self.audit_follow, "Follow (poll_after)");
ui.label(format!("cursor={}", self.audit_offset));
if ui.button("Poll once").clicked() {
self.poll_audit_once();
}
if ui.button("Reset cursor").clicked() {
self.audit_offset = 0;
self.audit_live.clear();
self.status_msg = "audit cursor reset".into();
}
});
if self.audit_follow {
self.poll_audit_once();
}
ui.add_space(8.0);
ui.heading("Live stream");
egui::ScrollArea::vertical()
.max_height(160.0)
.show(ui, |ui| {
if self.audit_live.is_empty() {
ui.label("(empty — enable Follow or Poll once)");
} else {
for line in &self.audit_live {
ui.monospace(line);
}
}
});
ui.add_space(12.0);
ui.heading("Recent events (tail)");
match self.kernel.audit_tail(30) {
Ok(rows) => {
egui::ScrollArea::vertical()
.max_height(220.0)
.show(ui, |ui| {
if rows.is_empty() {
ui.label("(empty)");
}
for r in rows.iter().rev() {
ui.monospace(format!("{} {:?}", r.ts.to_rfc3339(), r.event));
}
});
}
Err(e) => {
ui.colored_label(Color32::from_rgb(255, 120, 120), format!("{e}"));
}
}
}
fn ui_replay(&mut self, ui: &mut egui::Ui) {
ui.heading("Trajectory replay");
ui.label(
RichText::new("Offline summary of trajectory.jsonl (same as CLI omega-kernel replay).")
.weak(),
);
ui.add_space(8.0);
ui.horizontal(|ui| {
ui.label("tail:");
ui.add(egui::DragValue::new(&mut self.replay_tail).range(5..=200));
if ui.button(RichText::new("Load replay").strong()).clicked() {
self.load_replay();
}
});
ui.add_space(12.0);
match &self.replay_summary {
None => {
ui.label("(not loaded — run steps with dump_trajectory on)");
}
Some(sum) => {
ui.label(format!("path: {}", sum.path));
ui.label(format!("rows={} patches={}", sum.rows, sum.patches));
if let (Some(a), Some(b)) = (sum.first_avg_err, sum.last_avg_err) {
ui.label(format!("avg_err: {a:.4} -> {b:.4}"));
}
if !sum.action_counts.is_empty() {
ui.add_space(8.0);
ui.label("actions:");
for (name, n) in &sum.action_counts {
ui.label(format!(" {name:<12} {n}"));
}
}
ui.add_space(10.0);
ui.heading("Tail steps");
egui::ScrollArea::vertical()
.max_height(300.0)
.show(ui, |ui| {
for r in &sum.tail {
let err = r
.avg_err
.map(|e| format!("{e:.3}"))
.unwrap_or_else(|| "-".into());
ui.monospace(format!(
"step {:>4} act={:<10} patched={:<5} avg_err={}",
r.step, r.action, r.patched, err
));
}
});
}
}
}
fn ui_strategies(&mut self, ui: &mut egui::Ui) {
ui.heading("Strategy memory");
ui.label(
RichText::new("Operator weight nudge (0.1–10). Does not enable self_modify.")
.weak()
.small(),
);
let strategies = self.kernel.inner.l0.memory.strategy.retrieve("", 50);
if strategies.is_empty() {
ui.label("(none yet — run some steps)");
return;
}
ui.label(format!("{} entries", strategies.len()));
ui.add_space(6.0);
let mut nudges: Vec<(String, f64)> = Vec::new();
egui::ScrollArea::vertical().show(ui, |ui| {
for s in &strategies {
ui.horizontal(|ui| {
ui.monospace(format!("{:<12}", s.name));
ui.label(format!(
"w={:.3} ok={} fail={} idle={}",
s.weight, s.success_count, s.fail_count, s.idle_steps
));
if ui.small_button("−").on_hover_text("weight −0.1").clicked() {
nudges.push((s.name.clone(), (s.weight - 0.1).max(0.1)));
}
if ui.small_button("+").on_hover_text("weight +0.1").clicked() {
nudges.push((s.name.clone(), (s.weight + 0.1).min(10.0)));
}
if ui
.small_button("1.0")
.on_hover_text("reset to 1.0")
.clicked()
{
nudges.push((s.name.clone(), 1.0));
}
});
}
});
for (name, w) in nudges {
if self.kernel.set_strategy_weight(&name, w) {
self.status_msg = format!("weight {name} → {w:.2}");
let _ = self.kernel.save();
}
}
}
fn ui_settings(&mut self, ui: &mut egui::Ui) {
ui.heading("Settings");
ui.add_space(8.0);
ui.checkbox(&mut self.self_modify, "self_modify_enabled (default off)");
ui.checkbox(&mut self.dump_trajectory, "dump trajectory.jsonl");
if ui.button("Apply flags to Kernel").clicked() {
self.apply_flags_to_kernel();
self.status_msg = format!(
"applied self_modify={} dump={}",
self.self_modify, self.dump_trajectory
);
}
ui.add_space(12.0);
ui.label(format!("state: {}", self.kernel.state_path.display()));
ui.horizontal(|ui| {
if ui.button("Open state").clicked() {
self.load_state_dialog();
}
if ui.button("Load omega.toml").clicked() {
self.load_config_dialog();
}
if ui.button("Save state as").clicked() {
if let Some(path) = rfd::FileDialog::new()
.set_title("Save state")
.set_file_name("state.json")
.save_file()
{
self.kernel.state_path = path.clone();
match self.kernel.save() {
Ok(()) => self.status_msg = format!("saved {}", path.display()),
Err(e) => self.error = Some(format!("{e}")),
}
}
}
});
if let Some(ref p) = self.config_path {
ui.label(format!("last config: {}", p.display()));
}
ui.add_space(14.0);
ui.heading("Workspaces (multi-instance)");
ui.label(
RichText::new("Each workspace is a separate state.json. Switch without restarting.")
.weak()
.small(),
);
ui.horizontal(|ui| {
if ui.button("New workspace…").clicked() {
self.new_workspace();
}
if ui.button("Open state").clicked() {
self.load_state_dialog();
}
});
ui.add_space(6.0);
let active = self.active_workspace;
let labels: Vec<(usize, String, String)> = self
.workspaces
.iter()
.enumerate()
.map(|(i, w)| (i, w.label.clone(), w.path.display().to_string()))
.collect();
for (i, label, path) in labels {
ui.horizontal(|ui| {
let selected = i == active;
if ui
.selectable_label(selected, label)
.on_hover_text(&path)
.clicked()
&& !selected
{
self.switch_workspace(i);
}
ui.label(RichText::new(path).small().weak());
});
}
ui.add_space(16.0);
ui.separator();
ui.label(
RichText::new(
"Local-only operator UI. Keep self_modify=false until you intend L1 patches.",
)
.small(),
);
ui.label(
RichText::new("Omega Dashboard v0.5.4 · MIT")
.weak()
.small(),
);
}
}
fn main() -> eframe::Result<()> {
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
.with_inner_size([980.0, 700.0])
.with_title("Omega Kernel Dashboard"),
..Default::default()
};
eframe::run_native(
"Omega Kernel Dashboard",
options,
Box::new(|cc| Ok(Box::new(DashboardApp::new(cc)))),
)
}
#[cfg(test)]
mod tests {
use super::*;
use chrono::Utc;
#[test]
fn parses_fixed_point_enter_and_exit_events() {
let rows = vec![
AuditRecord {
ts: Utc::now(),
event: AuditEvent::Step {
step: 1,
goal: "g".into(),
action: "observe".into(),
avg_err: 0.2,
damping: 1.0,
},
},
AuditRecord {
ts: Utc::now(),
event: AuditEvent::FixedPointEntered {
step: 4,
alignment_score: 0.91,
},
},
AuditRecord {
ts: Utc::now(),
event: AuditEvent::FixedPointExited {
step: 11,
alignment_score: 0.43,
dwell_steps: 7,
},
},
];
let events = fixed_point_events_from_rows(&rows);
assert_eq!(events.len(), 2);
assert_eq!(events[0].kind, "entered");
assert_eq!(events[0].step, 4);
assert!((events[0].alignment_score - 0.91).abs() < f64::EPSILON);
assert_eq!(events[0].dwell_steps, None);
assert_eq!(events[1].kind, "exited");
assert_eq!(events[1].step, 11);
assert_eq!(events[1].dwell_steps, Some(7));
}
}