The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
docs(prompts): clarify prompt clock docs and tighten clock test
Steven Enamakel8f058510824c
diff --git a/crates/openhuman-core/src/prompts/section_renderers.rs b/crates/openhuman-core/src/prompts/section_renderers.rsindex 3976d14218..816c688469 100644--- a/crates/openhuman-core/src/prompts/section_renderers.rs+++ b/crates/openhuman-core/src/prompts/section_renderers.rs@@ -57,20 +57,6 @@ pub fn render_datetime(ctx: &PromptContext<'_>) -> Result<String> {DateTimeSection.build(ctx)}-/// Canonical one-line "now" stamp, injected per turn alongside the user-/// message by both the main session loop (`session::turn`) and the-/// sub-agent runner so every flow reports the current time identically-/// (#3602). Local time + IANA zone + `%Z`/offset + weekday, so the model-/// can localize greetings and date math without a tool call.-///-/// Deliberately lives on the *user message*, never the cached-/// system-prompt prefix: `Local::now()` is volatile, so freezing it into-/// the prefix both busts the KV cache and goes stale across a long-lived-/// session. The static grounding *rule* that tells the model to read this-/// line lives in [`DateTimeSection`] / [`render_datetime`].-///-/// `zone` is the user's IANA zone ([`crate::config::Config::time_zone`]);-/// `None`, or a name chrono-tz does not know, stamps the device's.type PromptClock = Arc<dyn Fn() -> DateTime<Utc> + Send + Sync>;static PROMPT_CLOCKS: crate::core::slots::HookSlot<PromptClock> =@@ -142,9 +128,9 @@ pub fn current_datetime_line_at(now: DateTime<Utc>, zone: Option<&str>) -> Strin}// When the host resolves an IANA zone, stamp local time + that zone. When- // it can't (CI, stripped containers), fall back to true UTC — formatting- // `Utc::now()` so the time, offset, and zone label all agree rather than- // pairing a "UTC" label with a local clock/offset.+ // it can't (CI, stripped containers), fall back to true UTC so the time,+ // offset, and zone label all agree rather than pairing a "UTC" label with+ // a local clock/offset.match iana_time_zone::get_timezone() {Ok(iana) => {let now = now.with_timezone(&chrono::Local);@@ -167,8 +153,22 @@ pub fn current_datetime_line_at(now: DateTime<Utc>, zone: Option<&str>) -> Strin}}-/// Render the current timestamp using the newest scoped provider, or the-/// system clock when no provider is registered.+/// Canonical one-line "now" stamp, injected per turn alongside the user+/// message by both the main session loop (`session::turn`) and the+/// sub-agent runner so every flow reports the current time identically+/// (#3602). Local time + IANA zone + `%Z`/offset + weekday, so the model+/// can localize greetings and date math without a tool call.+///+/// Deliberately lives on the *user message*, never the cached+/// system-prompt prefix: the clock is volatile, so freezing it into the+/// prefix both busts the KV cache and goes stale across a long-lived+/// session. The static grounding *rule* that tells the model to read this+/// line lives in [`DateTimeSection`] / [`render_datetime`].+///+/// `zone` is the user's IANA zone ([`crate::config::Config::time_zone`]);+/// `None`, or a name chrono-tz does not know, stamps the device's. The+/// newest live prompt-clock registration is used when present; otherwise+/// this reads the system clock.pub fn current_datetime_line(zone: Option<&str>) -> String {let now = PROMPT_CLOCKS.entries()diff --git a/crates/openhuman-core/src/prompts/section_renderers_tests.rs b/crates/openhuman-core/src/prompts/section_renderers_tests.rsindex 65436714d9..3b37d59aa3 100644--- a/crates/openhuman-core/src/prompts/section_renderers_tests.rs+++ b/crates/openhuman-core/src/prompts/section_renderers_tests.rs@@ -50,9 +50,34 @@ fn newest_prompt_clock_wins_and_non_lifo_drop_restores_the_remaining_provider()let before = Utc::now();let actual = current_datetime_line(Some("UTC"));let after = Utc::now();+ let stamped = actual+ .strip_prefix("Current Date & Time: ")+ .and_then(|rest| rest.get(..19))+ .and_then(|value| chrono::NaiveDateTime::parse_from_str(value, "%Y-%m-%d %H:%M:%S").ok())+ .expect("default clock emits a parseable UTC timestamp")+ .and_utc();assert!(- actual == current_datetime_line_at(before, Some("UTC"))- || actual == current_datetime_line_at(after, Some("UTC")),+ (before.timestamp()..=after.timestamp()).contains(&stamped.timestamp()),"dropping the final registration must restore the live system clock");}++#[test]+fn prompt_clock_registration_is_removed_when_scope_unwinds() {+ let prior = register_prompt_clock(|| utc("2024-01-01T12:00:00Z"));+ let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {+ let _temporary = register_prompt_clock(|| utc("2024-02-02T13:00:00Z"));+ assert_eq!(+ current_datetime_line(Some("UTC")),+ current_datetime_line_at(utc("2024-02-02T13:00:00Z"), Some("UTC"))+ );+ panic!("exercise prompt-clock guard unwinding");+ }));++ assert!(result.is_err());+ assert_eq!(+ current_datetime_line(Some("UTC")),+ current_datetime_line_at(utc("2024-01-01T12:00:00Z"), Some("UTC"))+ );+ drop(prior);+}