Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions crates/terraphim_orchestrator/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ pub struct NightwatchConfig {
/// Drift percentage threshold for Critical correction.
#[serde(default = "default_critical_threshold")]
pub critical_threshold: f64,
/// Hour (0-23) when nightwatch evaluation starts. Default: 0 (midnight).
#[serde(default)]
pub active_start_hour: u8,
/// Hour (0-23) when nightwatch evaluation ends. Default: 24 (always active).
#[serde(default = "default_active_end_hour")]
pub active_end_hour: u8,
}

impl Default for NightwatchConfig {
Expand All @@ -132,6 +138,8 @@ impl Default for NightwatchConfig {
moderate_threshold: default_moderate_threshold(),
severe_threshold: default_severe_threshold(),
critical_threshold: default_critical_threshold(),
active_start_hour: 0,
active_end_hour: default_active_end_hour(),
}
}
}
Expand All @@ -151,6 +159,9 @@ fn default_severe_threshold() -> f64 {
fn default_critical_threshold() -> f64 {
0.70
}
fn default_active_end_hour() -> u8 {
24
}

/// Compound review settings.
#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
15 changes: 13 additions & 2 deletions crates/terraphim_orchestrator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub use nightwatch::{
pub use persona::{MetapromptRenderError, MetapromptRenderer, PersonaRegistry};
pub use scheduler::{ScheduleEvent, TimeScheduler};

use chrono::Timelike;
use std::collections::HashMap;
use std::path::Path;
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -597,8 +598,18 @@ impl AgentOrchestrator {
// 4. Drain output events to nightwatch
self.drain_output_events();

// 5. Evaluate nightwatch drift
self.nightwatch.evaluate();
// 5. Evaluate nightwatch drift (only during active hours)
let nw_cfg = &self.config.nightwatch;
let current_hour = chrono::Local::now().hour() as u8;
let in_window = if nw_cfg.active_start_hour <= nw_cfg.active_end_hour {
current_hour >= nw_cfg.active_start_hour && current_hour < nw_cfg.active_end_hour
} else {
// Wraps past midnight, e.g. start=22 end=6
current_hour >= nw_cfg.active_start_hour || current_hour < nw_cfg.active_end_hour
};
if in_window {
self.nightwatch.evaluate();
}

// 6. Sweep expired handoff buffer entries
let swept = self.handoff_buffer.sweep_expired();
Expand Down
Loading