From afc858af6849fbd0552714075e6d268e8a71d90b Mon Sep 17 00:00:00 2001 From: Alex Alecu Date: Wed, 8 Apr 2026 16:26:25 +0300 Subject: [PATCH] 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. --- .../cli/cmd/tui/component/dialog-session-list.tsx | 2 +- packages/opencode/src/server/routes/experimental.ts | 12 ++++++++++++ packages/opencode/src/session/index.ts | 1 + packages/sdk/js/src/v2/gen/types.gen.ts | 1 + packages/sdk/openapi.json | 6 ++++++ 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/opencode/src/cli/cmd/tui/component/dialog-session-list.tsx b/packages/opencode/src/cli/cmd/tui/component/dialog-session-list.tsx index dedd30a3655..e063844c005 100644 --- a/packages/opencode/src/cli/cmd/tui/component/dialog-session-list.tsx +++ b/packages/opencode/src/cli/cmd/tui/component/dialog-session-list.tsx @@ -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, diff --git a/packages/opencode/src/server/routes/experimental.ts b/packages/opencode/src/server/routes/experimental.ts index 1acd7be0039..268b4d0c976 100644 --- a/packages/opencode/src/server/routes/experimental.ts +++ b/packages/opencode/src/server/routes/experimental.ts @@ -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 diff --git a/packages/opencode/src/session/index.ts b/packages/opencode/src/session/index.ts index 4eca075c919..dc4ee8529ed 100644 --- a/packages/opencode/src/session/index.ts +++ b/packages/opencode/src/session/index.ts @@ -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", }) diff --git a/packages/sdk/js/src/v2/gen/types.gen.ts b/packages/sdk/js/src/v2/gen/types.gen.ts index 3c0fd23c396..2a49963f81f 100644 --- a/packages/sdk/js/src/v2/gen/types.gen.ts +++ b/packages/sdk/js/src/v2/gen/types.gen.ts @@ -1780,6 +1780,7 @@ export type GlobalSession = { diff?: string } project: ProjectSummary | null + worktreeName?: string } export type McpResource = { diff --git a/packages/sdk/openapi.json b/packages/sdk/openapi.json index a2e81ed9b52..11046f7c45f 100644 --- a/packages/sdk/openapi.json +++ b/packages/sdk/openapi.json @@ -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"]