Knowledge Slug + Router Sync Plan
Goal
Allow Sasha’s Knowledge view to use clean /knowledge/<slug> URLs that deep-link to specific HTML documents, while keeping the existing iframe-based renderer and ?doc= backward compatibility.
Constraints & Considerations
- The iframe (
/api/docs-content/index.html) already handles internal navigation and posts updates viadocs:navigation. - React Router currently only has
/and/session/:idroutes inside the authenticated app. - FileTree uses the
docquery param to highlight selections and open preview drawers. DocsPanelexpects thedocquery param and callsapi.docsResolveto find the HTML preview URL.- We must keep existing deep links (
?doc=guides/foo.md) working while adding slug-based routing.
High-Level Steps
Add Router Support
- Register a dedicated React route for
/knowledge/*that renders the sameAppContent. - Decide on a canonical base (e.g.,
/knowledge), handling trailing slashes and encoded segments.
- Register a dedicated React route for
Map Slug ⇄ Doc Path
- Derive a helper that converts a slug path segment to the underlying doc reference:
- If slug ends with
.htmlor.md, keep it. - Otherwise assume
.mdwhen callingdocsResolve.
- If slug ends with
- Mirror helper to convert iframe paths (e.g.,
/api/docs-content/foo/bar.html) into/knowledge/foo/bar.
- Derive a helper that converts a slug path segment to the underlying doc reference:
Update DocsPanel Source Resolution
- Parse both
location.pathnameandlocation.search. - Prefer
/knowledge/<slug>when present; fall back to?doc=for legacy links. - Feed the resolved reference into
api.docsResolveand keep existing polling/cache-busting logic intact.
- Parse both
Sync Browser URL With iframe Navigation
- When receiving
docs:navigation, strip/api/docs-content/and.htmlto get the slug. - If the top-level route is not already
/knowledge/<slug>, callnavigate()withreplace: true. - Ensure this update preserves query params (notably
doc) for backwards compatibility until we drop them.
- When receiving
Keep FileTree UX Intact
- When a Markdown node opens:
- Continue setting
doc=<path>for compatibility. - New: navigate to
/knowledge/<relative-path-without-extension>(URL-encode segments).
- Continue setting
- When a non-doc node is selected (or the preview closes), clear the slug route back to
/(or the last non-knowledge route). - On mount, if the route is
/knowledge/..., ensure the tree highlights the matching file (derive the doc path from the slug and setselectedMarkdown).
- When a Markdown node opens:
Handle Back/Forward / Direct Loads
- Use a
useEffectinAppContent(orDocsPanel) that watcheslocation.pathname. - When it matches
/knowledge/<slug>, push the equivalentdocparam (unless already set) so the FileTree effect fires and opens the preview drawer. - When navigating away from
/knowledge, optionally clear thedocparam.
- Use a
Testing Checklist
- Deep links: open
/knowledge/guides/foodirectly → iframe loads correct content. - Legacy links: open
/?doc=guides/foo.md→ auto-redirect or display the doc while keeping slug synced. - Internal navigation: clicking links inside the Knowledge sidebar updates the top-level URL and the browser back button walks history.
- File tree interactions: selecting docs updates both slug + iframe; closing resets to chat route.
- Mobile Knowledge view still works (menu toggles, breadcrumbs, etc.).
- Deep links: open
Rollout / Docs
- Update developer docs (e.g.,
docs/technical/implementation/documentation-system-quick-reference.md) with the new slug behavior. - Communicate that
/knowledge/...URLs are now shareable and stable.
- Update developer docs (e.g.,
Open Questions
- Should we immediately redirect
?doc=links to/knowledge(301/replace) or keep both indefinitely? - Do we want hash fragments for headings (future enhancement) or rely on iframe internal anchors?
- Should bookmarks include
.mdor drop the extension for readability?
Next Steps
- Implement router + helper utilities.
- Update DocsPanel and FileTree per the above.
- Run through the testing checklist.
- Document behavior changes for support/dev teams.