From bd45d705bf85f1b3a2b9e956580e509167211945 Mon Sep 17 00:00:00 2001 From: Trevin Chow Date: Thu, 23 Jul 2026 23:26:39 -0700 Subject: [PATCH] fix(tab-bar): open absolute local paths from worktree tab create entry (#10222) * fix(tab-bar): open absolute local paths from worktree tab create entry Local worktrees can paste absolute file paths into tab create; remote and SSH workspaces stay blocked. Harden classifier ordering, ownership gating, and render-time fail-closed behavior from review. * fix(tab-bar): restore typecheck after worktree path refactor Add the missing editor file-operation import, finish the global file drop relative-path helper migration, and align the runtime env test mock. * fix(tab-bar): fail closed for absolute local paths --------- Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com> --- .../TabBarCreateEntry.keyboard.test.tsx | 4 +- .../components/tab-bar/TabBarCreateEntry.tsx | 26 +- .../tab-bar/TabBarCreateEntryRow.tsx | 7 +- .../tab-bar/tab-create-entry-absolute-file.ts | 54 +++ .../tab-bar/tab-create-entry-action.test.ts | 146 ++++++- .../tab-bar/tab-create-entry-action.ts | 68 ++- .../tab-create-entry-classifier.test.ts | 86 ++++ .../tab-bar/tab-create-entry-classifier.ts | 86 +++- .../tab-create-entry-local-path.test.ts | 394 ++++++++++++++++++ .../tab-bar/tab-create-entry-local-path.ts | 123 ++++++ .../tab-create-entry-path-validation.ts | 52 ++- src/renderer/src/i18n/locales/en.json | 3 +- src/renderer/src/i18n/locales/es.json | 3 +- src/renderer/src/i18n/locales/ja.json | 3 +- src/renderer/src/i18n/locales/ko.json | 3 +- src/renderer/src/i18n/locales/zh.json | 3 +- 16 files changed, 1024 insertions(+), 37 deletions(-) create mode 100644 src/renderer/src/components/tab-bar/tab-create-entry-absolute-file.ts create mode 100644 src/renderer/src/components/tab-bar/tab-create-entry-local-path.test.ts create mode 100644 src/renderer/src/components/tab-bar/tab-create-entry-local-path.ts diff --git a/src/renderer/src/components/tab-bar/TabBarCreateEntry.keyboard.test.tsx b/src/renderer/src/components/tab-bar/TabBarCreateEntry.keyboard.test.tsx index 437e2c2b1..23dd2a595 100644 --- a/src/renderer/src/components/tab-bar/TabBarCreateEntry.keyboard.test.tsx +++ b/src/renderer/src/components/tab-bar/TabBarCreateEntry.keyboard.test.tsx @@ -10,7 +10,9 @@ import type { TabAgentLaunchOption } from './tab-agent-launch-options' // keyboard behavior under test only needs a controllable option list. const entryOptionsMock = vi.hoisted(() => ({ options: [] as TabEntryOption[] })) vi.mock('./tab-create-entry-action', () => ({ - getTabEntryOptions: () => entryOptionsMock.options + getTabEntryOptions: () => entryOptionsMock.options, + createTabEntryAllowAbsolutePathsSelector: () => () => true, + isTabEntryAbsolutePathLike: () => false })) vi.mock('../quick-open-file-list', () => ({ useRuntimeFileListForWorktree: () => ({ files: [], loading: false, loadError: null }) diff --git a/src/renderer/src/components/tab-bar/TabBarCreateEntry.tsx b/src/renderer/src/components/tab-bar/TabBarCreateEntry.tsx index dd2772f36..8c9941cba 100644 --- a/src/renderer/src/components/tab-bar/TabBarCreateEntry.tsx +++ b/src/renderer/src/components/tab-bar/TabBarCreateEntry.tsx @@ -1,7 +1,12 @@ import React, { useEffect, useMemo, useRef, useState } from 'react' import { Input } from '@/components/ui/input' import { useRuntimeFileListForWorktree } from '../quick-open-file-list' -import { getTabEntryOptions, type TabCreateEntryArgs } from './tab-create-entry-action' +import { + createTabEntryAllowAbsolutePathsSelector, + getTabEntryOptions, + isTabEntryAbsolutePathLike, + type TabCreateEntryArgs +} from './tab-create-entry-action' import { findMatchingTabAgentLaunchOptions, type TabAgentLaunchOption @@ -23,6 +28,8 @@ import { } from './TabBarCreateEntryRow' import type { TuiAgent } from '../../../../shared/types' import { translate } from '@/i18n/i18n' +import { getRendererAppPlatform } from '@/lib/renderer-app-platform' +import { useAppStore } from '@/store' const EMPTY_AGENT_OPTIONS: readonly TabAgentLaunchOption[] = [] const EMPTY_MENU_OPTIONS: readonly TabCreateMenuOption[] = [] @@ -62,6 +69,16 @@ export default function TabBarCreateEntry({ const [lastMenuOpen, setLastMenuOpen] = useState(menuOpen) const inputRef = useRef(null) const fileList = useRuntimeFileListForWorktree({ enabled: menuOpen, worktreeId }) + const shouldResolveAbsolutePaths = menuOpen && isTabEntryAbsolutePathLike(query.trim()) + const allowAbsolutePathsSelector = useMemo( + () => + createTabEntryAllowAbsolutePathsSelector(worktreeId, { + skip: !shouldResolveAbsolutePaths + }), + [shouldResolveAbsolutePaths, worktreeId] + ) + const allowAbsolutePaths = useAppStore(allowAbsolutePathsSelector) + const localPlatform = getRendererAppPlatform() === 'win32' ? 'windows' : 'posix' // Why: once ArrowDown moves focus into the static menu list, ArrowUp on the // first item should return to the search box so the keyboard trip isn't @@ -105,13 +122,16 @@ export default function TabBarCreateEntry({ [menuOptions, query] ) const options = useMemo(() => { - const entryOptions = getTabEntryOptions(query, fileList) + const entryOptions = getTabEntryOptions(query, fileList, 4, { + allowAbsolutePaths, + localPlatform + }) if (matchingMenuOptions.length === 0) { return entryOptions } // Why: a matched create-menu action should win over a generic new-file fallback. return entryOptions.filter((option) => option.classification.kind !== 'new-file') - }, [fileList, matchingMenuOptions.length, query]) + }, [allowAbsolutePaths, fileList, localPlatform, matchingMenuOptions.length, query]) const matchingAgentOptions = useMemo( () => findMatchingTabAgentLaunchOptions(query, agentOptions), [agentOptions, query] diff --git a/src/renderer/src/components/tab-bar/TabBarCreateEntryRow.tsx b/src/renderer/src/components/tab-bar/TabBarCreateEntryRow.tsx index 01513864e..7aa57731c 100644 --- a/src/renderer/src/components/tab-bar/TabBarCreateEntryRow.tsx +++ b/src/renderer/src/components/tab-bar/TabBarCreateEntryRow.tsx @@ -114,9 +114,12 @@ function getActionPresentation(option: ActiveOption): { showDetail: true } } - if (classification.kind === 'existing-file') { + if (classification.kind === 'existing-file' || classification.kind === 'absolute-file') { return { - detail: classification.relativePath, + detail: + classification.kind === 'absolute-file' + ? classification.filePath + : classification.relativePath, icon: