Skip to content

Commit cad9488

Browse files
fix(sidebar): preserve path case for directory queries (anomalyco#729)
1 parent 05ba208 commit cad9488

3 files changed

Lines changed: 14 additions & 19 deletions

File tree

‎packages/app/src/app/app.tsx‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ import {
104104
isVisibleTextPart,
105105
isTauriRuntime,
106106
modelEquals,
107+
normalizeDirectoryQueryPath,
107108
normalizeDirectoryPath,
108109
} from "./utils";
109110
import { currentLocale, setLocale, t, type Language } from "../i18n";
@@ -2513,7 +2514,7 @@ export default function App() {
25132514
if (!directory) {
25142515
try {
25152516
const pathInfo = unwrap(await c.path.get());
2516-
const discovered = normalizeDirectoryPath(pathInfo.directory ?? "");
2517+
const discovered = normalizeDirectoryQueryPath(pathInfo.directory ?? "");
25172518
if (discovered) {
25182519
directory = discovered;
25192520
c = createClient(config.baseUrl, directory, config.auth);
@@ -2523,13 +2524,7 @@ export default function App() {
25232524
}
25242525
}
25252526

2526-
const queryDirectory = (() => {
2527-
const trimmed = (directory ?? "").trim();
2528-
if (!trimmed) return undefined;
2529-
const unified = trimmed.replace(/\\/g, "/");
2530-
const withoutTrailing = unified.replace(/\/+$/, "");
2531-
return withoutTrailing || "/";
2532-
})();
2527+
const queryDirectory = normalizeDirectoryQueryPath(directory) || undefined;
25332528

25342529
// Fetch sessions scoped to the workspace directory to avoid loading the
25352530
// full global session list for every workspace.
@@ -4342,7 +4337,7 @@ export default function App() {
43424337
if (!resolvedProjectDir) {
43434338
try {
43444339
const pathInfo = unwrap(await activeClient.path.get());
4345-
const discoveredRaw = normalizeDirectoryPath(pathInfo.directory ?? "");
4340+
const discoveredRaw = normalizeDirectoryQueryPath(pathInfo.directory ?? "");
43464341
const discovered = discoveredRaw.replace(/^\/private\/tmp(?=\/|$)/, "/tmp");
43474342
if (discovered) {
43484343
resolvedProjectDir = discovered;
@@ -4532,7 +4527,7 @@ export default function App() {
45324527
if (!resolvedProjectDir) {
45334528
try {
45344529
const pathInfo = unwrap(await activeClient.path.get());
4535-
const discoveredRaw = normalizeDirectoryPath(pathInfo.directory ?? "");
4530+
const discoveredRaw = normalizeDirectoryQueryPath(pathInfo.directory ?? "");
45364531
const discovered = discoveredRaw.replace(/^\/private\/tmp(?=\/|$)/, "/tmp");
45374532
if (discovered) {
45384533
resolvedProjectDir = discovered;

‎packages/app/src/app/context/session.ts‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import type {
1818
} from "../types";
1919
import {
2020
addOpencodeCacheHint,
21+
normalizeDirectoryQueryPath,
2122
modelFromUserMessage,
2223
normalizeDirectoryPath,
2324
normalizeEvent,
@@ -592,13 +593,7 @@ export function createSessionStore(options: {
592593
// Note: We intentionally normalize slashes + trailing separators but do NOT
593594
// lowercase on Windows for the query value because the server does strict
594595
// string equality against the stored session.directory.
595-
const queryDirectory = (() => {
596-
const trimmed = (scopeRoot ?? "").trim();
597-
if (!trimmed) return undefined;
598-
const unified = trimmed.replace(/\\/g, "/");
599-
const withoutTrailing = unified.replace(/\/+$/, "");
600-
return withoutTrailing || "/";
601-
})();
596+
const queryDirectory = normalizeDirectoryQueryPath(scopeRoot) || undefined;
602597

603598
const start = Date.now();
604599
sessionDebug("sessions:load:start", { scopeRoot: scopeRoot ?? null, queryDirectory: queryDirectory ?? null });

‎packages/app/src/app/utils/index.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,17 @@ export function formatBytes(bytes: number) {
180180
return `${rounded} ${units[idx]}`;
181181
}
182182

183-
export function normalizeDirectoryPath(input?: string | null) {
183+
export function normalizeDirectoryQueryPath(input?: string | null) {
184184
const trimmed = (input ?? "").trim();
185185
if (!trimmed) return "";
186186
const unified = trimmed.replace(/\\/g, "/");
187187
const withoutTrailing = unified.replace(/\/+$/, "");
188-
const normalized = withoutTrailing || "/";
188+
return withoutTrailing || "/";
189+
}
190+
191+
export function normalizeDirectoryPath(input?: string | null) {
192+
const normalized = normalizeDirectoryQueryPath(input);
193+
if (!normalized) return "";
189194
return isWindowsPlatform() ? normalized.toLowerCase() : normalized;
190195
}
191196

0 commit comments

Comments
 (0)