Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(renderer): name a project after its folder on Windows, not its whole path

Erik Zwepec8f7d138ab0
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 236cbbf64..b0acbb50a 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -242,7 +242,8 @@ import {
nextFreePosition,
armForColdOpen,
projectTargetFlagRefusal,
- clearAttachConsent
+ clearAttachConsent,
+ folderName
} from '../lib/projectOpen'
import {
FIT_NODE_OPTIONS,
@@ -10028,7 +10029,7 @@ export function Canvas() {
const contextFor = (nodeId: string): string => {
const node = nodesRef.current.find((n) => n.id === nodeId)
const cwd = (node?.data.cwd as string) || ''
- const folder = cwd.replace(/\/+$/, '').split('/').filter(Boolean).pop()
+ const folder = folderName(cwd)
const title = node?.data.title as string | undefined
return folder || (title && title !== 'Claude Code' ? title : '') || 'workspace'
}
diff --git a/src/renderer/lib/projectOpen.test.ts b/src/renderer/lib/projectOpen.test.ts
index 458309c11..9e71124e6 100644
--- a/src/renderer/lib/projectOpen.test.ts
+++ b/src/renderer/lib/projectOpen.test.ts
@@ -1,5 +1,7 @@
import { describe, it, expect, beforeEach } from 'vitest'
import {
+ folderName,
+ normalizeProjectCwd,
planOpenProject,
recordAttachConsent,
attachConsentRecorded,
@@ -284,3 +286,60 @@ describe('dialog copy flattens hostile names to one line (review M-2)', () => {
expect(plan.message.split('\n').length).toBe(3)
})
})
+
+
+/**
+ * The basename behind every project name. It used to be an inline `split('/')` at five sites, which
+ * on Windows returns the WHOLE path as one segment — so a project was named
+ * `C:\Users\me\code\my-app` in the sidebar and the tab bar, and, because `name` is git-shared
+ * through `project.json`, for every teammate who pulled that file as well.
+ */
+describe('folderName', () => {
+ it('takes the last segment of a POSIX path', () => {
+ expect(folderName('/Users/me/code/my-app')).toBe('my-app')
+ expect(folderName('/Users/me/code/my-app/')).toBe('my-app')
+ expect(folderName('/Users/me/code//my-app//')).toBe('my-app')
+ })
+
+ it('takes the last segment of a Windows path — the regression', () => {
+ expect(folderName('C:\\Users\\me\\code\\my-app')).toBe('my-app')
+ expect(folderName('C:\\Users\\me\\code\\my-app\\')).toBe('my-app')
+ // A UNC share, and a mixed-separator path (Node hands back both shapes).
+ expect(folderName('\\\\server\\share\\my-app')).toBe('my-app')
+ expect(folderName('C:\\Users\\me/code\\my-app')).toBe('my-app')
+ })
+
+ it('answers empty for a path with no folder in it, so callers own their fallback', () => {
+ // 'Project' is right for a project name and wrong for a notification label, so the fallback
+ // stays at each call site rather than being baked in here.
+ expect(folderName('')).toBe('')
+ expect(folderName('/')).toBe('')
+ expect(folderName('\\\\')).toBe('')
+ })
+
+ it('leaves a drive root as the drive, without inventing a name', () => {
+ expect(folderName('C:\\')).toBe('C:')
+ })
+})
+
+describe('normalizeProjectCwd', () => {
+ it('strips a trailing separator of either kind', () => {
+ expect(normalizeProjectCwd('/Users/me/code/')).toBe('/Users/me/code')
+ // The Windows half: stripping only `/` left the backslash in place, which then read as an
+ // empty final segment for anything that split the path afterwards.
+ expect(normalizeProjectCwd('C:\\Users\\me\\code\\')).toBe('C:\\Users\\me\\code')
+ expect(normalizeProjectCwd('C:\\Users\\me\\code\\\\')).toBe('C:\\Users\\me\\code')
+ })
+
+ it('keeps a drive root, which is not the same place as the drive', () => {
+ // `C:\\` is the root of drive C; `C:` is the CURRENT directory on drive C. Stripping the
+ // separator here would dedupe an opened drive root against the wrong project.
+ expect(normalizeProjectCwd('C:\\')).toBe('C:\\')
+ expect(normalizeProjectCwd('//')).toBe('//')
+ })
+
+ it('leaves a one-character path alone, root included', () => {
+ expect(normalizeProjectCwd('/')).toBe('/')
+ expect(normalizeProjectCwd('\\')).toBe('\\')
+ })
+})
diff --git a/src/renderer/lib/projectOpen.ts b/src/renderer/lib/projectOpen.ts
index 33975f0d4..900b8da18 100644
--- a/src/renderer/lib/projectOpen.ts
+++ b/src/renderer/lib/projectOpen.ts
@@ -18,7 +18,34 @@ export interface ProjectForOpen {
* defense, never a second resolution.
*/
export function normalizeProjectCwd(resolvedCwd: string): string {
- return resolvedCwd.length > 1 ? resolvedCwd.replace(/\/+$/, '') : resolvedCwd
+ // Both separators: a Windows cwd arrives with backslashes, and stripping only `/` left a
+ // trailing `\` in place — which then became an empty final segment for anything splitting the
+ // path afterwards.
+ if (resolvedCwd.length <= 1) return resolvedCwd
+ const stripped = resolvedCwd.replace(/[\\/]+$/, '')
+ // …but a separator is not always cosmetic. `C:\` is the drive ROOT; `C:` is the current
+ // directory ON drive C — a different place, and one that would dedupe against the wrong
+ // project. Likewise a path that is nothing but separators. Keep the original wherever
+ // removing the separator would change what the path MEANS.
+ return stripped === '' || /^[A-Za-z]:$/.test(stripped) ? resolvedCwd : stripped
+}
+
+/**
+ * The folder name a path ends in — the ONE basename for project naming, shared by every site that
+ * used to inline `split('/')`.
+ *
+ * That inline version only split on forward slashes, so on Windows a path like
+ * `C:\\Users\\me\\code\\my-app` came back as ONE segment: the whole path. Every project
+ * there was named after its absolute path, in the sidebar, in the tab bar, and — because `name` is
+ * git-shared through `project.json` — for every teammate who pulled that file too.
+ *
+ * Backslashes are folded to `/` before splitting, the way `session-host/host.ts` and
+ * `session-host/session.ts` already do it, so one implementation answers on both platforms. A path
+ * that is nothing but separators (or empty) has no folder name and yields `''`; callers keep their
+ * own fallback, since `'Project'` is right for a project and wrong for a notification label.
+ */
+export function folderName(p: string): string {
+ return p.replace(/\\/g, '/').split('/').filter(Boolean).pop() ?? ''
}
export function findProjectByCwd<T extends { cwd?: string }>(
@@ -135,7 +162,7 @@ export function planOpenProject(input: {
}
const name = oneLine(
(requestedName ?? '').trim() ||
- (normalizeProjectCwd(resolvedCwd).split('/').filter(Boolean).pop() || 'Project')
+ (folderName(normalizeProjectCwd(resolvedCwd)) || 'Project')
)
return {
kind: 'confirm',
diff --git a/src/renderer/state/projects.ts b/src/renderer/state/projects.ts
index ae182e223..070cc7d5e 100644
--- a/src/renderer/state/projects.ts
+++ b/src/renderer/state/projects.ts
@@ -16,6 +16,7 @@ import type { ProjectIcon } from '@shared/project-icon'
import { recordCapabilityAck, type CapabilityAnswer } from '@shared/project-capability-consent'
import { applyCanvasMutation, createProject, reorderGroupWithinParent } from './workspace'
import { markWorkspaceDirty } from './workspaceDirty'
+import { folderName } from '../lib/projectOpen'
interface ProjectsState {
projects: Project[]
@@ -298,7 +299,7 @@ export const useProjects = create<ProjectsState>((set, get) => ({
get().reopenProject(existing.id)
return existing
}
- const name = folder.split('/').filter(Boolean).pop() || 'Project'
+ const name = folderName(folder) || 'Project'
const project = get().addProject(name, folder)
set({ activeProjectId: project.id })
return project
@@ -633,7 +634,7 @@ export const useProjects = create<ProjectsState>((set, get) => ({
set((s) => ({ projects: [...s.projects, adopted] }))
return { project: adopted, created: false, adopted: true }
}
- const fallbackName = cwd.split('/').filter(Boolean).pop() || 'Project'
+ const fallbackName = folderName(cwd) || 'Project'
const project = {
...createProject(get().projects.length, name ?? fallbackName, cwd),
...(color ? { color } : {})