Skip to content

feat(workbench,workspace-files): open external file links in read-only Stage preview - #7599

Merged
M4n5ter merged 1 commit into
mainfrom
feat/external-file-links
Dec 5, 2026
Merged

M4n5ter merged 1 commit into
mainfrom
feat/external-file-links

Conversation

@M4n5ter

@M4n5ter M4n5ter commented Dec 4, 2026

Copy link
Copy Markdown
Member

Summary

Previously, clicking an agent-emitted local file link outside the active session workspace failed for almost all files:

  1. resolveFileLink / readFile applied the Agent's sandbox policy to user-activated clicks instead of enforcing user-client identity.
  2. host.openLink reused the inline-image pipeline (read_external_image) and threw This file is not a supported image. for every non-image external file (source code, Markdown, binaries, directories).
  3. Stage CurrentFile and resolveRevealTarget only accepted workspace-relative WorkspacePath.

This PR fixes the contract cleanly without auto-executing clicked links (preserving click-to-RCE safety against prompt-injected links):

  • Backend identity & read-only external reads (workspace-files/engine, agent/api, agent/native):
    • Explicitly enforce user-client identity (Native | Remote, rejecting Agent | Background | BrowserLease) on resolveFileLink, readFile, and resolveRevealTarget, decoupling human clicks from the Agent's managed sandbox policy (while keeping Sandbox::External rejection for non-local workspaces).
    • Support ~ / ~/ expansion in Directory::resolve_link and map paths outside the editable workspace (including .git metadata) to read-only FileReadPath::External.
    • Replace read_external_image with Directory::read_external_file (UTF-8 text, validated images, first-chunk binary short-circuit to avoid buffering large binaries, symlink resolution, and clean Directory / Absent states).
    • Extend WorkspaceFileReveal.path to FileReadPath (wire-compatible untagged enum), add Directory::reveal_external_target, and expose openWorkspaceFile on local desktop bindings via the same resolveRevealTarget local-Host verification.
  • Workbench / Stage / Web UI (workbench, workspace-files/ui, web-nsh, plugin-sdk, locales):
    • Remove the This file is not a supported image. restriction from host.openLink; route both workspace and external FileReadPath targets into Stage CurrentFile.
    • Render external files in read-only mode (Editor readOnly, read-only formatted Markdown via TextView, no watchFiles / saveFile / workspace LSP), display the full external path, preserve #L line-anchor highlights, and provide explicit Reveal in Finder / Show in File Explorer and Open in default app actions on local desktop.
    • Fix webHost.parseMarkdownLink to parse file://, #L anchors, and base64 pathBytes, regenerate packages/plugin-sdk, and sync all 12 locale catalogs.

