fix: prevent stale markdown preview cache in app://md-preview protoco…#2387
Open
dushyant-hada-90 wants to merge 12 commits into
Open
fix: prevent stale markdown preview cache in app://md-preview protoco…#2387dushyant-hada-90 wants to merge 12 commits into
dushyant-hada-90 wants to merge 12 commits into
Conversation
…l handler Add Cache-Control: no-cache, no-store, must-revalidate headers to the app://md-preview protocol handler response so Chromium does not cache the rendered HTML. When the file-backed markdown changes, the chokidar watcher updates the cached HTML in MarkdownHost and emits md:fileChanged; the renderer calls reload(), which re-requests the URL. Without cache prevention headers, Chromium served the stale cached copy instead of re-invoking the protocol handler for the updated HTML.
…mon proxy URL file watching The markdown auto-refresh failed for daemon-proxied URLs because: 1. Chromium cached the app://md-preview response (Cache-Control fix already deployed) 2. Daemon proxy URLs (http://host/api/v1/sessions/<id>/preview/files/<entry>) bypassed chokidar watchers since resolveLocalPath() only handled file:// Fix: - Backend: sessionView() populates WorkspacePath from SessionMetadata - API: SessionView DTO + regenerated OpenAPI spec + TypeScript types - Frontend: workspacePath flows SessionView → BrowserPanel → useBrowserView → preload → markdownHost.render() → resolveLocalPath() - markdown-host.ts: parseDaemonProxyEntry() extracts entry from proxy URL and resolves it against workspacePath with directory traversal guard - Test: removed negative assertion for workspacePath leak (now curated field)
…roaden BrowserPanel path normalization - Replace httpFetch() with native fetch() — simpler, standard, no extra deps - Add tryLocalFile() fallback for UNC/drive-letter paths that fail fileURLToPath - Guard file:// URLs from reaching fetch() to avoid ERR_INVALID_PROTOCOL - Broaden BrowserPanel path normalization to handle UNC (\\host) and Windows drive-letter (C:\) paths - Remove md_implementation.md from git tracking (internal reference doc, not intended for remote)
…kill instructions
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.
Overview
This PR adds live markdown preview in the Electron browser panel alongside
ao previewCLI support, file-watching with auto-refresh, and CSS-only theme control. The implementation spans backend (daemon + CLI), frontend (Electron main/renderer/preload), and agent skill assets.Features
Markdown rendering in browser panel
.mdfiles are rendered to styled HTML viamarked+DOMPurifyinside the Electron BrowserView using a customapp://md-previewprotocol handlerCache-Control: no-cache, no-store, must-revalidate) soreload()always fetches fresh contentchange, and the renderer callsreload()on the BrowserViewao previewCLI commandao preview [url]— opens a URL in the desktop browser panel for the current session; with no argument, opens the workspace'sindex.htmlao preview clear— empties the panel$AO_SESSION_IDreturns a usage errorDaemon preview endpoints
POST /api/v1/sessions/{id}/preview— set preview URL; accepts file paths (resolved tofile://), HTTP URLs, or daemon-proxy URLsDELETE /api/v1/sessions/{id}/preview— clear preview; autodetectsindex.htmlin the workspace or falls back to blanksession_updatedevent) to the rendererFile deletion handling
.mdfile is deleted, the daemon DELETE endpoint is called, reverting toindex.html(if it exists) or clearing to blank — no stale content, no error pageMarkdownHostviareportBoundPort→setDaemonPort()for the HTTP DELETE callCSS-only dark/light theme toggle
<label for>hack withbody:has(#theme-toggle:checked)selectorsbody:has()instead of.content(fixes white border frommax-width: 920px)transition: color 0.25s/background 0.25sscript-src 'none')Agent auto-preview instructions
SKILL.mdupdated to direct agents to runao preview <path>immediately after creating a.mdfile.mdfiles, only the last one is auto-previewed (panel shows one at a time)Key changes by layer
internal/httpd/controllers/sessions.gointernal/cli/preview.goao previewcommand with relative path resolutioninternal/cli/preview_test.gomain.ts,markdown-host.ts,markdown-renderer.tspreload.tsrenderMarkdown/md:fileChangedcomponents/BrowserPanel.tsx,hooks/useBrowserView.tsbackend/internal/skillassets/markdown-preview/SKILL.mdTesting
go test ./internal/...andgo vet ./internal/...