feat(console): selected_at anchor recovers item window on stale shared link#19
Open
vaderyang wants to merge 2 commits into
Open
feat(console): selected_at anchor recovers item window on stale shared link#19vaderyang wants to merge 2 commits into
vaderyang wants to merge 2 commits into
Conversation
…d link
Builds on the previous PR (selected id in URL): copying a list page
URL like `?preset=15m&selected=<id>` and opening it half an hour
later would compute `start=now-15m, end=now` from scratch — the
selected item is no longer in that window. The detail panel still
loaded (it queries by id) but the list behind it showed an unrelated
slice, the row had no highlight, prev/next disabled.
Fix the window without changing the original tab's behaviour:
1. List pages also write `?selected_at=<unix_s>` when an item is
selected — taken from the item's start_time (agent turns) or
request_time (llm calls / http exchanges). Cleared together with
`selected` when the panel is closed.
2. `useToolbarUrlSync` reads `selected_at` during hydration. If the
anchor falls outside the preset-derived window, override:
- keep the preset's *duration* (the original user's "show me this
much context" signal),
- slide so `end = anchor + 60s` (small breathing pad keeps the
item from sitting flush at the edge in a desc-by-time list),
- promote `preset` to `custom` so subsequent URL writes carry
absolute start/end and the shift survives navigation.
No-op when the anchor is inside the window, absent, unparseable,
or future-dated relative to a window that already includes it.
3. Pure helper `applySelectedAtAnchor` lives in its own module
(`selected-at-anchor.ts`, no `@/` aliases) so it's directly
testable under bun without the toolbar-store / react-router
runtime chain. 7 unit tests cover the no-op cases, the stale-
preset shift, default-1h fallback, and clock-skew anchors.
Effects:
- Original tab: relative preset still ticks `now` as usual; no
surprise switch to `custom`.
- Fresh URL load: window auto-widens / slides to bracket the
shared item; list, highlight, prev/next all work.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Why
Copying a list URL like `?preset=15m&selected=` and opening it half an hour later: `start=now-15m, end=now` is computed from scratch, the selected item is no longer in that window. The detail panel still loaded (queries by id) but the list behind it was unrelated, the row had no highlight, prev/next disabled. Mid-experience drop.
Approach
Pin the item's wall-clock time alongside the id:
List pages write `?selected_at=<unix_s>` when an item is selected — from `start_time` (agent turns, microseconds) or `request_time` (llm calls / http exchanges, milliseconds). Cleared together with `selected` on close.
`useToolbarUrlSync` hydration reads the anchor. If it falls outside the preset-derived window:
No-op when the anchor is inside the window, absent, unparseable, or already covered.
Pure helper `applySelectedAtAnchor` in its own module (`selected-at-anchor.ts`, no `@/` aliases) so it's directly testable under bun. 7 unit tests:
Behaviour summary
Verification
Test plan
🤖 Generated with Claude Code