Skip to content

fix(web): open Windows absolute file paths in session viewer - #1113

Merged
heavygee merged 1 commit into
tiann:mainfrom
techotaku39:fix/web-windows-absolute-file-links
Jul 31, 2026
Merged

fix(web): open Windows absolute file paths in session viewer#1113
heavygee merged 1 commit into
tiann:mainfrom
techotaku39:fix/web-windows-absolute-file-links

Conversation

@techotaku39

@techotaku39 techotaku39 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • recognize Windows drive-letter absolute file paths in chat text
  • rewrite explicit Markdown links targeting Windows files to HAPI's internal session file route
  • support the same paths when wrapped in inline code, alongside the file-link ergonomics added by Peer #1120: file-path autolink ergonomics #1142
  • keep line suffix handling, extension filtering, and CLI workspace-boundary validation intact

Problem

Windows absolute paths such as C:\Users\dev\project\handoff.md could be rendered as custom c: URI links. Clicking them opened the custom URI confirmation dialog and then did nothing, especially when the HAPI web client was running on a different device from the session host.

HAPI already has a session-aware file viewer backed by the CLI ReadFile RPC. Relative file paths use that route, but Windows drive-letter paths were explicitly excluded from the Markdown file-path transform.

Implementation

  • extend the existing path matcher to recognize both C:\... and C:/... forms
  • convert recognized paths to the existing hapi-file: representation
  • rewrite explicit Markdown link nodes before URL serialization can interpret the drive letter as a URI scheme
  • continue stripping :line / :line:column suffixes from the read target
  • retain the existing known-extension allowlist

The web client does not read local files directly. Clicking the link still navigates to /sessions/:sessionId/file, and the CLI's existing validatePath() check rejects targets outside the session working directory.

Test plan

  • bun run --cwd web test src/lib/remark-file-path-links.test.ts
  • bun run --cwd web typecheck
  • bun run --cwd web test — 165 files / 1394 tests passed
  • bun typecheck
  • production Web and Hub builds
  • manual deployment on port 3016: HTTP 200, clean Hub stderr, Windows file links route through the session file viewer instead of the c: custom URI dialog

AI disclosure

Implementation and tests were prepared with OpenAI Codex assistance and manually reviewed.

@heavygee

Copy link
Copy Markdown
Collaborator

Adjacent (not overlapping): #1120 covers relative chat autolink footguns — explicit markdown links, backtick-wrapped paths, and missing allowlist entries such as .mmd. Your PR’s Windows absolute-path + explicit-link rewrite is complementary; please keep the shared security exclusions aligned if both land.

@techotaku39 techotaku39 reopened this Jul 23, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Findings

  • None.

Summary

  • Review mode: initial
  • No issues found with the Windows absolute path matching/rewrite changes in web/src/lib/remark-file-path-links.ts.
  • Residual risk: I could not run the web test/typecheck commands because bun is not installed in this runner.

Testing

  • Not run (automation): bun unavailable in this environment.

HAPI Bot

pull Bot pushed a commit to chancat87/hapi that referenced this pull request Jul 24, 2026
* fix(web): autolink markdown links, inline code, and .mmd file paths in chat

Chat autolinking previously only worked for bare file paths in plain text.
Fancier markdown forms silently produced dead links:

- COMMON_FILE_EXTENSIONS omitted common agent-cited types (mmd, puml, rst,
  csv, ini, etc.), so bare diagram.mmd never linked.
- inlineCode nodes were never processed, so `path/to/file.md` never linked.
- explicit [label](relative/file.md) links kept a raw relative URL that the
  SPA router treated as a dead route under /sessions/.

Changes:
- Expand COMMON_FILE_EXTENSIONS with justified doc/diagram/config/lang exts;
  deliberately exclude TLD-lookalikes (org/com/io) to avoid domain false
  positives.
- Autolink inlineCode nodes whose ENTIRE value is a single path pattern match
  (whitespace-free, allowlisted ext), wrapping an inlineCode child to keep
  monospace. Real code snippets are left untouched.
