Skip to content

Commit 90184ad

Browse files
AlexMikhalevclaude
andcommitted
feat(nightwatch): add active hours window for drift evaluation
Nightwatch evaluate() is now gated by active_start_hour / active_end_hour in NightwatchConfig. Defaults to 0-24 (always active) for backwards compatibility. Supports wrap-around past midnight (e.g. 22-06). This allows the orchestrator to run nightwatch only during off-peak hours, e.g. 2am-6am, reducing noise during active development. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a5e2b32 commit 90184ad

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

crates/terraphim_orchestrator/src/config.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ pub struct NightwatchConfig {
122122
/// Drift percentage threshold for Critical correction.
123123
#[serde(default = "default_critical_threshold")]
124124
pub critical_threshold: f64,
125+
/// Hour (0-23) when nightwatch evaluation starts. Default: 0 (midnight).
126+
#[serde(default)]
127+
pub active_start_hour: u8,
128+
/// Hour (0-23) when nightwatch evaluation ends. Default: 24 (always active).
129+
#[serde(default = "default_active_end_hour")]
130+
pub active_end_hour: u8,
125131
}
126132

127133
impl Default for NightwatchConfig {
@@ -132,6 +138,8 @@ impl Default for NightwatchConfig {
132138
moderate_threshold: default_moderate_threshold(),
133139
severe_threshold: default_severe_threshold(),
134140
critical_threshold: default_critical_threshold(),
141+
active_start_hour: 0,
142+
active_end_hour: default_active_end_hour(),
135143
}
136144
}
137145
}
@@ -151,6 +159,9 @@ fn default_severe_threshold() -> f64 {
151159
fn default_critical_threshold() -> f64 {
152160
0.70
153161
}
162+
fn default_active_end_hour() -> u8 {
163+
24
164+
}
154165

155166
/// Compound review settings.
156167
#[derive(Debug, Clone, Serialize, Deserialize)]

crates/terraphim_orchestrator/src/lib.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ pub use nightwatch::{
6262
pub use persona::{MetapromptRenderError, MetapromptRenderer, PersonaRegistry};
6363
pub use scheduler::{ScheduleEvent, TimeScheduler};
6464

65+
use chrono::Timelike;
6566
use std::collections::HashMap;
6667
use std::path::Path;
6768
use std::time::{Duration, Instant};
@@ -597,8 +598,18 @@ impl AgentOrchestrator {
597598
// 4. Drain output events to nightwatch
598599
self.drain_output_events();
599600

600-
// 5. Evaluate nightwatch drift
601-
self.nightwatch.evaluate();
601+
// 5. Evaluate nightwatch drift (only during active hours)
602+
let nw_cfg = &self.config.nightwatch;
603+
let current_hour = chrono::Local::now().hour() as u8;
604+
let in_window = if nw_cfg.active_start_hour <= nw_cfg.active_end_hour {
605+
current_hour >= nw_cfg.active_start_hour && current_hour < nw_cfg.active_end_hour
606+
} else {
607+
// Wraps past midnight, e.g. start=22 end=6
608+
current_hour >= nw_cfg.active_start_hour || current_hour < nw_cfg.active_end_hour
609+
};
610+
if in_window {
611+
self.nightwatch.evaluate();
612+
}
602613

603614
// 6. Sweep expired handoff buffer entries
604615
let swept = self.handoff_buffer.sweep_expired();

0 commit comments

Comments
 (0)