Repository navigation
Render a cmd-clicked markdown file as a themed overlay page - #866
Merged
Merged
Conversation
MarkdownPage builds the document a bundled renderer fills: the source as escaped text, local pictures inside the file's folder (symlinks resolved before the containment check) embedded once each, and a CSP that loads only data: pictures. MarkdownProbe reads the file through BoundedFile, the descriptor check ImageProbe now shares, and embeds pictures within a total byte and pixel budget.
HtmlSource.markdown is a themed page with no file grant or bridge. The registry reads it through MarkdownProbe and renders it with the bundled markdown-it and highlight.js, run as an app-owned user script in its own content world with the page's JavaScript off. Pictures are emitted only as the data URIs the app embedded, links keep only http(s) targets and fragments, and headings get GitHub-style ids. Theme styling is separated from bridge eligibility; browser hand-off is refused for a markdown page. The tree reports htmlOverlays[].markdown.
session.overlay.open takes markdownFile, its own field since markdown is the HUD's flag: an absolute .md or .markdown path, exclusive with every other source and refused with the program and page flags, and refused as a page companion. The app checks the file's descriptor before opening, and the CLI sends --markdown FILE resolved to an absolute path.
A local .md or .markdown path, bare or file://, routes like an image: a pane or the scratch terminal renders it over the owning session at the link-open size (95 in browser mode, so cmd-shift outside mouse capture asks for that), and every other origin, or a refused open, reveals the file. The click checks the file's descriptor off the main actor and rechecks the HUD, zoom and slot before opening. Tests whose .md paths stood for a revealed file use .txt.
…imit The image and markdown checks of session.overlay.open move into their page files (openImageFile, markdownFileRefusal), one line each at the call site. The markdown read-back and request encoding tests move beside the projection and CLI tests that build them.
The user guide's local-path paragraph covers markdown files, the command reference gains overlay open --markdown and the markdown read-back field, the bundled skill gets a trigger, a section and a reference entry, and the control-api rules describe the page, its routing and the theme/bridge split.
…se file: references a picture now renders as a placeholder whose data URI is set through the DOM, so a repeated reference no longer copies the whole payload into the markup string, and at most 256 pictures show. file: references were read but dropped by the renderer, so they are refused before any read.
…r time a quote fused with a combining mark is one Character that matched no escape case, so a picture name could close the image-map attribute and add attributes of its own. escaping now walks scalars. a run of identical headings probed every earlier suffix for each heading; a per-base cursor keeps it linear while the used-id check still catches an authored suffixed heading.
Deploying agterm with
|
| Latest commit: |
88c429f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://b55a9403.agterm.pages.dev |
| Branch Preview URL: | https://markdown-link-overlay.agterm.pages.dev |
There was a problem hiding this comment.
🟡 Changes recommended
A critical check-to-open symlink race can embed images outside the document folder, alongside unresolved loose-task-list rendering, native probe-limit, and cached-image alias defects.
4 open issues
What changed in this PR
Extends the image-overlay behavior from #844 to local Markdown files, allowing users to preview themed documents within their session through ⌘-click or the control CLI.
Changes:
- Adds Markdown link routing,
--markdown FILE, validation, and source read-back. - Introduces themed rendering with highlighting, task lists, heading anchors, and bounded local-image embedding.
- Adds automated coverage and updates user, agent, and engineering documentation.
| File | Description |
|---|---|
| site/docs.html | Documents Markdown link previews. |
| site/commands.html | Documents CLI options and read-back. |
| project.yml | Bundles renderer assets and licenses. |
| plugins/agterm/skills/agterm/SKILL.md | Adds Markdown discovery and usage guidance. |
| plugins/agterm/skills/agterm/reference.md | Details Markdown command behavior and restrictions. |
| docs/plans/completed/20261102-markdown-link-overlay.md | Records implementation and verification plan. |
| agtermUITests/ControlHtmlOverlayUITests.swift | Tests rendering, read-back, and closing. |
| agtermTests/MarkdownProbeTests.swift | Tests file checks and image budgets. |
| agtermTests/MarkdownAssetsTests.swift | Checks bundled assets and dependency order. |
| agtermTests/HtmlOverlayRegistryTests.swift | Tests rendering, isolation, navigation, and reloads. |
| agtermTests/GhosttySurfaceViewInputTests.swift | Tests click routing and Finder fallback. |
| agtermTests/ControlServerLinkOverlayTests.swift | Tests Markdown opening and refusal paths. |
| agtermCore/Tests/agtermctlKitTests/OverlayCommandsTests.swift | Tests CLI validation and request encoding. |
| agtermCore/Tests/agtermCoreTests/MarkdownPageTests.swift | Tests escaping, image resolution, and containment. |
| agtermCore/Tests/agtermCoreTests/LinkPolicyTests.swift | Tests Markdown classification and routing. |
| agtermCore/Tests/agtermCoreTests/HtmlOverlayTests.swift | Tests Markdown identity and navigation policy. |
| agtermCore/Tests/agtermCoreTests/ControlDispatcherOverlayTests.swift | Tests dispatcher validation and routing. |
| agtermCore/Tests/agtermCoreTests/AppStoreTreeProjectionTests.swift | Tests Markdown source projection. |
| agtermCore/Tests/agtermCoreTests/AppStoreRemotePageTests.swift | Checks Markdown remains local-only. |
| agtermCore/Sources/agtermctlKit/SessionCommands.swift | Adds the --markdown CLI option. |
| agtermCore/Sources/agtermCore/MarkdownPage.swift | Builds escaped documents and resolves image references. |
| agtermCore/Sources/agtermCore/LinkPolicy.swift | Routes Markdown paths to session overlays. |
| agtermCore/Sources/agtermCore/HtmlOverlay.swift | Adds Markdown source and navigation behavior. |
| agtermCore/Sources/agtermCore/ControlProtocol.swift | Adds request field and validation errors. |
| agtermCore/Sources/agtermCore/ControlProjection.swift | Adds Markdown read-back field. |
| agtermCore/Sources/agtermCore/ControlDispatcher+Overlay.swift | Validates Markdown overlay requests. |
| agtermCore/Sources/agtermCore/ControlDispatcher+Companions.swift | Rejects Markdown page companions. |
| agtermCore/Sources/agtermCore/AppStore+RemotePage.swift | Excludes Markdown from remote presentation. |
| agtermCore/Sources/agtermCore/AppStore+HtmlOverlay.swift | Projects Markdown source paths. |
| agterm/Views/MarkdownProbe.swift | Reads Markdown and embeds bounded images. |
| agterm/Views/MarkdownAssets.swift | Loads bundled renderer and stylesheet. |
| agterm/Views/ImageProbe.swift | Extracts shared descriptor-based file reading. |
| agterm/Views/HtmlOverlayView.swift | Handles Markdown source display and toolbar behavior. |
| agterm/Views/HtmlOverlayRegistry.swift | Hosts isolated rendering and separates styling from bridge access. |
| agterm/Resources/markdown/render.js | Renders Markdown, images, anchors, and tasks. |
| agterm/Resources/markdown/page.css | Styles rendered content using terminal colors. |
| agterm/Resources/markdown/markdown-it-14.1.0.LICENSE | Includes markdown-it license. |
| agterm/Resources/markdown/highlight-11.11.1.LICENSE | Includes highlight.js license. |
| agterm/Ghostty/LinkOpener.swift | Dispatches Markdown clicks with fallback. |
| agterm/Control/ControlServer+SessionActions.swift | Checks Markdown files before opening overlays. |
| agterm/Control/ControlServer+RemoteCompanions.swift | Handles the new source in companion arguments. |
| agterm/Control/ControlServer+MarkdownPage.swift | Adds file checks and asynchronous click opening. |
| agterm/Control/ControlServer+ImagePage.swift | Extracts synchronous image-opening helper. |
| agterm/agtermApp.swift | Connects Markdown clicks to the control server. |
| .claude/rules/control-api.md | Documents Markdown boundaries and script lifecycle. |
Review effort: Balanced
| continue | ||
| } | ||
| guard bytes < MarkdownPage.maxImageBytes, pixels < MarkdownPage.maxImagePixels else { break } | ||
| guard case .success(let (probe, data)) = ImageProbe.load(path: image.path, maxBytes: MarkdownPage.maxImageBytes - bytes), |
Comment on lines
+66
to
+67
| const first = item.firstChild && item.firstChild.nodeType === Node.TEXT_NODE ? item.firstChild | ||
| : item.firstElementChild && item.firstElementChild.tagName === 'P' ? item.firstElementChild.firstChild : null; |
| if let known { embedded.references[image.reference] = known } | ||
| continue | ||
| } | ||
| guard bytes < MarkdownPage.maxImageBytes, pixels < MarkdownPage.maxImagePixels else { break } |
Comment on lines
+51
to
+52
| guard bytes < MarkdownPage.maxImageBytes, pixels < MarkdownPage.maxImagePixels else { break } | ||
| guard case .success(let (probe, data)) = ImageProbe.load(path: image.path, maxBytes: MarkdownPage.maxImageBytes - bytes), |
a loose list item starts with a newline text node, so its task marker stayed text; the renderer now reads the item's first paragraph. A budget used up exactly ended the embed loop and dropped later aliases of an embedded picture, so a spent budget now skips new files only. At most 256 distinct picture files are probed per page, failed probes included. The renderer separately caps displayed picture occurrences at 256.
|
@umputun I'm having a few issues with this.
|
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.



a ⌘-click on a
.mdor.markdownpath in terminal output now opens the file rendered as a page in the terminal's theme, over its own session, the way a picture path opens since #844. The same page opens fromagtermctl session overlay open --markdown FILE.The page is sized like other clicked links: the link-open mode's size, or 95% when links go to the browser. Code blocks are highlighted, task lists show their boxes, and headings get GitHub-style anchors, so a README's table of contents scrolls in place. Pictures kept in the file's own folder are embedded, up to 256 of them. Unembedded references parsed as images show alt text, unsupported syntax stays text, and the page fetches no network resources. Clicks in local panes and the scratch terminal render the file; a refused open reveals it in Finder.
The markdown comes from an arbitrary clicked path, so the page treats its content as untrusted:
BoundedFile(regular file, 4 MB cap), and pictures go through the same descriptor, signature and pixel checks as an image page, within one byte and pixel budget per page~and URL schemes are refused before file data is readdata:pictures and inline style#fragmentis turned into plain textfile://link is revealed, as pictures areDocs:
site/docs.html,site/commands.html, the agent skill and its reference,.claude/rules/control-api.md. The plan is indocs/plans/completed/20261102-markdown-link-overlay.md.