From 9c29853014b24984c20d0498cc9331ea72ebbb0c Mon Sep 17 00:00:00 2001 From: Tak Hoffman <781889+Takhoffman@users.noreply.github.com> Date: Sat, 31 Jan 2026 09:24:27 -0600 Subject: [PATCH] Gateway: inject timestamps into agent/chat.send (#3705) (thanks @conroywhitney, @CashWilliams) --- CHANGELOG.md | 1 + src/gateway/server-methods/agent-timestamp.ts | 22 +++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 761099086..71ca4213d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ Docs: https://docs.openclaw.ai - Auth: switch Kimi Coding to built-in provider; normalize OAuth profile email. - Auth: add MiniMax OAuth plugin + onboarding option. (#4521) Thanks @Maosghoul. - Agents: update pi SDK/API usage and dependencies. +- Gateway: inject timestamps into agent and chat.send messages. (#3705) Thanks @conroywhitney, @CashWilliams. - Web UI: refresh sessions after chat commands and improve session display names. - Build: move TypeScript builds to `tsdown` + `tsgo` (faster builds, CI typechecks), update tsconfig target, and clean up lint rules. - Build: align npm tar override and bin metadata so the `openclaw` CLI entrypoint is preserved in npm publishes. diff --git a/src/gateway/server-methods/agent-timestamp.ts b/src/gateway/server-methods/agent-timestamp.ts index 3dcb71834..51b6d1907 100644 --- a/src/gateway/server-methods/agent-timestamp.ts +++ b/src/gateway/server-methods/agent-timestamp.ts @@ -1,6 +1,6 @@ import { resolveUserTimezone } from "../../agents/date-time.js"; import { formatZonedTimestamp } from "../../auto-reply/envelope.js"; -import type { MoltbotConfig } from "../../config/types.js"; +import type { OpenClawConfig } from "../../config/types.js"; /** * Cron jobs inject "Current time: ..." into their messages. @@ -39,19 +39,27 @@ export interface TimestampInjectionOptions { * @see https://github.com/moltbot/moltbot/issues/3658 */ export function injectTimestamp(message: string, opts?: TimestampInjectionOptions): string { - if (!message.trim()) return message; + if (!message.trim()) { + return message; + } // Already has an envelope or injected timestamp - if (TIMESTAMP_ENVELOPE_PATTERN.test(message)) return message; + if (TIMESTAMP_ENVELOPE_PATTERN.test(message)) { + return message; + } // Already has a cron-injected timestamp - if (CRON_TIME_PATTERN.test(message)) return message; + if (CRON_TIME_PATTERN.test(message)) { + return message; + } const now = opts?.now ?? new Date(); const timezone = opts?.timezone ?? "UTC"; const formatted = formatZonedTimestamp(now, timezone); - if (!formatted) return message; + if (!formatted) { + return message; + } // 3-letter DOW: small models (8B) can't reliably derive day-of-week from // a date, and may treat a bare "Wed" as a typo. Costs ~1 token. @@ -63,9 +71,9 @@ export function injectTimestamp(message: string, opts?: TimestampInjectionOption } /** - * Build TimestampInjectionOptions from a MoltbotConfig. + * Build TimestampInjectionOptions from an OpenClawConfig. */ -export function timestampOptsFromConfig(cfg: MoltbotConfig): TimestampInjectionOptions { +export function timestampOptsFromConfig(cfg: OpenClawConfig): TimestampInjectionOptions { return { timezone: resolveUserTimezone(cfg.agents?.defaults?.userTimezone), };