Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(mobile): 合并 Windows 同路径工作区并统一选中状态 (#5897)

DavidShenXD4c1554ecb693
diff --git a/apps/mobile/app/sessions/new.tsx b/apps/mobile/app/sessions/new.tsx
index aab0c6e1b5..53c1eba23b 100644
--- a/apps/mobile/app/sessions/new.tsx
+++ b/apps/mobile/app/sessions/new.tsx
@@ -7,6 +7,7 @@ import { retainOutboxFile, durableOutboxUploadUri, removeRetainedOutboxFiles, ou
import { buildOutboxItem, createOutboxClientId } from '@/session/sessionOutbox';
import type { DurableOutboxRecord } from '@/session/durableOutbox';
import { stripTrailingPathSeparators } from '@cindy/maker-shared/path-text';
+import { workspacePathsEqual } from '@/session/workspaceSelection';
import { isSharedTaskPeer } from '@cindy/device-link';
import { takeRefinementContextTail } from '@cindy/voice-input-core';
import { Stack, useIsFocused, useLocalSearchParams, useNavigation, useRouter } from 'expo-router';
@@ -6797,7 +6798,7 @@ export default function NewRemoteSessionScreen() {
<View>
{recentWorkspaces.map((workspace) => {
const selected = draft.workspaceKind === 'project'
- && draft.workingDir.trim() === workspace.workingDir;
+ && workspacePathsEqual(draft.workingDir, workspace.workingDir);
return (
<Pressable
accessibilityLabel={t('session.new.selectProjectNamed', { title: workspace.title })}
diff --git a/apps/mobile/src/__tests__/nativeGlassControls.test.tsx b/apps/mobile/src/__tests__/nativeGlassControls.test.tsx
index 9fad787113..bed81f7607 100644
--- a/apps/mobile/src/__tests__/nativeGlassControls.test.tsx
+++ b/apps/mobile/src/__tests__/nativeGlassControls.test.tsx
@@ -47,7 +47,13 @@ vi.mock("react-i18next", () => ({
vi.mock("@/session/ComposerSheet", () => ({
ComposerSheet: ({ children, footer }: any) => <div>{children}{footer}</div>,
}));
-vi.mock("@/session/ComposerNativeRow", () => ({ ComposerNativeRow: () => null }));
+vi.mock("@/session/ComposerNativeRow", () => ({
+ ComposerNativeRow: ({ title, subtitle, selected, disabled, onPress, testID }: any) => (
+ <button data-testid={testID} aria-pressed={selected} disabled={disabled} onClick={onPress}>
+ {title}{subtitle}
+ </button>
+ ),
+}));
vi.mock("@/session/ComposerNativeSection", () => ({
ComposerNativeSection: ({ children }: any) => <div>{children}</div>,
}));
@@ -362,6 +368,38 @@ function directoryProps(overrides: Partial<NewTaskSelectionSheetProps> = {}): Ne
};
}
+it.each(["light", "dark"])("selects equivalent remote Windows workspaces without rewriting their paths in %s", (mode) => {
+ state.mode = mode;
+ const props = directoryProps({
+ page: "workspace", workingDir: "d:/PROJECTS/cindy/",
+ workspaces: [{ title: "cindy", workingDir: "D:\\projects\\cindy" }],
+ });
+ const host = mount(<NewTaskSelectionSheet {...props} />);
+ const row = host.querySelector('[data-testid="newSession.workspaceProjectOption"]') as HTMLButtonElement;
+ expect(row.getAttribute("aria-pressed")).toBe("true");
+ expect(row.textContent).toContain("D:\\projects\\cindy");
+ act(() => row.click());
+ expect(props.onProject).toHaveBeenCalledExactlyOnceWith("D:\\projects\\cindy");
+ const dialogueHost = mount(<NewTaskSelectionSheet {...props} workspaceKind="dialogue" />);
+ expect(dialogueHost.querySelector('[data-testid="newSession.workspaceProjectOption"]')!.getAttribute("aria-pressed"))
+ .toBe("false");
+});
+
+it.each([
+ ["/repo", "/repo/.cindy-worktrees/branch"],
+ ["D:/repo", "d:\\repo\\.cindy-worktrees\\branch"],
+])("does not mark %s selected for a remembered worktree directory", (base, worktree) => {
+ const props = directoryProps({
+ page: "workspace", workingDir: worktree, workspaces: [{ title: "repo", workingDir: base }],
+ });
+ const host = mount(<NewTaskSelectionSheet {...props} />);
+ const row = host.querySelector('[data-testid="newSession.workspaceProjectOption"]') as HTMLButtonElement;
+ expect(row.getAttribute("aria-pressed")).toBe("false");
+ expect(props.workingDir).toBe(worktree);
+ act(() => row.click());
+ expect(props.onProject).toHaveBeenCalledExactlyOnceWith(base);
+});
+
it.each(["light", "dark"])("gives the current-folder label a contrasting color and keeps selection working in %s", (mode) => {
state.mode = mode;
const props = directoryProps();
diff --git a/apps/mobile/src/__tests__/newSession.test.ts b/apps/mobile/src/__tests__/newSession.test.ts
index d26abf4e60..5842711f2a 100644
--- a/apps/mobile/src/__tests__/newSession.test.ts
+++ b/apps/mobile/src/__tests__/newSession.test.ts
@@ -1730,6 +1730,48 @@ describe('new session model', () => {
]);
});
+ // Remote path strings deliberately model the host OS, not the test runner's filesystem.
+ it.each([
+ ['slash direction', 'D:\\projects\\cindy', 'D:/projects/cindy'],
+ ['letter case', 'D:/projects/cindy', 'd:/PROJECTS/Cindy'],
+ ['trailing separator', 'D:\\projects\\cindy', 'D:\\projects\\cindy\\'],
+ ['combined variants', 'D:\\projects\\cindy', 'd:/PROJECTS/cindy/'],
+ ['drive root', 'D:\\', 'd:/'],
+ ['UNC share', '\\\\Server\\Share\\cindy', '//server/share/CINDY/'],
+ ['worktree', 'D:\\projects\\cindy', 'd:/PROJECTS/cindy/.cindy-worktrees/branch'],
+ ])('deduplicates equivalent remote Windows %s before sorting and limiting', (_name, original, variant) => {
+ const options = buildRecentWorkspaceOptions([
+ remoteSession('original', { workingDir: original, deviceLinkDeviceId: 'pc' }),
+ remoteSession('variant', {
+ workingDir: variant, deviceLinkDeviceId: 'pc', userSendAt: '2026-01-01T00:06:00.000Z',
+ }),
+ remoteSession('other', {
+ workingDir: 'D:/projects/other', deviceLinkDeviceId: 'pc', userSendAt: '2026-01-01T00:05:00.000Z',
+ }),
+ remoteSession('another-host', {
+ workingDir: variant, deviceLinkDeviceId: 'another-pc', userSendAt: '2026-01-01T00:07:00.000Z',
+ }),
+ ], 'pc', 2);
+
+ expect(options).toHaveLength(2);
+ expect(options[0]).toMatchObject({
+ workingDir: original, sessionCount: 2, lastActivityAt: '2026-01-01T00:06:00.000Z',
+ });
+ expect(options[1]).toMatchObject({ workingDir: 'D:/projects/other', sessionCount: 1 });
+ });
+
+ it('preserves remote POSIX case and literal backslashes while ignoring trailing slashes', () => {
+ const paths = ['/repo/App', '/repo/app', '/repo/app/', '/repo/weird\\name', '/repo/weird/name'];
+ const options = buildRecentWorkspaceOptions(paths.map((workingDir, index) =>
+ remoteSession(String(index), { workingDir }),
+ ));
+ expect(options).toHaveLength(4);
+ expect(options.find((option) => option.workingDir === '/repo/app')?.sessionCount).toBe(2);
+ expect(options.map((option) => option.workingDir)).toEqual(expect.arrayContaining([
+ '/repo/App', '/repo/weird\\name', '/repo/weird/name',
+ ]));
+ });
+
it('excludes worker-only directories before limiting recent workspace picks', () => {
const sessions = [
...Array.from({ length: 6 }, (_, index) => remoteSession(`worker-${index}`, {
diff --git a/apps/mobile/src/__tests__/newTaskSelectionAndroid.test.tsx b/apps/mobile/src/__tests__/newTaskSelectionAndroid.test.tsx
index ec44953702..d5b286be0e 100644
--- a/apps/mobile/src/__tests__/newTaskSelectionAndroid.test.tsx
+++ b/apps/mobile/src/__tests__/newTaskSelectionAndroid.test.tsx
@@ -183,3 +183,29 @@ it("keeps workspace choices and blocks them while busy", () => {
click("workspaceBrowseOption");
expect(props.onBrowse).toHaveBeenCalledOnce();
});
+
+it("selects an equivalent remote Windows path and sends the original workspace path", () => {
+ render({ page: "workspace", workingDir: "d:\\PROJECT\\" });
+ const row = container.querySelector('[data-testid="newSession.workspaceProjectOption"]')!;
+ expect(row.getAttribute("aria-pressed")).toBe("true");
+ click("workspaceProjectOption");
+ expect(props.onProject).toHaveBeenCalledExactlyOnceWith("D:/project");
+ render({ workspaceKind: "dialogue" });
+ expect(row.getAttribute("aria-pressed")).toBe("false");
+ render({ workspaceKind: "project", workingDir: "D:/different" });
+ expect(row.getAttribute("aria-pressed")).toBe("false");
+});
+
+it.each([
+ ["/repo", "/repo/.cindy-worktrees/branch"],
+ ["D:/repo", "d:\\repo\\.cindy-worktrees\\branch"],
+])("does not mark %s selected when the draft uses a worktree", (base, worktree) => {
+ render({ page: "workspace", workingDir: worktree, workspaces: [{ title: "repo", workingDir: base }] });
+ const row = container.querySelector('[data-testid="newSession.workspaceProjectOption"]')!;
+ expect(row.getAttribute("aria-pressed")).toBe("false");
+ expect(props.workingDir).toBe(worktree);
+ click("workspaceProjectOption");
+ expect(props.onProject).toHaveBeenCalledExactlyOnceWith(base);
+ render({ workingDir: base });
+ expect(row.getAttribute("aria-pressed")).toBe("true");
+});
diff --git a/apps/mobile/src/__tests__/workspaceSelection.test.ts b/apps/mobile/src/__tests__/workspaceSelection.test.ts
new file mode 100644
index 0000000000..a9cac91ed0
--- /dev/null
+++ b/apps/mobile/src/__tests__/workspaceSelection.test.ts
@@ -0,0 +1,33 @@
+import { expect, it } from 'vitest';
+import { workspacePathsEqual } from '@/session/workspaceSelection';
+
+// Remote host path strings; independent of the test runner's filesystem.
+it.each([
+ ['D:\\projects\\cindy', 'd:/PROJECTS/cindy/'],
+ ['D:\\', 'd:/'],
+ ['\\\\Server\\Share\\cindy', '//server/share/CINDY/'],
+ ['/repo/app/', '/repo/app'],
+ ['/', '/'],
+ ['D:\\repo\\.cindy-worktrees\\branch', 'd:/REPO/.cindy-worktrees/BRANCH/'],
+ ['/repo/.worktrees/branch/', '/repo/.worktrees/branch'],
+])('matches equivalent directory spellings: %s and %s', (left, right) => {
+ expect(workspacePathsEqual(left, right)).toBe(true);
+ expect(workspacePathsEqual(right, left)).toBe(true);
+});
+
+it.each([
+ ['/repo', '/repo/.cindy-worktrees/branch'],
+ ['D:/repo', 'd:\\repo\\.cindy-worktrees\\branch'],
+ ['/repo', '/repo/.xdt-worktrees/branch'],
+ ['/repo', '/repo/.worktrees/branch'],
+ ['/repo', '/repo/.claude/worktrees/branch'],
+ ['/repo/.cindy-worktrees/one', '/repo/.cindy-worktrees/two'],
+ ['/repo/App', '/repo/app'],
+ ['/repo/weird\\name', '/repo/weird/name'],
+ ['/repo/weird\\', '/repo/weird'],
+ ['D:/', 'D:'],
+ ['/', ''],
+])('keeps different target directories distinct: %s and %s', (left, right) => {
+ expect(workspacePathsEqual(left, right)).toBe(false);
+ expect(workspacePathsEqual(right, left)).toBe(false);
+});
diff --git a/apps/mobile/src/session/NewTaskSelectionSheet.android.tsx b/apps/mobile/src/session/NewTaskSelectionSheet.android.tsx
index d0f8a53104..29a79aae50 100644
--- a/apps/mobile/src/session/NewTaskSelectionSheet.android.tsx
+++ b/apps/mobile/src/session/NewTaskSelectionSheet.android.tsx
@@ -2,6 +2,7 @@ import { useEffect, useMemo, useRef, useState } from "react";
import { ActivityIndicator, View, useWindowDimensions } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { useTranslation } from "react-i18next";
+import { workspacePathsEqual } from "./workspaceSelection";
import {
ArrowUp,
ChevronRight,
@@ -115,7 +116,7 @@ export function NewTaskSelectionSheet(p: NewTaskSelectionSheetProps) {
leading={icon(Folder)}
selected={
p.workspaceKind === "project" &&
- p.workingDir.trim() === workspace.workingDir
+ workspacePathsEqual(p.workingDir, workspace.workingDir)
}
disabled={p.busy}
onPress={() => p.onProject(workspace.workingDir)}
diff --git a/apps/mobile/src/session/NewTaskSelectionSheet.ios.tsx b/apps/mobile/src/session/NewTaskSelectionSheet.ios.tsx
index fb28ed22fb..8289835fae 100644
--- a/apps/mobile/src/session/NewTaskSelectionSheet.ios.tsx
+++ b/apps/mobile/src/session/NewTaskSelectionSheet.ios.tsx
@@ -1,6 +1,7 @@
import { Button, Image, Picker, ProgressView, Text, Toggle } from '@expo/ui/swift-ui';
import { disabled, font, foregroundStyle, frame, pickerStyle, tag, tint } from '@expo/ui/swift-ui/modifiers';
import { useTranslation } from 'react-i18next';
+import { workspacePathsEqual } from './workspaceSelection';
import { iconSize, useTheme } from '@/theme';
import { ComposerSheet } from './ComposerSheet';
import { ComposerNativeRow } from './ComposerNativeRow';
@@ -52,7 +53,7 @@ export function NewTaskSelectionSheet(p: NewTaskSelectionSheetProps) {
{p.workspaces.length ? <Section>
{p.workspaces.map(workspace => <ComposerNativeRow key={workspace.workingDir}
title={workspace.title} subtitle={workspace.workingDir} leading={icon('folder')}
- selected={p.workspaceKind === 'project' && p.workingDir.trim() === workspace.workingDir}
+ selected={p.workspaceKind === 'project' && workspacePathsEqual(p.workingDir, workspace.workingDir)}
disabled={p.busy} onPress={() => p.onProject(workspace.workingDir)} testID="newSession.workspaceProjectOption" />)}
</Section> : null}
<Section>
diff --git a/apps/mobile/src/session/newSession.ts b/apps/mobile/src/session/newSession.ts
index 9cc94ba628..43387db4df 100644
--- a/apps/mobile/src/session/newSession.ts
+++ b/apps/mobile/src/session/newSession.ts
@@ -1,6 +1,7 @@
import { modelNeedsReselection } from './modelReselection';
import { stripTrailingPathSeparators } from '@cindy/maker-shared/path-text';
import { collapseWorktreeDirForGrouping } from '@cindy/maker-shared/worktree-paths';
+import { normalizeProjectOrderPath } from '@cindy/maker-shared/project-order-sync';
import {
DEFAULT_DRAFT_SESSION_TITLE,
deriveOptimisticSessionTitle,
@@ -368,10 +369,12 @@ export function buildRecentWorkspaceOptions(
const rawWorkingDir = session.workingDir?.trim();
if (!rawWorkingDir) continue;
const workingDir = collapseWorktreeDirForGrouping(rawWorkingDir);
+ // Match home project grouping; keep the original path for display and remote actions.
+ const pathKey = normalizeProjectOrderPath(workingDir);
const lastActivityAt = session.userSendAt ?? session.updatedAt ?? session.createdAt;
- const current = byPath.get(workingDir);
+ const current = byPath.get(pathKey);
if (!current) {
- byPath.set(workingDir, {
+ byPath.set(pathKey, {
workingDir,
title: projectTitle(workingDir),
sessionCount: 1,
diff --git a/apps/mobile/src/session/workspaceSelection.ts b/apps/mobile/src/session/workspaceSelection.ts
new file mode 100644
index 0000000000..e005d54e78
--- /dev/null
+++ b/apps/mobile/src/session/workspaceSelection.ts
@@ -0,0 +1,18 @@
+/** Compare actual workspace directories, without the worktree folding used by project groups. */
+export function workspacePathsEqual(left: string, right: string): boolean {
+ return normalizeWorkspacePath(left) === normalizeWorkspacePath(right);
+}
+
+function normalizeWorkspacePath(value: string): string {
+ const trimmed = value.trim();
+ // The path belongs to the remote host, not the phone's OS. POSIX backslashes are literal.
+ const windows = /^[a-z]:[\\/]/i.test(trimmed) || trimmed.startsWith('\\\\') || trimmed.startsWith('//');
+ const path = windows ? trimmed.replaceAll('\\', '/').toLowerCase() : trimmed;
+ let end = path.length;
+ while (end > 1 && path[end - 1] === '/') {
+ // Keep drive roots absolute: D:/ is not the drive-relative D:.
+ if (end === 3 && /^[a-z]:/i.test(path)) break;
+ end -= 1;
+ }
+ return path.slice(0, end);
+}