feat(hooks): live per-turn time context (fixes stale session-start date)#1511
Open
anikinsasha wants to merge 1 commit into
Open
feat(hooks): live per-turn time context (fixes stale session-start date)#1511anikinsasha wants to merge 1 commit into
anikinsasha wants to merge 1 commit into
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The harness injects
currentDateas 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
UserPromptSubmithook (TimeContext.hook.ts) that recomputes the wall clock every turn and injects it asadditionalContext:Because it recomputes per turn, the value can never drift within a session.
Notes
settings.jsonprincipal.timezone(the same sourcelib/time.tsreads), falling back to UTC. Read inline so a config problem can't break the hook.hooks/hooks.jsonunderUserPromptSubmit(5s timeout), alongside the existing per-turn hooks.Running on a live install. Happy to adjust the format or the relative-label thresholds.