ea84b913b4
* feat: choose worktree when opening IDE on multi-repo tasks On multi-repo tasks the open-in-IDE button always opened the first worktree. The editors menu now shows a worktree picker (repo + branch) when a session has multiple worktrees, and each editor in the dropdown expands into a per-worktree submenu. - open-editor/open-folder accept an optional worktree_id; empty keeps the first-worktree fallback so existing clients are unaffected - session DTOs now serialize the full worktrees list instead of only the flattened first-worktree fields - useSessionWorktrees unions API worktrees with the WS-populated list - new Playwright spec covers the picker on a real multi-repo session * fix: address review feedback on worktree picker - fall back on empty-string worktree fields, not only null/undefined - bind optional open-folder body via EOF check instead of ContentLength so chunked requests keep their worktree_id - wrap disabled editor buttons in a focusable span so tooltips work - add hook test asserting worktreeId is forwarded as worktree_id * fix: map editor service errors to HTTP status, drop e2e sleep - open-editor/open-folder return 404/400/409 for known service errors (unknown worktree or editor, invalid config, unavailable editor) instead of a blanket 500 - replace the picker spec's 750ms sleep with an explicit composer click so the autofocus race is deterministic --------- Co-authored-by: Kandev Agent <agent@kandev.dev>
30 lines
954 B
TypeScript
30 lines
954 B
TypeScript
import type { Worktree } from "@/lib/state/slices/session/types";
|
|
import type { Repository } from "@/lib/types/http";
|
|
|
|
export type WorktreeOption = {
|
|
worktreeId: string;
|
|
label: string;
|
|
branch?: string;
|
|
};
|
|
|
|
function worktreePathBasename(path: string | undefined): string | undefined {
|
|
if (!path) return undefined;
|
|
return path.split(/[\\/]/).filter(Boolean).pop();
|
|
}
|
|
|
|
/**
|
|
* Builds display options for a session's worktrees: labeled by repository name
|
|
* when known, otherwise by the worktree folder name.
|
|
*/
|
|
export function buildWorktreeOptions(
|
|
worktrees: Worktree[],
|
|
repositories: Repository[],
|
|
): WorktreeOption[] {
|
|
return worktrees.map((worktree, index) => {
|
|
const repository = repositories.find((repo) => repo.id === worktree.repositoryId);
|
|
const label =
|
|
repository?.name ?? worktreePathBasename(worktree.path) ?? `Worktree ${index + 1}`;
|
|
return { worktreeId: worktree.id, label, branch: worktree.branch };
|
|
});
|
|
}
|