Skip to content

md: add local markdown link navigation within CWD sandbox#102

Closed
tig wants to merge 1 commit into
developfrom
feature/md-local-link-navigation
Closed

md: add local markdown link navigation within CWD sandbox#102
tig wants to merge 1 commit into
developfrom
feature/md-local-link-navigation

Conversation

@tig
Copy link
Copy Markdown
Member

@tig tig commented May 6, 2026

Summary

Prep for gui-cs/Terminal.Gui#5220 (which adds Link.SafeSchemes and blocks file:// by default).

Clicking a relative .md link in the markdown viewer now navigates to that file in-place. The sandbox is CWD — links that resolve outside the working directory are blocked by default and remain SurfaceOnly (URL shown in status bar).

Behavior

Link type Default With --allow-external-links true
Relative .md within CWD Navigate in viewer Navigate in viewer
Relative .md outside CWD SurfaceOnly (status bar) Navigate in viewer
file:// to .md within CWD Navigate in viewer Navigate in viewer
http://, https://, mailto: SurfaceOnly SurfaceOnly
Non-.md files SurfaceOnly SurfaceOnly

How it works

  • TryResolveLocalMarkdownLink resolves URLs relative to the currently-viewed file's directory
  • Fragment anchors (#section) are stripped before path resolution
  • Path traversal (e.g. ../../etc/passwd.md) is caught by the sandbox check
  • currentFileDir is updated on each navigation so chains of relative links work
  • --allow-external-links is a clet-specific option (passed as --allow-external-links true)

Relation to D-017/D-031

The SurfaceOnly policy (D-017, D-031) is preserved for all non-local links. --allow-link-open (browser opening) remains deferred. This PR only adds in-viewer navigation between local markdown files.

Test plan

  • 6 new unit tests for TryResolveLocalMarkdownLink (sandbox, external, HTTP, non-md, fragment)
  • All 283 unit tests pass
  • Manual: clet md README.md → click a relative link like [spec](specs/clet-spec.md) → navigates
  • Manual: link outside CWD → shows URL in status bar, does not navigate
  • Manual: --allow-external-links true → permits navigation outside CWD

Spec/decisions impact

  • specs/decisions.md — needs a D-NNN entry for the sandbox boundary decision
  • specs/clet-spec.md — Appendix A link policy section should mention in-viewer navigation
  • README Available Clets table — add --allow-external-links to md options

(Will update docs once the design is confirmed.)

🤖 Generated with Claude Code

Clicking a relative .md link in the viewer now navigates to that
file in-place, provided it's within the CWD sandbox. Links outside
CWD, to non-markdown files, or using http/https remain SurfaceOnly
(shown in the status bar).

New --allow-external-links option opts in to following markdown
links outside the working directory.

Prep for gui-cs/Terminal.Gui#5220 which adds Link.SafeSchemes and
blocks file:// by default.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tig
Copy link
Copy Markdown
Member Author

tig commented May 6, 2026

Closing — this work will be done as part of #96 (file-access confinement for clet md).

@tig tig closed this May 6, 2026
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.

1 participant