Verification

  • cargo test -p maka-fs-tools (60/60 passed, including external text/binary/directory/missing/symlink/~ expansion/reveal tests)
  • cargo test -p maka-agent-native --lib -- owner::files
  • node --test products/maka/workbench/tests/conversation-resources.test.mjs products/maka/workbench/tests/session-links.test.mjs products/maka/web-nsh/tests/web-foundation.test.mjs (42/42 passed)
  • node scripts/ci.mjs run contracts, node scripts/i18n/check.mjs, and biome check
  • Verified live in an isolated Maka Preview desktop instance (--root /tmp/...) clicking external code (#L8-L12), Markdown, binary, and directory links:

External Rust source with #L8-L12 anchor

External Rust file opened read-only with #L8-L12 highlight and path/actions

External Markdown document (read-only formatted preview)

External Markdown file opened in read-only preview

External binary file (full path + Reveal / Open in default app)

External binary file showing full path with Reveal and Open in default app

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The read-only Stage view is a useful distinction from the explicit desktop open action. The main concern is that the new preview path also changes an existing file-access exclusion. Please keep protected paths separate from ordinary files outside the workspace before merging.

I checked the Host, desktop and web routing, the generated method, and the user-facing file states. The three focused JavaScript suites passed 42/42 on this commit and 41/41 on its base. The browser parser also handled ordinary file URLs and line-range anchors in isolation. The fast PR check passed, but it did not run the native file-access tests. This commit conflicts with current main in CurrentFile.tsx, so I have not verified the combined desktop flow or mixed-version Host calls.


Automated review notice: This comment was posted by an automated review agent operated by Astro-Han. It is not an independent human review and does not replace one.

};
let workspace = |candidate: &Path| -> io::Result<Option<FileReadPath>> {
if self.excluded(candidate) || has_git_segment(candidate) {
return Ok(None);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Keep explicit filesystem exclusions separate from external preview eligibility. This branch now puts product-private paths and ordinary out-of-workspace files into the same category. Making the editor read-only does not preserve the original access rule. Keep the hard exclusion in the Host policy shared by preview, reveal, and open, and add a negative authorization test alongside the normal external-file case.

Comment thread products/maka/web-nsh/src/webHost.tsx Outdated
let line: number | null = null;
let endLine: number | null = null;
let column: number | null = null;
const anchorMatch = /^[Ll](\d+)(?:[Cc:](\d+))?(?:-[Ll]?(\d+))?$/.exec(fragment.trim());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] The browser still treats a normal desktop-style link such as src/locate.ts:7:4 as a literal filename. I checked the actual parser separately from the Stage test, which mocks the link resolver. Please reuse the desktop line-and-column contract or add a browser test documenting that only fragment anchors are supported.

…y Stage preview

Previously, clicking any agent-emitted file link outside the active session
workspace went through the Agent sandbox read policy and read_external_image,
causing every non-image external file (code, Markdown, binary, directory) to
fail with "This file is not a supported image." or "This conversation cannot
read that path."

Fix the contract end-to-end:
- Enforce user-client identity (Native/Remote, rejecting Agent/Background/
  BrowserLease) on resolveFileLink, readFile, and resolveRevealTarget instead
  of applying the Agent's sandbox policy to user-activated link clicks.
- Replace read_external_image with read_external_file (with first-chunk binary
  short-circuiting, symlink resolution, directory/missing reporting, and ~
  home expansion in resolve_link).
- Extend WorkspaceFileReveal.path to FileReadPath and add openWorkspaceFile on
  the local desktop Host binding so users can explicitly reveal or open both
  workspace and external files without auto-executing clicked links.
- Support FileReadPath in WorkspaceFileTarget, Stage tabs/history, and
  CurrentFile in read-only mode (showing the full external path, line anchor
  highlights, read-only Markdown/Editor views, and explicit Reveal / Open in
  default app actions).
- Align webHost.parseMarkdownLink with file://, #L anchors, and base64
  pathBytes, regenerate plugin-sdk contracts, and update locales & tests.

Generated-by: Maka
@M4n5ter
M4n5ter force-pushed the feat/external-file-links branch from 7b99d85 to 1d6b3b8 Compare December 5, 2026 02:52

@jackwener jackwener left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved at M4n5ter's direction for commit 1d6b3b869079a9cf7df2f31b18cf494a08bee446.

The browser parser now handles file links with line and column suffixes. All 43 focused Workbench and Web tests, the localization check, and the required GitHub check passed. The commit applies cleanly to main at e86d744a. My verification covered the source and automated checks. The native Host tests and live desktop interactions are outside that coverage.

The previously reported concern about product-private paths remains. Please preserve the Host's existing path exclusions across preview, reveal, and open, and add an authorization regression test. The commit attributes substantive assistance to Maka. Please also record its scope in the PR description.


Automated review notice: This comment was posted by an automated review agent operated by jackwener. It is not an independent human review and does not replace one.

@M4n5ter
M4n5ter merged commit 5933626 into main Dec 5, 2026
1 check passed
@M4n5ter
M4n5ter deleted the feat/external-file-links branch December 5, 2026 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants