Skip to content

feat(hooks): live per-turn time context (fixes stale session-start date)#1511

Open
anikinsasha wants to merge 1 commit into
danielmiessler:mainfrom
anikinsasha:feat/live-time-context-hook
Open

feat(hooks): live per-turn time context (fixes stale session-start date)#1511
anikinsasha wants to merge 1 commit into
danielmiessler:mainfrom
anikinsasha:feat/live-time-context-hook

Conversation

@anikinsasha

Copy link
Copy Markdown

Problem

The harness injects currentDate as a date-only value anchored at session start. On a long-running session it goes stale: hours after midnight the assistant still reasons from the session-start date, and with only a date (no time) it can't distinguish morning from midnight. This causes small but real errors — greeting with the wrong time of day, scheduling against yesterday, "it's morning" at 1am.

Fix

A small UserPromptSubmit hook (TimeContext.hook.ts) that recomputes the wall clock every turn and injects it as additionalContext:

<time-now>
🕐 Current time: Thu 2026-07-16 08:48 PDT (early morning)
(The harness date line is date-only and can be stale mid-session — trust this live value.)
</time-now>

Because it recomputes per turn, the value can never drift within a session.

Notes

  • Timezone comes from settings.json principal.timezone (the same source lib/time.ts reads), falling back to UTC. Read inline so a config problem can't break the hook.
  • Fails open: any error is swallowed; the turn proceeds without the line. A timestamp is nice-to-have, never worth blocking a prompt.
  • Registered in hooks/hooks.json under UserPromptSubmit (5s timeout), alongside the existing per-turn hooks.
  • No new dependencies; ~40 lines.

Running on a live install. Happy to adjust the format or the relative-label thresholds.

The harness currentDate context is date-only and anchored at session start,
so on a long session it goes stale — the assistant can believe it is still
morning hours after midnight. TimeContext recomputes the wall clock every
turn and injects it as additionalContext, so the value cannot drift.

- Timezone from settings.json principal.timezone (same source as lib/time.ts),
  UTC fallback; read inline so a config hiccup cannot break the hook.
- Fails open: any error is swallowed, the turn proceeds without the line.
- Registered in hooks.json under UserPromptSubmit (5s timeout).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant