Skip to content

feat(console): selected_at anchor recovers item window on stale shared link#19

Open
vaderyang wants to merge 2 commits into
mainfrom
feat/selected-at-anchor
Open

feat(console): selected_at anchor recovers item window on stale shared link#19
vaderyang wants to merge 2 commits into
mainfrom
feat/selected-at-anchor

Conversation

@vaderyang
Copy link
Copy Markdown
Collaborator

Stacked on top of #18 — base is `feat/selected-id-in-url`. The diff against `main` here shows only the anchor work.

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:

  1. 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.

  2. `useToolbarUrlSync` hydration reads the anchor. If it falls outside the preset-derived window:

    • keep the preset's duration (the original user's "show me this much context" signal),
    • slide so `end = anchor + 60s` (small 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`.

    No-op when the anchor is inside the window, absent, unparseable, or already covered.

  3. Pure helper `applySelectedAtAnchor` in its own module (`selected-at-anchor.ts`, no `@/` aliases) so it's directly testable under bun. 7 unit tests:

    • no-op: missing param, unparseable param, anchor inside window
    • shift: 15m window, anchor 30 min ago → custom window of 15m ending at anchor+60s
    • default 1h window when no preset in URL
    • 1h duration preserved across an arbitrary shift
    • clock-skew / future-dated anchor

Behaviour summary

Scenario Before After
Original tab clicking around (preset=15m) Toolbar stays relative, ticks every refresh Same — anchor only affects fresh URL loads
Recipient opens shared URL within window Works Same
Recipient opens shared URL after window moved Panel opens but list is empty / unrelated Window auto-widens to bracket the item; list, highlight, prev/next all work
Recipient opens URL with anchor older than retention Panel 404s Window slides correctly but item itself is gone (no help possible)

Verification

  • `bun test` — 104 pass (7 new for the anchor logic)
  • `npm run build` — green
  • Deployed to wuneng (bundle index-ZiliosRk.js)

Test plan

  • Open a row in Agent Turns → URL now contains `?selected=&selected_at=<unix_s>`
  • Wait > 15 minutes
  • Open the same URL in a new tab → list re-anchors around the item, panel opens, prev/next active
  • Same flow for LLM Calls and HTTP Exchanges
  • Original tab: switching presets still snaps to `now` (not `custom`) — confirm the anchor doesn't leak into post-mount behaviour

🤖 Generated with Claude Code

…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>
@vaderyang vaderyang changed the base branch from feat/selected-id-in-url to main May 19, 2026 07:50
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