- Rewrite explicit markdown links whose target is a repo-relative allowlisted
  file path into hapi-file: hrefs (aligns with tiann#1113). Preserves label.

Security invariants preserved: shouldLinkPath still rejects abs / ~/ / ../ /
Windows-drive / scheme:// paths; scheme-bearing link urls are left for the
deny-scheme layer; deny-scheme handling untouched.

Refs tiann#1120

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(web): don't rewrite explicit links in standalone markdown preview

Codex review (tiann#1142): rewriteFileLinkNode ran on the standalone file-preview
surface too, but that surface has no HappyChatContext so the shared `A` anchor
collapses hapi-file: links to plain text (returns props.children when !chat).
That turned an explicit [label](file.md) link in a README preview from an
anchor into plain text.

Gate explicit-link rewriting behind a rewriteExplicitLinks option (default on
for chat) and disable it for the standalone renderer via new
MARKDOWN_PLUGINS_STANDALONE(_WITH_BREAKS) arrays. Bare-path and inlineCode
autolinks are kept — they were already inert on the standalone surface, so no
behavior change there.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Debian <heavygee@oos-linux.in.lockhouse>
Co-authored-by: Cursor <cursoragent@cursor.com>
@techotaku39
techotaku39 force-pushed the fix/web-windows-absolute-file-links branch from fc29ae2 to 117cfd2 Compare July 24, 2026 13:39
@techotaku39

Copy link
Copy Markdown
Contributor Author

Rebased onto current main after #1142 and resolved the shared file-path plugin conflicts. Windows absolute paths now use the same bare-text, inline-code, and explicit-link flows while preserving the relative-path exclusions added there; workspace containment remains enforced by the CLI file RPC. Updated coverage passes locally (37 targeted tests, 165 Web test files / 1394 tests, and root typecheck).

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Findings

  • None.

Summary

  • Review mode: follow-up after new commits
  • No issues found in the latest web/src/lib/remark-file-path-links.ts and web/src/lib/remark-file-path-links.test.ts changes.
  • Prior HAPI Bot review at fc29ae202a3fd372bf815ff7629e914921055b90 also had no findings; this pass reviewed the full latest PR diff, not only the incremental context.
  • Residual risk: Windows path handling depends on the existing CLI file RPC path validation on the session host.

Testing

  • Not run (automation): bun unavailable in this environment.

HAPI Bot

@techotaku39

Copy link
Copy Markdown
Contributor Author

Hi @heavygee, a quick follow-up now that #1142 has landed: I’ve rebased this PR onto the latest main and aligned the Windows absolute-path handling with the new bare-text, inline-code, and explicit-link flows.

The PR is conflict-free and all checks are green. When you have a chance, could you please review it for merging? I’m happy to address any remaining concerns. Thanks!

swear01 added a commit to swear01/hapi that referenced this pull request Jul 28, 2026
fix(web): open Windows absolute file paths in session viewer
swear01 added a commit to swear01/hapi that referenced this pull request Jul 29, 2026
fix(web): open Windows absolute file paths in session viewer

@heavygee heavygee left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM - thumbs up.

Reviewed the post-#1142 rebase of the Windows absolute-path handling in remark-file-path-links:

  • Drive-letter recognition (C:\... / C:/...) is correctly gated on the existing extension allowlist.
  • Explicit-link rewrite correctly special-cases Windows drive letters so the residual-colon deny still catches mailto:, foo:bar.md, etc.
  • Bare-text / inlineCode / explicit-link coverage matches the #1142 shape; POSIX abs / ~/ / ../ exclusions stay intact.
  • Containment still bottoms out in CLI validatePath() on the session host (the right place for this); web only rewrites to hapi-file: and routes through the session file viewer.

CI is green (test, pr-review).

Currently by convention, only @tiann merges - please wait for them to land this. Happy to re-check if anything else comes up.

@heavygee heavygee added low-impact Focused / low-blast-radius change; estate lane B promote candidate (PR merge policy) and removed low-impact Focused / low-blast-radius change; estate lane B promote candidate (PR merge policy) labels Jul 31, 2026
@heavygee
heavygee merged commit f985d56 into tiann:main Jul 31, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

low-impact Focused / low-blast-radius change; estate lane B promote candidate (PR merge policy)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants