@devries-cameron20 / t3code-1 / commits / 52d755f91c
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(clients): pasting a path copied from Finder or Explorer adds that folder (#28460)

Kim Khoi Lam committed Nov 1, 2026 at 13:52 UTC 52d755f91cff5cb9b54eca46e05b94ecefa92f6f
12 files changed +152 -15
apps/mobile/src/features/projects/AddProjectScreen.tsx
+2 -1
@@ -47,6 +47,7 @@ import {
47 inferProjectTitleFromPath,
48 isWindowsPlatform,
49 } from "@t3tools/client-runtime/state/projects";
50 +import { resolvePastedPath } from "@t3tools/shared/path";
51 import {
52 AuthOrchestrationOperateScope,
53 AuthSourceControlWriteScope,
@@ -279,7 +280,7 @@ function ProjectPathInput(props: {
280 <TextInput
281 className="h-12 min-h-12 rounded-[24px] px-4 py-0 text-base leading-snug"
282 value={props.value}
282 - onChangeText={props.onChangeText}
283 + onChangeText={(text) => props.onChangeText(resolvePastedPath(props.value, text))}
284 autoCapitalize="none"
285 autoCorrect={false}
286 placeholder="~/projects/my-app"
apps/mobile/src/features/settings/SettingsScheduledTasksRouteScreen.tsx
+7 -1
@@ -25,6 +25,7 @@ import {
25 squashAtomCommandFailure,
26 type AtomCommandResult,
27 } from "@t3tools/client-runtime/state/runtime";
28 +import { resolvePastedPath } from "@t3tools/shared/path";
29 import {
30 DEFAULT_WEBHOOK_PROMPT,
31 emptyWebhookFilterDraft,
@@ -982,7 +983,12 @@ function TaskForm({
983 disabled={saving}
984 value={draft.checkoutPath}
985 borderTop
985 - onChange={(checkoutPath) => setDraft({ ...draft, checkoutPath })}
986 + onChange={(checkoutPath) =>
987 + setDraft({
988 + ...draft,
989 + checkoutPath: resolvePastedPath(draft.checkoutPath, checkoutPath),
990 + })
991 + }
992 />
993 ) : null}
994 </SettingsSection>
apps/web/src/components/AddProjectToMachineDialog.tsx
+4 -1
@@ -5,6 +5,7 @@ import {
5 getCloneDestinationPath,
6 getCloneDirectoryName,
7 } from "@t3tools/client-runtime/operations/projects";
8 +import { resolvePastedPath } from "@t3tools/shared/path";
9 import {
10 type EnvironmentId,
11 type ProjectIgnoredFile,
@@ -316,7 +317,9 @@ function AddProjectToMachineDialog({ request }: { request: AddProjectToMachineRe
317 <Input
318 id={`${id}-path`}
319 value={destinationPath}
319 - onChange={(event) => setPathOverride(event.target.value)}
320 + onChange={(event) =>
321 + setPathOverride(resolvePastedPath(destinationPath, event.target.value))
322 + }
323 spellCheck={false}
324 autoComplete="off"
325 />
apps/web/src/components/CommandPalette.tsx
+5 -6
@@ -142,6 +142,7 @@ import {
142 isUnsupportedWindowsProjectPath,
143 resolveProjectPathForDispatch,
144 } from "@t3tools/client-runtime/state/projects";
145 +import { resolvePastedPath } from "@t3tools/shared/path";
146 import {
147 dispatchCommandPalette,
148 getCommandPaletteReturnFocus,
@@ -623,11 +624,9 @@ function OpenCommandPaletteDialog(props: {
624 addProjectCloneFlow.repository?.nameWithOwner ?? addProjectCloneFlow.remoteUrl,
625 )
626 : "";
626 - const browsePath = getFilesystemBrowsePath(
627 - query,
628 - browseEnvironmentPlatform,
629 - browseEnvironmentId !== null && !isRemoteProjectRepositoryStep && newProjectFlow === null,
630 - );
627 + const canBrowsePaths =
628 + browseEnvironmentId !== null && !isRemoteProjectRepositoryStep && newProjectFlow === null;
629 + const browsePath = getFilesystemBrowsePath(query, browseEnvironmentPlatform, canBrowsePaths);
630 const isBrowsing = browsePath.isBrowsing;
631 const browseDirectoryPath = browsePath.directoryPath;
632 const paletteMode = getCommandPaletteMode({ currentView, isBrowsing });
@@ -904,7 +903,7 @@ function OpenCommandPaletteDialog(props: {
903 function handleQueryChange(nextQuery: string): void {
904 browseNavigation.invalidate();
905 clearTypedHighlight();
907 - setQuery(nextQuery);
906 + setQuery(canBrowsePaths ? resolvePastedPath(query, nextQuery) : nextQuery);
907 if (nextQuery === "" && currentView?.initialQuery) {
908 popView();
909 }
apps/web/src/components/settings/ScheduledTasksSettings.tsx
+5 -1
@@ -74,6 +74,7 @@ import {
74 clampManagedRuntimeMode,
75 managedCapabilityDenial,
76 } from "@t3tools/contracts";
77 +import { resolvePastedPath } from "@t3tools/shared/path";
78 import { useManagedPolicy } from "~/state/managedPolicy";
79 import { ManagedNotice } from "../ManagedPolicy";
80 import { readEnvironmentScope } from "~/state/session";
@@ -1559,7 +1560,10 @@ function ScheduledTaskEditorForm({
1560 onChange={(event) =>
1561 setDraft((current) => ({
1562 ...current,
1562 - existingWorktreePath: event.target.value,
1563 + existingWorktreePath: resolvePastedPath(
1564 + current.existingWorktreePath,
1565 + event.target.value,
1566 + ),
1567 }))
1568 }
1569 />
apps/web/src/components/settings/SettingsPanels.tsx
+2
@@ -25,6 +25,7 @@ import {
25 } from "@t3tools/contracts/settings";
26 import { desktopUpdateChannelOf } from "@t3tools/shared/cliRelease";
27 import { createModelSelection } from "@t3tools/shared/model";
28 +import { resolvePastedPath } from "@t3tools/shared/path";
29 import * as Equal from "effect/Equal";
30 import * as Schema from "effect/Schema";
31 import { APP_VERSION, HOSTED_APP_CHANNEL, HOSTED_APP_CHANNEL_LABEL } from "../../branding";
@@ -1577,6 +1578,7 @@ export function ThreadsSettingsPanel() {
1578 className="w-full sm:w-72"
1579 value={mixedAddProjectBaseDirectory ? "" : settings.addProjectBaseDirectory}
1580 onCommit={(next) => updateSettings({ addProjectBaseDirectory: next })}
1581 + normalizeDraft={resolvePastedPath}
1582 placeholder={mixedAddProjectBaseDirectory ? "Mixed" : "~/"}
1583 spellCheck={false}
1584 aria-label="Add project base directory"
apps/web/src/components/settings/StorageSettings.tsx
+8 -1
@@ -3,6 +3,7 @@ import type {
3 StorageCleanupSettings,
4 WorktreeCleanupRules,
5 } from "@t3tools/contracts";
6 +import { resolvePastedPath } from "@t3tools/shared/path";
7 import { resolveWorktreeCleanup } from "@t3tools/shared/projectSettings";
8 import { useRef, useState } from "react";
9 import { useAtomValue } from "@effect/atom-react";
@@ -54,6 +55,7 @@ export function WorktreesDirectoryRow() {
55 const updateSettings = useUpdateScopedSettings();
56 const mixed = useScopedSettingsMixed(["worktreesDirectory"]);
57 const edited = useRef(false);
58 + const draft = useRef("");
59 if (
60 connectedEnvironments.some(
61 (environment) =>
@@ -87,8 +89,13 @@ export function WorktreesDirectoryRow() {
89 spellCheck={false}
90 placeholder={mixed ? "Mixed" : "Default"}
91 defaultValue={mixed ? "" : settings.worktreesDirectory}
90 - onChange={() => {
92 + onFocus={(event) => {
93 + draft.current = event.target.value;
94 + }}
95 + onChange={(event) => {
96 edited.current = true;
97 + draft.current = resolvePastedPath(draft.current, event.target.value);
98 + event.target.value = draft.current;
99 }}
100 onBlur={(event) => {
101 const value = event.target.value.trim();
apps/web/src/components/ui/draft-input.tsx
+3 -2
@@ -4,10 +4,11 @@ import { Input, type InputProps } from "./input";
4 export type DraftInputProps = Omit<InputProps, "value" | "onChange" | "defaultValue"> & {
5 readonly value: string;
6 readonly onCommit: (next: string) => void;
7 + readonly normalizeDraft?: (previous: string, next: string) => string;
8 };
9
10 /** Commit drafts without settings-wide rerenders or server round trips per keystroke. */
10 -export function DraftInput({ value, onCommit, ...rest }: DraftInputProps) {
11 - const bag = useCommitOnBlur(value, onCommit);
11 +export function DraftInput({ value, onCommit, normalizeDraft, ...rest }: DraftInputProps) {
12 + const bag = useCommitOnBlur(value, onCommit, normalizeDraft);
13 return <Input {...rest} {...bag} />;
14 }
apps/web/src/hooks/useCommitOnBlur.browser.test.tsx
+21
@@ -1,6 +1,8 @@
1 import { describe, expect, it } from "vite-plus/test";
2 import { userEvent } from "vite-plus/test/browser";
3
4 +import { resolvePastedPath } from "@t3tools/shared/path";
5 +
6 import { render } from "../../test/render";
7 import { DraftInput } from "../components/ui/draft-input";
8
@@ -38,4 +40,23 @@ describe("settings draft commits", () => {
40
41 expect(saved).toBe("/projects");
42 });
43 +
44 + it("normalizes each change against the draft before it", async () => {
45 + let saved = "/mnt/old/";
46 + const commit = (next: string) => {
47 + saved = next;
48 + };
49 + await using screen = await render(
50 + <DraftInput value={saved} onCommit={commit} normalizeDraft={resolvePastedPath} />,
51 + );
52 + const input = screen.getByRole("textbox");
53 + await input.fill("/mnt/old//mnt/new");
54 + await userEvent.tab();
55 + expect(saved).toBe("/mnt/new");
56 +
57 + await input.fill("");
58 + await userEvent.type(input, "/tmp/a\\ b");
59 + await userEvent.tab();
60 + expect(saved).toBe("/tmp/a\\ b");
61 + });
62 });
apps/web/src/hooks/useCommitOnBlur.ts
+7 -2
@@ -1,13 +1,18 @@
1 import { type ChangeEvent, type KeyboardEvent, useRef, useState } from "react";
2
3 -export function useCommitOnBlur(value: string, onCommit: (next: string) => void) {
3 +export function useCommitOnBlur(
4 + value: string,
5 + onCommit: (next: string) => void,
6 + normalizeDraft?: (previous: string, next: string) => string,
7 +) {
8 const [draft, setDraft] = useState<string | null>(null);
9 const valueOnFocus = useRef(value);
10
11 return {
12 value: draft ?? value,
13 onChange: (event: ChangeEvent<HTMLInputElement>) => {
10 - setDraft(event.target.value);
14 + const next = event.target.value;
15 + setDraft(normalizeDraft ? normalizeDraft(draft ?? value, next) : next);
16 },
17 onFocus: () => {
18 valueOnFocus.current = value;
packages/shared/src/path.test.ts
+59
@@ -4,6 +4,7 @@ import {
4 newProjectFolderName,
5 normalizeProjectPathForComparison,
6 normalizeProjectPathForDispatch,
7 + resolvePastedPath,
8 resolveWorkspaceFilePath,
9 } from "./path.ts";
10
@@ -37,6 +38,64 @@ describe("path helpers", () => {
38 });
39 });
40
41 +describe("resolvePastedPath", () => {
42 + it.each([
43 + ["Finder, a space", "", "'/Users/me/Monarch Money'", "/Users/me/Monarch Money"],
44 + ["Finder, an apostrophe", "", "/Users/me/Bob\\'s\\ Stuff", "/Users/me/Bob's Stuff"],
45 + ["Finder, a backslash", "", "/Users/me/a\\\\\\ b", "/Users/me/a\\ b"],
46 + [
47 + "Finder, apostrophes around a name",
48 + "",
49 + "/Users/me/\\'My\\ Folder\\'",
50 + "/Users/me/'My Folder'",
51 + ],
52 + ["Explorer, a drive", "", '"C:\\Users\\me\\My Code"', "C:\\Users\\me\\My Code"],
53 + ["Explorer, a share", "", '"\\\\host\\share\\My Code"', "\\\\host\\share\\My Code"],
54 + ["an apostrophe in double quotes", "", '"/Users/me/Bob\'s Stuff"', "/Users/me/Bob's Stuff"],
55 + ["a shell, home-relative", "", "~/Bob\\'s\\ Stuff", "~/Bob's Stuff"],
56 + ["surrounding whitespace", "", " '/Users/me/My Code'\n", "/Users/me/My Code"],
57 + ["over a selection", "/Users/me/old", "'/Users/me/My Code'", "/Users/me/My Code"],
58 + ["after a prefilled folder", "~/", "~/'/Users/me/My Code'", "/Users/me/My Code"],
59 + ["plain, after a prefilled folder", "~/", "~//Users/me/code", "/Users/me/code"],
60 + ["after a Windows folder", "C:\\Users\\", 'C:\\Users\\"D:\\My Code"', "D:\\My Code"],
61 + ["a shell's quoted apostrophe", "", "'/Users/me/Bob'\\''s Work'", "/Users/me/Bob's Work"],
62 + ["after a clone destination", "~/code/repo", "~/code/repo'/a b'", "/a b"],
63 + ["over part of the box", "~/code/old", "~/code/'/a b'", "/a b"],
64 + ])("reads the path copied from %s", (_source, previous, next, expected) => {
65 + expect(resolvePastedPath(previous, next)).toBe(expected);
66 + });
67 +
68 + it.each([
69 + ["typing a separator", "/Users/me", "/Users/me/"],
70 + ["typing a separator after a folder", "~/", "~//"],
71 + ["typing a trailing space", "/Users/My", "/Users/My "],
72 + ["deleting", "/Users/me/", "/Users/me"],
73 + ["pasting a relative folder", "~/", "~/Documents/code"],
74 + ["a longer path over a selection", "/Users/me", "/Users/me/code"],
75 + ["a longer path after a folder", "/Users/me/", "/Users/me/code"],
76 + ["quoted text that is no path", "", "'hello world'"],
77 + ["a quoted relative path", "", "'code/my app'"],
78 + ["a search ending in a quoted path", "", "find '/tmp/repo'"],
79 + ["a quote left open", "", "'/Users/me/My Code"],
80 + ["a quote inside the quotes", "", "'/Users/me/it's here'"],
81 + ["Windows separators", "", "C:\\Users\\me\\code"],
82 + ["a Windows dot folder", "", "C:\\Users\\me\\.config"],
83 + ["a Windows dot folder below home", "", "~/code\\.vscode"],
84 + ["a share", "", "\\\\host\\share\\code"],
85 + ["a backslash before a letter", "", "/Users/me/a\\b"],
86 + ])("keeps %s", (_case, previous, next) => {
87 + expect(resolvePastedPath(previous, next)).toBe(next);
88 + });
89 +
90 + it.each(["/Users/me/a\\ b", "~/code\\.vscode", "'/Users/me/My Code'"])(
91 + "leaves %s typed one character at a time",
92 + (typed) => {
93 + const box = [...typed].reduce((text, char) => resolvePastedPath(text, text + char), "");
94 + expect(box).toBe(typed);
95 + },
96 + );
97 +});
98 +
99 describe("workspaceRelativeFilePath", () => {
100 // regression: #9309 POSIX paths compare case-sensitively, Windows paths do not
101 it.each([
packages/shared/src/path.ts
+29
@@ -124,6 +124,35 @@ export function isHostPath(value: string): boolean {
124 return isAbsolutePath(value) || value.startsWith("~/");
125 }
126
127 +// Finder and Explorer copy a path ready for a shell: `'/a b'`, `/a\'s\ b`, or `"C:\a b"`.
128 +const QUOTED_PATH_AT_END = /(?:'((?:[^']|'\\'')+)'|"([^"]+)")\s*$/;
129 +const SHELL_ESCAPE = /\\([\s'"\\()[\]{}<>|&;$`!*?#~^=])/g;
130 +
131 +/**
132 + * What a folder box holds after a change. A full path pasted into it replaces the box, even after
133 + * the text already there, because `~/'/a b'` would create that nested folder.
134 + */
135 +export function resolvePastedPath(previous: string, next: string): string {
136 + const isTyping = next.startsWith(previous)
137 + ? next.length === previous.length + 1
138 + : previous.startsWith(next);
139 + if (isTyping) return next;
140 +
141 + const match = QUOTED_PATH_AT_END.exec(next);
142 + // Text before the quote that wasn't in the box is a search, not a folder to paste after.
143 + if (match && previous.startsWith(next.slice(0, match.index).trimEnd())) {
144 + const quoted = match[1]?.replaceAll("'\\''", "'") ?? match[2] ?? "";
145 + if (isHostPath(quoted)) return quoted;
146 + }
147 +
148 + // Without a trailing separator, `/a` then `/a/b` is a longer path, not one pasted after a folder.
149 + const afterFolder = /[/\\]$/.test(previous) && next.startsWith(previous);
150 + const path = afterFolder ? next.slice(previous.length) : next;
151 + if (!isHostPath(path)) return next;
152 + // `\` separates folders in Windows paths, so it only escapes in `/` and `~/` paths.
153 + return isWindowsAbsolutePath(path) ? path : path.replace(SHELL_ESCAPE, "$1");
154 +}
155 +
156 export function resolveWorkspaceFilePath(path: string, workspaceRoot: string): string {
157 if (isAbsolutePath(path) || path.startsWith("~/") || path.startsWith("~\\")) return path;
158 const base = workspaceRoot.replace(/[/\\]+$/, "");