Repository navigation
fix(mobile): make native-chat file links and path citations tappable (STA-3331) - #12364
Conversation
…(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
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe 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)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
|
Review and QA complete.
Electron evidence: Mobile native-chat evidence: |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
mobile/src/components/MobileMarkdown.file-links.test.ts (1)
1-3: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAvoid new
react-test-renderercoverage.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
📒 Files selected for processing (21)
mobile/app/h/[hostId]/session/[worktreeId].tsxmobile/src/components/MobileMarkdown.file-links.test.tsmobile/src/components/MobileMarkdown.tsxmobile/src/components/markdown-file-path-detection.test.tsmobile/src/components/markdown-file-path-detection.tsmobile/src/components/markdown-href-routing.test.tsmobile/src/components/markdown-href-routing.tsmobile/src/components/markdown-inline-token-rules.test.tsmobile/src/components/markdown-inline-token-rules.tsmobile/src/session/MobileNativeChatOverlay.tsxmobile/src/session/MobileNativeChatView.tsxmobile/src/session/mobile-file-tap-open.test.tsmobile/src/session/mobile-file-tap-open.tsmobile/src/session/mobile-native-chat-open-file.test.tsmobile/src/session/mobile-native-chat-open-file.tsmobile/src/session/use-mobile-file-tap-handlers.test.tsmobile/src/session/use-mobile-file-tap-handlers.tsmobile/src/session/use-mobile-native-chat-controller.tssrc/renderer/src/components/native-chat/native-chat-file-link.tssrc/shared/native-chat-href-routing.test.tssrc/shared/native-chat-href-routing.ts
| client, | ||
| hostId, | ||
| worktreeId, | ||
| worktreeName: routeWorktreeName, |
There was a problem hiding this comment.
🎯 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.
| worktreeName: routeWorktreeName, | |
| worktreeName, |
|
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:\n |
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.
…d emphasis" This reverts commit 308bfaf.
Final review and Electron QA
|
|
Fresh iOS simulator follow-up on final head 93a6aa2:
|
…(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








Summary
Fixes STA-3331: file references in mobile native chat messages were effectively dead — POSIX absolute paths never linkified,
path:linecitations 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):
/Users/me/wt/src/app.tsxin 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./root.ts,C:\root.ts,./root.ts, and../root.tswithout weakening URL/domain guards.path:line(:col)citations work end to end.src/foo.ts:42linkifies in prose and inline code, and the line/column carry through to the mobile file-preview route (matching terminal taps and desktop).[label](src/foo.ts),[plan](./docs/plan.md#L7), andfile:///…links now route to the file opener (desktop parity — hrefs are the entire desktop file-link contract).http(s)/mailtostill open the system handler; other schemes (javascript:,data:, …) stay dropped. Windows drive paths are exempt from the scheme filter.<worktree>/mobileno longer turnsmobile/src/x.tsintomobile/mobile/src/x.ts→ ENOENT).files.openplus session-tab activation with retries otherwise — and failures show a "Couldn't open …" toast instead of a silent no-op._no longer shredssrc/foo_bar.tsinto italics (CommonMark-correct), bold/italic/strike spans are scanned for paths, autolinks no longer swallow trailing sentence punctuation, and the chat list setskeyboardShouldPersistTaps="handled"so link taps land while the composer keyboard is up.Structurally, href classification now lives in
src/shared/native-chat-href-routing.tsand 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 tomobile-file-tap-open.tsand gains an optionalonOpenFailed; a new identity-stableuseMobileFileTapHandlershook 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.tsrendered as file links. Tapping the missing/root.tsfixture 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:

Mobile link rendering:

Mobile tap behavior:

Testing
pnpm lint(frommobile/— oxlint, 0 errors; React Doctor pre-commit config also clean)pnpm typecheck(frommobile/— tsc, 0 errors)pnpm typecheck(repo root — node/CLI/web TypeScript projects, 0 errors)pnpm test(frommobile/— 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./root.ts,C:\root.ts,./root.ts,../root.ts),:line/:line:col(relative, absolute, Windows drive), protocol-relative URL guard, non-line colon tails, andsplitFilePathLineSuffixunit cases#Lfragments, percent-decoding,file:URIs (POSIX + Windows), scheme dropsonOpenFile/Linking.openURLfor every href class, snake_case survival, bold-span detection, autolink punctuation, plain-text fallback withoutonOpenFileterminal/cwdin the RPC), line-citation → preview route,onOpenFailedon resolve miss / rejection / failedfiles.open, and no failure callback when the user merely left the source tabAI 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
:linesuffixes (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 sharedfileUriToFilesystemPath(drive + UNC forms covered), the scheme filter exemptsC:\…via the sharedisWindowsAbsolutePathLike, and no keyboard shortcuts, labels, or shell behavior are touched. SSH/remote: resolution still goes throughfiles.resolveTerminalPathon the host (provider-aware), the local-file://browser shortcut for HTML remains gated onprovider === '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
https?/mailtoto the system handler,file:/scheme-less to the file opener;javascript:,data:, and other schemes are dropped before reachingLinking.openURL(previously enforced by a narrower filter; now covered by tests).files.resolveTerminalPath, which enforcesisSafeMobileRelativePathand 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).Notes
Textpress path should be investigated separately.Closes STA-3331.