mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
752ed90d78
Stacked on #28822. ## Summary - add a host-injectable current-time provider with a built-in system implementation - record UTC developer reminders in history immediately before due model requests - keep cadence state per session and force a refresh after compaction This does NOT include the app server client <-> server clock logic. This PR is only for the reminder message & system clock that will be used in prod. ## Testing - `just test -p codex-core varlatency_` - `just clippy -p codex-core -p codex-app-server -p codex-mcp-server -p codex-thread-manager-sample` - `just fmt`
42 lines
1.3 KiB
Rust
42 lines
1.3 KiB
Rust
use std::future::Future;
|
|
use std::pin::Pin;
|
|
use std::sync::Arc;
|
|
|
|
use anyhow::Result;
|
|
use anyhow::anyhow;
|
|
use chrono::DateTime;
|
|
use chrono::Utc;
|
|
use codex_features::CurrentTimeSource;
|
|
use codex_protocol::ThreadId;
|
|
|
|
use crate::config::CurrentTimeReminderConfig;
|
|
|
|
pub type TimeFuture<'a> = Pin<Box<dyn Future<Output = Result<DateTime<Utc>>> + Send + 'a>>;
|
|
|
|
/// Host integration boundary for obtaining the current time.
|
|
pub trait TimeProvider: Send + Sync {
|
|
fn current_time(&self, thread_id: ThreadId) -> TimeFuture<'_>;
|
|
}
|
|
|
|
pub(crate) struct SystemTimeProvider;
|
|
|
|
impl TimeProvider for SystemTimeProvider {
|
|
fn current_time(&self, _thread_id: ThreadId) -> TimeFuture<'_> {
|
|
Box::pin(async { Ok(Utc::now()) })
|
|
}
|
|
}
|
|
|
|
pub(crate) fn resolve_time_provider(
|
|
config: Option<&CurrentTimeReminderConfig>,
|
|
external_provider: Option<Arc<dyn TimeProvider>>,
|
|
) -> Result<Arc<dyn TimeProvider>> {
|
|
match config.map(|config| config.clock_source).unwrap_or_default() {
|
|
CurrentTimeSource::System => Ok(Arc::new(SystemTimeProvider)),
|
|
CurrentTimeSource::External => external_provider.ok_or_else(|| {
|
|
anyhow!(
|
|
"features.current_time_reminder.clock_source is external, but no external current-time provider is available"
|
|
)
|
|
}),
|
|
}
|
|
}
|