Conversation
2 tasks
…or html and media preview
kolawong
force-pushed
the
fix/preview-relative-workspace-paths
branch
from
September 24, 2026 03:06
6923048 to
7ed13e6
Compare
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.
Fixes #692. Extends #689.
Symptom
When opening or previewing a workspace-relative file (e.g.
pelican-bicycle.htmlor files emitted by agent tools) in the editor's HTML preview or media preview, the route failed with 400 ENOENT:{"ok":false,"error":{"code":"fs-error","message":"cannot resolve target \"/pelican-bicycle.html\": ENOENT: no such file or directory, realpath '/pelican-bicycle.html'"}}Root Cause
htmlUrlandfileUrlinsrc/client/api.tspassed relative file paths (e.g.pelican-bicycle.html) directly intoencodeHtmlUrlor the query param without resolving againstscope.cwd.decodeHtmlUrldecoded the pathname, it prepended/, turningpelican-bicycle.htmlinto root/pelican-bicycle.html.ensureWorkspacePath(cwd, "/pelican-bicycle.html"), which treated it as an absolute path at the host root/rather than the session workspace, throwingENOENT: realpath '/pelican-bicycle.html'.Changes (Defense in Depth)
src/client/api.ts):htmlUrl: resolve relative path againstscope.cwdviaresolveSidebarPathbefore encoding.fileUrl: resolve relative path againstscope.cwdviaresolveSidebarPathbefore settingpathsearch parameter.src/index.ts):/sidebar/htmland/sidebar/file: if the decoded path is not within the session workspacecwd, try candidatejoin(cwd, target.replace(/^[\/\\]+/, '')). If candidate is withincwd, resolve to candidate safely.tests/paths.spec.ts):htmlUrlandmediaUrl/downloadUrl.Verification
pnpm testpassed (127 test files, 1347 tests passed).pnpm typecheck(tsc --noEmit) clean./sidebar/html/<sessionId>/pelican-bicycle.htmlreturns HTTP 200 OK with full HTML content rendered properly in the preview iframe.