fix(cli): resolve worktree folder name for session list labels

Instead of path.basename(session.directory) which shows the working
directory name (e.g. 'opencode' for sessions in packages/opencode/),
resolve the actual worktree root by matching against WorktreeFamily.list()
directories. This shows the correct worktree folder name (e.g. 'kilocode',
'cross-session-conflict') matching git worktree list output.
This commit is contained in:
Alex Alecu
2026-04-08 16:26:25 +03:00
parent b89513fd8d
commit afc858af68
5 changed files with 21 additions and 1 deletions
@@ -71,7 +71,7 @@ export function DialogSessionList() {
const isWorking = status?.type === "busy"
return {
title: isDeleting ? `Press ${keybind.print("session_delete")} again to confirm` : x.title,
description: all ? `(${path.basename(x.directory)})` : undefined, // kilocode_change - worktree label
description: all && x.worktreeName ? `(${x.worktreeName})` : undefined, // kilocode_change - worktree label
bg: isDeleting ? theme.error : undefined,
value: x.id,
category,
@@ -16,6 +16,8 @@ import { WorktreeDiff } from "../../kilocode/review/worktree-diff" // kilocode_c
import { WorktreeFamily } from "../../kilocode/worktree-family" // kilocode_change
import { Log } from "../../util/log" // kilocode_change
import { WorkspaceRoutes } from "./workspace"
import { Filesystem } from "../../util/filesystem" // kilocode_change
import path from "path" // kilocode_change
export const ExperimentalRoutes = lazy(() =>
new Hono()
@@ -356,6 +358,9 @@ export const ExperimentalRoutes = lazy(() =>
? Instance.project.id // kilocode_change
: query.projectID
const directories = query.worktrees ? await WorktreeFamily.list() : undefined // kilocode_change
// kilocode_change start - sort longest-first so most specific worktree matches first
const sorted = directories ? [...directories].sort((a, b) => b.length - a.length) : undefined
// kilocode_change end
const sessions: Session.GlobalInfo[] = []
for await (const session of Session.listGlobal({
projectID, // kilocode_change
@@ -368,6 +373,13 @@ export const ExperimentalRoutes = lazy(() =>
limit: limit + 1,
archived: query.archived,
})) {
// kilocode_change start - resolve worktree folder name for each session
if (sorted) {
const root = sorted.find((d) => Filesystem.contains(d, session.directory))
sessions.push({ ...session, worktreeName: path.basename(root ?? session.directory) })
continue
}
// kilocode_change end
sessions.push(session)
}
const hasMore = sessions.length > limit
+1
View File
@@ -204,6 +204,7 @@ export namespace Session {
export const GlobalInfo = Info.extend({
project: ProjectInfo.nullable(),
worktreeName: z.string().optional(), // kilocode_change - basename of the specific worktree directory
}).meta({
ref: "GlobalSession",
})
+1
View File
@@ -1780,6 +1780,7 @@ export type GlobalSession = {
diff?: string
}
project: ProjectSummary | null
worktreeName?: string
}
export type McpResource = {
+6
View File
@@ -5818,6 +5818,9 @@
"projectID": {
"type": "string"
},
"force": {
"type": "boolean"
},
"workspaceID": {
"type": "string"
},
@@ -14210,6 +14213,9 @@
"type": "null"
}
]
},
"worktreeName": {
"type": "string"
}
},
"required": ["id", "slug", "projectID", "directory", "title", "version", "time", "project"]