Skip to content

fix(mobile): make native-chat file links and path citations tappable (STA-3331) - #12364

Merged
brennanb2025 merged 9 commits into
mainfrom
brennanb2025/sta-3331-chat-file-links
Aug 4, 2026
Merged

brennanb2025 merged 9 commits into
mainfrom
brennanb2025/sta-3331-chat-file-links

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes STA-3331: file references in mobile native chat messages were effectively dead — POSIX absolute paths never linkified, path:line citations rendered inert, file:// and relative markdown hrefs were silently dropped, relative paths resolved against the wrong base, and even successful opens gave zero feedback on the phone.

What changes for the user (mobile native chat):

  • Absolute paths linkify. /Users/me/wt/src/app.tsx in prose is now tappable. The detection regex gains a leading-/ alternative, and the URL guard now discards a match only when the character before the matched slash proves a URL (://, //, domain tail), instead of discarding every absolute path.
  • Paths directly under roots linkify too. Regression coverage includes /root.ts, C:\root.ts, ./root.ts, and ../root.ts without weakening URL/domain guards.
  • path:line(:col) citations work end to end. src/foo.ts:42 linkifies in prose and inline code, and the line/column carry through to the mobile file-preview route (matching terminal taps and desktop).
  • Markdown hrefs open files. [label](src/foo.ts), [plan](./docs/plan.md#L7), and file:///… links now route to the file opener (desktop parity — hrefs are the entire desktop file-link contract). http(s)/mailto still open the system handler; other schemes (javascript:, data:, …) stay dropped. Windows drive paths are exempt from the scheme filter.
  • Chat paths resolve against the worktree root instead of the backing terminal's live cwd (an agent launched from <worktree>/mobile no longer turns mobile/src/x.ts into mobile/mobile/src/x.ts → ENOENT).
  • Taps feel real. Chat file taps now reuse the terminal tap-to-open flow: selection haptic, mobile file-preview route for line refs, files.open plus session-tab activation with retries otherwise — and failures show a "Couldn't open …" toast instead of a silent no-op.
  • Rendering fixes around paths: intraword _ no longer shreds src/foo_bar.ts into italics (CommonMark-correct), bold/italic/strike spans are scanned for paths, autolinks no longer swallow trailing sentence punctuation, and the chat list sets keyboardShouldPersistTaps="handled" so link taps land while the composer keyboard is up.

Structurally, href classification now lives in src/shared/native-chat-href-routing.ts and is consumed by both desktop native chat and the mobile adapter, so the working desktop contract is reused instead of duplicated. The terminal tap-to-open flow (mobile-terminal-file-tap-open.ts) is renamed to mobile-file-tap-open.ts and gains an optional onOpenFailed; a new identity-stable useMobileFileTapHandlers hook owns both the terminal and chat handlers (shared activation seq so a newer tap on either surface supersedes an in-flight one), shrinking the session route file by ~20 effective lines. The chat controller no longer owns the open-file concern.

Screenshots

Electron CDP and iOS emulator QA passed. The desktop PR worktree loaded without console errors; on iOS, /root.ts, C:\root.ts, ./root.ts, and ../root.ts rendered as file links. Tapping the missing /root.ts fixture exercised the open flow and showed the expected “Couldn't open /root.ts” toast. See the QA follow-up for full notes.

Electron regression context:
sta-3331-electron.png

Mobile link rendering:
sta-3331-mobile-file-links.png

Mobile tap behavior:
sta-3331-mobile-file-link-tap.png

Testing

  • pnpm lint (from mobile/ — oxlint, 0 errors; React Doctor pre-commit config also clean)
  • pnpm typecheck (from mobile/ — tsc, 0 errors)
  • pnpm typecheck (repo root — node/CLI/web TypeScript projects, 0 errors)
  • pnpm test (from mobile/ — 407 files: 3,056 passed, 3 skipped)
  • pnpm build — not run locally; the PR includes a shared href-routing module consumed by mobile and desktop. Root/mobile typechecks, focused shared tests, Electron CDP QA, and iOS emulator QA passed; packaging remains covered by PR CI.
  • Added or updated high-quality tests that would catch regressions:
    • detection: absolute POSIX and direct-root paths (/root.ts, C:\root.ts, ./root.ts, ../root.ts), :line/:line:col (relative, absolute, Windows drive), protocol-relative URL guard, non-line colon tails, and splitFilePathLineSuffix unit cases
    • href routing: web/mailto, relative + #L fragments, percent-decoding, file: URIs (POSIX + Windows), scheme drops
    • rendering (react-test-renderer): press → onOpenFile/Linking.openURL for every href class, snake_case survival, bold-span detection, autolink punctuation, plain-text fallback without onOpenFile
    • open flow: worktree-root resolution (no terminal/cwd in the RPC), line-citation → preview route, onOpenFailed on resolve miss / rejection / failed files.open, and no failure callback when the user merely left the source tab
    • hook: handler identity stability across rerenders, non-active-handle guard, chat-tap contract + toast

AI Review Report

Reviewed for: regex correctness and false positives (URL/domain/email/version guards all re-verified against the existing test corpus; protocol-relative //cdn… added), regex backtracking (new alternatives add no nesting; the existing 2000-char detection cap still bounds worst case), press-handler identity churn (the new hook reads latest options via refs at dispatch time and its callbacks have empty dep arrays — a test pins identity stability across rerenders, per the STA-3291 lesson), activation-gate semantics (navigating away mid-resolve is not reported as a failure), and behavior parity through the shared desktop/mobile href contract (native-chat-href-routing.ts).

Cross-platform explicitly checked for macOS, Linux, and Windows: Windows drive colons are never mistaken for :line suffixes (only a trailing all-digit suffix parses), UNC and drive-relative detection is preserved by the ordered regex alternation with new tests, file: URI conversion reuses the shared fileUriToFilesystemPath (drive + UNC forms covered), the scheme filter exempts C:\… via the shared isWindowsAbsolutePathLike, and no keyboard shortcuts, labels, or shell behavior are touched. SSH/remote: resolution still goes through files.resolveTerminalPath on the host (provider-aware), the local-file:// browser shortcut for HTML remains gated on provider === 'local', and resolve/open RPCs now carry the same 10s/15s timeouts as terminal taps instead of hanging a dead tap for the transport default. Folder workspaces are unaffected (resolution keys off the worktree selector, not git state).

Flagged and consciously kept: __init__-style dunder segments still render bold — that matches CommonMark and the desktop renderer; only intraword underscores are treated as literal.

Security Audit

  • Input handling: detection/tokenization regexes run over untrusted agent output; the pre-existing length cap bounds backtracking and the new alternatives are non-nesting. Percent-decoding failures fall back to the raw string.
  • Scheme safety: href routing is an explicit allowlist — https?/mailto to the system handler, file:/scheme-less to the file opener; javascript:, data:, and other schemes are dropped before reaching Linking.openURL (previously enforced by a narrower filter; now covered by tests).
  • Path handling / authorization: no client-side trust added. All opens still resolve through the host's files.resolveTerminalPath, which enforces isSafeMobileRelativePath and worktree containment; chat taps now omit the terminal handle, which narrows the out-of-worktree artifact-grant surface (those grants require terminal provenance and now simply surface a toast).
  • No changes to auth, secrets, dependencies, or IPC surfaces; no new RPC methods.

Notes

  • iOS emulator QA completed for direct-root link rendering and tap-to-open/toast behavior. The separate inline-code no-RPC report remains unreproduced; if it recurs on a physical device, the native nested-Text press path should be investigated separately.
  • Out-of-worktree absolute paths from transcripts now fail visibly (toast) rather than silently; opening them would need a transcript-scoped grant model, noted on the ticket.
  • Expanded tool rows still show raw JSON as the tappable label (cosmetic, out of scope here, on the ticket).
  • Fenced code blocks and tool-result bodies intentionally remain undetected surfaces (same as before); only prose, inline code, and styled spans linkify.

Closes STA-3331.

…(STA-3331)

- Linkify POSIX absolute paths in chat prose (leading-/ regex alternative;
  URL guard now keys off the char before the matched slash)
- Parse agent-style path:line(:col) citations in prose, code spans, and the
  open flow; line/column ride into the mobile file preview route
- Route non-web markdown hrefs (file: URIs, relative/absolute paths) to the
  file opener instead of silently dropping them; unknown schemes stay dead
- Resolve chat paths against the worktree root, not the terminal's live cwd
- Reuse the terminal tap-to-open flow for chat taps (haptic, preview route,
  tab activation with retries) via a shared identity-stable hook, and toast
  on misses instead of silent no-ops
- Keep snake_case paths whole (intraword underscores are literal text),
  scan bold/italic/strike spans for paths, split trailing punctuation off
  autolinks, and let taps land while the composer keyboard is up
@coderabbitai

coderabbitai Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The change centralizes Markdown and native-chat href routing. Markdown supports additional file-path formats, citations, formatted text, and file-link callbacks. Mobile terminal and native-chat file taps share opening, navigation, activation, and failure handling. Native chat receives its file-opening callback from the session screen. Tests cover routing, detection, rendering, tap handling, failures, and stale activation.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: making native-chat file links and path citations tappable on mobile.
Description check ✅ Passed The description covers all template sections with detailed scope, testing, AI review, security audit, and platform notes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review and QA complete.

  • Same-model / same-reasoning subagent review fixed the meaningful findings in ecd921b173, then re-audited the updated PR and returned CLEAN.
  • Fixes cover render-time React ref mutation, false-success handling for unsupported file opens, stale failure toasts, and quadratic URL punctuation trimming.
  • The 16K-character punctuation case improved from about 1,317 ms to 0.125 ms.
  • Local verification passed: 81 focused tests, mobile typecheck, changed-file lint/format, and React Doctor with 0 issues.
  • Full PR CI is green across Mobile Checks, static analysis, typecheck, Git compatibility, Node 24/26 test shards, and macOS/Windows packaging.
  • Electron paired-device UI validated through the PR worktree Electron session.
  • iOS native chat rendered the full mobile/src/components/MobileMarkdown.tsx:1 citation as a tappable file link. Tapping it created the MobileMarkdown.tsx file tab in the target worktree.

Electron evidence:

sta-3331-electron-mobile-pairing.png

Mobile native-chat evidence:

sta-3331-mobile-chat-full-path.png

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
mobile/src/components/MobileMarkdown.file-links.test.ts (1)

1-3: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid new react-test-renderer coverage.

React 19 deprecates react-test-renderer; use React Native Testing Library coverage for this new test instead.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 237065b2-30a9-405d-b393-b38b71350cef

📥 Commits

Reviewing files that changed from the base of the PR and between 13f033f and 7c1af0b.

📒 Files selected for processing (21)
  • mobile/app/h/[hostId]/session/[worktreeId].tsx
  • mobile/src/components/MobileMarkdown.file-links.test.ts
  • mobile/src/components/MobileMarkdown.tsx
  • mobile/src/components/markdown-file-path-detection.test.ts
  • mobile/src/components/markdown-file-path-detection.ts
  • mobile/src/components/markdown-href-routing.test.ts
  • mobile/src/components/markdown-href-routing.ts
  • mobile/src/components/markdown-inline-token-rules.test.ts
  • mobile/src/components/markdown-inline-token-rules.ts
  • mobile/src/session/MobileNativeChatOverlay.tsx
  • mobile/src/session/MobileNativeChatView.tsx
  • mobile/src/session/mobile-file-tap-open.test.ts
  • mobile/src/session/mobile-file-tap-open.ts
  • mobile/src/session/mobile-native-chat-open-file.test.ts
  • mobile/src/session/mobile-native-chat-open-file.ts
  • mobile/src/session/use-mobile-file-tap-handlers.test.ts
  • mobile/src/session/use-mobile-file-tap-handlers.ts
  • mobile/src/session/use-mobile-native-chat-controller.ts
  • src/renderer/src/components/native-chat/native-chat-file-link.ts
  • src/shared/native-chat-href-routing.test.ts
  • src/shared/native-chat-href-routing.ts

client,
hostId,
worktreeId,
worktreeName: routeWorktreeName,

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Pass the live worktreeName, not the route parameter.

worktreeName (line 856) resolves the live name through useLiveWorktreeName and backs the header title and panel routes. routeWorktreeName is the raw route parameter, which is optional and goes stale after a rename. The hook forwards this value into createMobileFilePreviewHref as the preview label, so a file opened from a tap can show a missing or stale workspace name while the rest of the screen shows the live one.

🔧 Proposed fix
-    worktreeName: routeWorktreeName,
+    worktreeName,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
worktreeName: routeWorktreeName,
worktreeName,

@brennanb2025

Copy link
Copy Markdown
Contributor Author

QA follow-up\n\n- Same-model review (gpt-5.6-sol, xhigh) found one meaningful edge case: files directly under a path root were not linkified. Fixed in f45a8cb with focused regression coverage.\n- Validation passed: 34 focused tests, focused oxlint, mobile typecheck, and the full mobile suite (2,935 passed, 3 skipped).\n- Electron CDP QA: the PR worktree loaded in the desktop app with no console errors.\n- iOS emulator QA: the branch Metro bundle loaded without a redbox; /root.ts, C:\root.ts, ./root.ts, and ../root.ts all render as file links. Tapping /root.ts invoked the file-open flow and produced the expected “Couldn't open /root.ts” toast because the QA fixture path does not exist.\n\nElectron regression context:\nsta-3331-electron.png\n\nMobile link rendering:\nsta-3331-mobile-file-links.png\n\nMobile tap behavior:\nsta-3331-mobile-file-link-tap.png

Review follow-ups on the chat file-link work:

- A rejected intraword `_` token left the scan index past its closing
  underscore, so every inline token between two snake_case words was
  swallowed and rendered as literal source — including markdown links,
  which became untappable. Rescan from just past the opening delimiter.
- Treat a path separator as an intraword flank so `src/__init__.py` and
  `a/__tests__/x.ts` stay whole; previously they rendered as bold plus a
  remnant that the new absolute-root pattern turned into a tap on `/x.ts`.
- Bound the `:line(:col)` tail so `src/app.ts:1e3` and `:80%` no longer
  parse a line number, while a cited range still opens its first line.
- Route chat tap failures through the composer banner (toast fallback):
  chat taps happen with the keyboard up, which covers the toast.
- Drop the tap-handler mirror's dep list; the call site rebuilds its
  accessors every render, so it could never skip on a route that
  rerenders per keystroke.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Final review and Electron QA

  • Same-model, same-reasoning senior review found four meaningful STA-3331 regressions and fixed them in 93a6aa21d3: markdown between snake_case paths stays tappable, dunder path segments stay one file link, numeric-looking non-line suffixes no longer partially parse, and chat file-open failures use the visible composer banner while the keyboard is up.
  • The same reviewer then re-reviewed the complete pushed head for correctness, security, performance, activation races, Windows/UNC, SSH, and folder workspaces and returned CLEAN.
  • Validation passed: full mobile suite (3,060 passed, 3 skipped), shared/desktop routing tests (14 passed), mobile typecheck/lint/format/React Doctor, and all PR CI checks including macOS and Windows packaging.
  • Fresh Electron CDP QA on 93a6aa21d3: the PR worktree opened successfully, the editor reported No uncommitted changes, and the renderer console had no errors. The only console entry was an unrelated xterm scheduling warning.
  • The available iOS dev client remained attached to another worktree Metro bundle, so the earlier valid iOS screenshots on this PR remain the mobile evidence rather than claiming a fresh bundle pass.

sta-3331-electron-final.png

@brennanb2025

brennanb2025 commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Fresh iOS simulator follow-up on final head 93a6aa2:

  • iOS 26.5 on PR 12502 QA; the branch Metro bundle completed at 4,676 modules with no redbox or runtime exception.
  • Re-paired through the real desktop flow and opened PR fix(mobile): make native-chat file links and path citations tappable (STA-3331) #12364 in live native chat.
  • Confirmed snake_case paths remain separate from the embedded Markdown link, the Markdown link is tappable and opened Safari, a/tests/x.ts stays one file link, and the :1e3 suffix remains outside the file link.
  • Tapping the nonexistent absolute path with the composer focused showed the visible missing-file banner.

Native-chat rendering:
sta3331-mobile-file-links-rendered.png

Missing-file banner:
sta3331-mobile-missing-file-banner-fast.png

@brennanb2025
brennanb2025 merged commit 9ee3595 into main Aug 4, 2026
43 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…(STA-3331) (stablyai#12364)

* fix(mobile): make native-chat file links and path citations tappable (STA-3331)

- Linkify POSIX absolute paths in chat prose (leading-/ regex alternative;
  URL guard now keys off the char before the matched slash)
- Parse agent-style path:line(:col) citations in prose, code spans, and the
  open flow; line/column ride into the mobile file preview route
- Route non-web markdown hrefs (file: URIs, relative/absolute paths) to the
  file opener instead of silently dropping them; unknown schemes stay dead
- Resolve chat paths against the worktree root, not the terminal's live cwd
- Reuse the terminal tap-to-open flow for chat taps (haptic, preview route,
  tab activation with retries) via a shared identity-stable hook, and toast
  on misses instead of silent no-ops
- Keep snake_case paths whole (intraword underscores are literal text),
  scan bold/italic/strike spans for paths, split trailing punctuation off
  autolinks, and let taps land while the composer keyboard is up

* fix(mobile): harden chat file tap handling

* refactor(chat): share native chat href routing

* fix(mobile): detect files directly under path roots

* fix(mobile): keep inline tokens and dunder paths intact around emphasis

Review follow-ups on the chat file-link work:

- A rejected intraword `_` token left the scan index past its closing
  underscore, so every inline token between two snake_case words was
  swallowed and rendered as literal source — including markdown links,
  which became untappable. Rescan from just past the opening delimiter.
- Treat a path separator as an intraword flank so `src/__init__.py` and
  `a/__tests__/x.ts` stay whole; previously they rendered as bold plus a
  remnant that the new absolute-root pattern turned into a tap on `/x.ts`.
- Bound the `:line(:col)` tail so `src/app.ts:1e3` and `:80%` no longer
  parse a line number, while a cited range still opens its first line.
- Route chat tap failures through the composer banner (toast fallback):
  chat taps happen with the keyboard up, which covers the toast.
- Drop the tap-handler mirror's dep list; the call site rebuilds its
  accessors every render, so it could never skip on a route that
  rerenders per keystroke.

* Revert "fix(mobile): keep inline tokens and dunder paths intact around emphasis"

This reverts commit 308bfaf.

* fix(mobile): preserve chat file-link parsing and feedback
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