feat(preview): agent driven browser previews + Markdown rendering#2455
Open
aprv10 wants to merge 3 commits into
Open
feat(preview): agent driven browser previews + Markdown rendering#2455aprv10 wants to merge 3 commits into
aprv10 wants to merge 3 commits into
Conversation
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.
Problem
The desktop browser panel could only ever auto-open a file literally named
index.html(or itspublic/dist/buildvariants). Anything else an agent produced — a standalonereport.html, a chart, a Markdown write-up — could not be surfaced in the panel. Markdown was doubly broken: even when pointed at directly,.mdfiles were served byhttp.ServeFileastext/plain, so the webview showed raw source instead of a rendered document.We wanted the agent to decide what to show (similar to how an artifact-aware coding tool opens a preview), while keeping
index.htmlauto-opening as a zero-effort fallback.What changed
preview/filesroute now converts.md/.markdownto a styled, self-contained HTML document (goldmark + GitHub-flavored extensions: tables, task lists, strikethrough, autolinks) and serves it astext/html. All other files are served verbatim as before, so the frontend needs no changes — a.mdURL simply returns rendered HTML.ao preview <file>proactively for artifacts a human should see (HTML pages, reports, charts, Markdown docs). This is the mechanism that makes "the agent decides what to open" actually happen; the command doc already documented the CLI usage.DiscoverIndexEntry(index anchors only) andDiscoverEntry(index, then most-recently-modified previewable file). The background poller now uses index-only, so it auto-opens a real app entry but never guesses at loose files. The full most-recent fallback is kept only for a bare, agent-initiatedao preview.The bug found and fixed along the way
While testing,
ao preview report.htmlappeared to do nothing: the panel stayed blank and the session'spreviewRevisionkept climbing whilepreviewUrlstayed empty. Root cause: after the poller became index-only, any workspace without anindex.htmlmade it treat the agent's own/preview/files/...URL as stale and clear it on every ~250ms cycle — erasing the agent's explicit preview almost immediately. The poller now clears a preview only when it itself opened it for anindex.htmlthat has since disappeared, and never touches a preview the agent set explicitly.Testing
go test ./internal/preview/... ./internal/httpd/controllers/...— passes. New/updated tests cover: index precedence and most-recent fallback, the index-only discovery used by the poller, Markdown rendering (HTML document, GFM table, title escaping), the poller ignoring loose non-index files, and the regression fix (TestPollerPreservesExplicitNonIndexPreview— the poller must leave an agent-set non-index preview untouched across multiple poll cycles).index.htmlstill auto-opens;ao preview sample.htmlandao preview test.md(relative paths) both persist and render, with Markdown shown as a formatted document rather than raw text.Files affected
backend/internal/preview/entry.go— split discovery intoDiscoverIndexEntry(index-only) andDiscoverEntry(index + most-recent fallback); addedIsMarkdownPath.backend/internal/preview/markdown.go(new) — goldmark-basedRenderMarkdownwith an embedded light/dark stylesheet.backend/internal/preview/poller.go— poller uses index-only discovery and only clears previews it opened, never the agent's.backend/internal/httpd/controllers/sessions.go—previewFilerenders Markdown to HTML; other files unchanged.backend/internal/session_manager/manager.go— standing worker prompt block instructing proactiveao preview <file>.backend/internal/preview/entry_test.go,markdown_test.go(new),poller_test.go— coverage for the above.backend/go.mod,backend/go.sum— goldmark dependency (promoted from indirect).