Remove the blanket .agent/ gitignore so the phase roadmap, user stories, reports, and PLAN.md are versioned with the code. Only runtime artifacts (.agent/phase-sessions/, .agent/pipeline.log) remain ignored. Update AGENTS.md git protocol rule to match.
2.3 KiB
2.3 KiB
Phase 13 — Document Back Button Returns to Where You Came From
Story: .agent/user_stories/document-back-navigation.md
Context: owner report 2026-08-22 — "clicking a document from the
chat tab pulls up the document correct, but the back button goes back to
sources, not the chat."
Goal
The viewer's back button returns to the page the document was opened from: chat chip → Chat; Sources table → Sources.
Diagnosis
Chips/links open the viewer with target="_blank". In the fresh tab
window.history.length is 1, so document.js's heuristic
(history.length > 1 ? history.back() : href) always falls through to
the static href="/sources.html" — wrong for chat-originated visits.
Implementation steps
- Chat chips (
frontend/assets/app.js):documentUrl(source, path, back = "/")— appends&back=<encoded>; chat passes"/". Existing phase-10 E2E href assertion updates to include&back=%2F. - Sources links — unchanged: no
backparam in the URL; the viewer's default target is/sources.html, so the phase-10 assertion stays green. - Viewer (
frontend/document.js):- Resolve back target:
backparam wins only when it is a same-origin relative URL (starts with/, not//); otherwise/sources.html. (Rejectshttps://…,//…,javascript:….) - Set
#doc-backhref + label:/→ "Chat",/sources.html→ "Sources", anything else relative → "Back". - Click: deterministic navigation to the resolved target (drop the
history.lengthheuristic — both entry points are new tabs, and determinism is what the story demands). - The static
href="/sources.html"indocument.htmlremains the no-JS fallback.
- Resolve back target:
- E2E:
tests/e2e/test_document_back_navigation.pyper the story mapping; updatetest_document_viewer.pychip-href assertion.
Locked decisions
None. A10/A11 untouched (no new endpoint, no new asset).
Testing & Quality
- E2E in isolation (new file) +
test_document_viewer.pyregression in isolation. - Coverage gate unchanged (frontend-only phase).
Commit
git add -A .agent/ frontend/ tests/e2e/ && git commit --no-gpg-sign -m "fix(ui): document viewer back button returns to the page you came from (chat or sources)"