@laoyuehanni/dsh-git-worktree 0.4.0 → 0.4.1-dsh-0.1.2-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -21,6 +21,29 @@ window.__ModuleLoader__.load({
21
21
  const at = branch.indexOf("/");
22
22
  return at <= 0 ? branch : branch.slice(at + 1);
23
23
  }
24
+ /**
25
+ * Pre-flight check of a user-typed NEW branch name against git's ref-name
26
+ * rules (git check-ref-format's reject list, the subset typing can hit):
27
+ * non-empty; no leading `-` (git would parse it as a flag); no space, `~^:?*[\`
28
+ * or control character; no `..`, `@{`, `//`, leading/trailing `/`; no component
29
+ * starting with `.` or ending with `.lock`; no trailing `.`; not the lone `@`.
30
+ * `git switch -c` stays the authority — a miss here surfaces through the
31
+ * error envelope — this only feeds immediate form feedback.
32
+ * @param name - raw draft text (NOT trimmed: a space is a real issue).
33
+ * @returns the issue kind, or null when the name is acceptable.
34
+ */
35
+ function branchNameIssue(name) {
36
+ if (name.trim() === "") return "empty";
37
+ if (name.startsWith("-")) return "leadingDash";
38
+ if (name === "@") return "illegal";
39
+ if (/[\s~^:?*[\\\u0000-\u001f]/.test(name)) return "illegal";
40
+ if (name.includes("..") || name.includes("@{") || name.includes("//")) return "illegal";
41
+ if (name.startsWith("/") || name.endsWith("/")) return "illegal";
42
+ if (name.endsWith(".")) return "illegal";
43
+ if (/(^|\/)\./.test(name)) return "illegal";
44
+ if (/(^|\/)[^/]+\.lock($|\/)/.test(name)) return "illegal";
45
+ return null;
46
+ }
24
47
  //#endregion
25
48
  //#region src/wire.ts
26
49
  /**
@@ -37,6 +60,14 @@ window.__ModuleLoader__.load({
37
60
  const ROUTE_WORKTREE = `${ROUTE_PREFIX}/worktree`;
38
61
  /** POST ROUTE_PREFIX/switch — in-place branch switch of the main checkout. */
39
62
  const ROUTE_SWITCH = `${ROUTE_PREFIX}/switch`;
63
+ /** POST ROUTE_PREFIX/branch — create a NEW branch from the current checkout and switch to it. */
64
+ const ROUTE_BRANCH = `${ROUTE_PREFIX}/branch`;
65
+ /** POST ROUTE_PREFIX/fetch — sync remote-tracking refs (fetch every remote + prune). */
66
+ const ROUTE_FETCH = `${ROUTE_PREFIX}/fetch`;
67
+ /** POST ROUTE_PREFIX/update — fast-forward the current branch to its upstream. */
68
+ const ROUTE_UPDATE = `${ROUTE_PREFIX}/update`;
69
+ /** POST ROUTE_PREFIX/group — git belonging facts for a batch of workspace paths. */
70
+ const ROUTE_GROUP = `${ROUTE_PREFIX}/group`;
40
71
  //#endregion
41
72
  //#region src/client/api.ts
42
73
  /** POST one JSON body and parse the uniform envelope. */
@@ -105,12 +136,15 @@ window.__ModuleLoader__.load({
105
136
  * worktree (the current branch itself is occupied by the main worktree).
106
137
  * @param repoPath - absolute directory inside the repository.
107
138
  * @param branch - the current checkout's branch (or `HEAD` when detached).
139
+ * @param name - explicit name for the new branch; omitted, the host
140
+ * derives `<branch>-wt`, suffixing past taken names.
108
141
  */
109
- function requestWorktreeCutout(repoPath, branch) {
142
+ function requestWorktreeCutout(repoPath, branch, name) {
110
143
  return post(ROUTE_WORKTREE, {
111
144
  repoPath,
112
145
  branch,
113
- cutout: true
146
+ cutout: true,
147
+ ...name === void 0 ? {} : { name }
114
148
  });
115
149
  }
116
150
  /**
@@ -124,52 +158,96 @@ window.__ModuleLoader__.load({
124
158
  branch
125
159
  });
126
160
  }
161
+ /**
162
+ * Create a NEW branch from the directory's current checkout and switch to it
163
+ * in place.
164
+ * @param repoPath - absolute directory whose HEAD the branch is cut from.
165
+ * @param name - user-typed new branch name (validated client-side already).
166
+ */
167
+ function requestCreateBranch(repoPath, name) {
168
+ return post(ROUTE_BRANCH, {
169
+ repoPath,
170
+ name
171
+ });
172
+ }
173
+ /**
174
+ * Sync remote-tracking refs (fetch every remote + prune) for the repository.
175
+ * @param repoPath - absolute directory inside the repository.
176
+ */
177
+ function requestFetch(repoPath) {
178
+ return post(ROUTE_FETCH, { repoPath });
179
+ }
180
+ /**
181
+ * Update the CURRENT checkout: fetch every remote, then fast-forward the
182
+ * checked-out branch to its upstream.
183
+ * @param repoPath - absolute directory whose checked-out branch is updated.
184
+ */
185
+ function requestUpdate(repoPath) {
186
+ return post(ROUTE_UPDATE, { repoPath });
187
+ }
188
+ /**
189
+ * Git belonging facts for a batch of workspace directories; a path outside
190
+ * any git repository answers null, a failed route call answers the error
191
+ * envelope (the sidebar then renders flat, its degrade shape).
192
+ * @param paths - absolute workspace directories to probe.
193
+ */
194
+ async function requestGroupWorktrees(paths) {
195
+ return post(ROUTE_GROUP, { paths });
196
+ }
127
197
  //#endregion
128
- //#region \0git-worktree-css:D:\Code\dsh-worktree\src\client\BranchChip.module.css?inline
129
- const css$1 = "/* Branch chip row inside the composer tool row (conversation.input_2006230319.left_2006230319,\n * right of the mode chips). Modeled as a single rounded-rectangle\n * segmented control: the branch picker and the worktree toggle share one\n * container with a thin divider between them, so they read as one\n * affordance instead of two loose buttons.\n *\n * Geometry mirrors the composer trigger chips in the DSH base (see\n * PermissionSelect / ModelSelect): 28px height, 13/20 medium-secondary\n * label, transparent fill, no outline 鈥?the dock stays at the same\n * visual weight as the surrounding chips (dsh-worktree select, standard\n * mode select, Workspace Write, MiniMax-M3 High). The corners stop short\n * of the base's full pill (24px) so the silhouette stays a chip rather\n * than a capsule, per the design brief. */\n\n/* Shared trigger geometry 鈥?copied 1:1 from the base composer triggers\n * (PermissionSelect .trigger_2006230319 / ModelSelect .trigger_2006230319). Centralizing here\n * keeps the two segments visually fused so the divider reads as part of\n * one component, not two loose buttons. */\n.dock_2006230319 {\n display: inline-flex;\n align-items: stretch;\n height: 28px;\n border-radius: 6px;\n background: transparent;\n color: var(--dsw-alias-label-secondary, #81858c);\n font-size: 13px;\n line-height: 20px;\n font-weight: 500;\n min-height: 28px;\n overflow: hidden;\n}\n\n/* Vertical separator between the two segments. Uses the secondary label\n * color so it stays in the same tonal family as the surrounding trigger\n * outlines and chevrons. */\n.divider_2006230319 {\n width: 1px;\n margin: 6px 0;\n background: color-mix(in srgb, currentColor 22%, transparent);\n flex-shrink: 0;\n}\n\n.chip_2006230319 {\n display: inline-flex;\n align-items: center;\n gap: 4px;\n height: 100%;\n padding: 0 8px 0 8px;\n border: none;\n border-radius: 0;\n background: transparent;\n color: inherit;\n font: inherit;\n font-size: 13px;\n line-height: 20px;\n font-weight: 500;\n cursor: pointer;\n}\n\n.chip_2006230319:hover {\n background: var(--dsw-alias-interactive-bg-hover, color-mix(in srgb, currentColor 8%, transparent));\n}\n\n/* The leftmost segment rounds only its left corners so it tucks into the dock. */\n.chip_2006230319:first-child {\n border-top-left-radius: 6px;\n border-bottom-left-radius: 6px;\n}\n\n/* Started sessions drop the worktree segment: the lone chip rounds all\n * corners and reads as a plain button, not a broken-off half control. */\n.chip_2006230319:only-child {\n border-radius: 6px;\n}\n\n.branch_2006230319 {\n max-width: 16em;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n\n.check_2006230319,\n.checkOn_2006230319 {\n display: inline-flex;\n align-items: center;\n gap: 4px;\n height: 100%;\n padding: 0 4px 0 8px;\n border: none;\n border-radius: 0;\n background: transparent;\n color: inherit;\n font: inherit;\n font-size: 13px;\n line-height: 20px;\n font-weight: 500;\n cursor: pointer;\n}\n\n.check_2006230319:hover,\n.checkOn_2006230319:hover {\n background: var(--dsw-alias-interactive-bg-hover, color-mix(in srgb, currentColor 8%, transparent));\n}\n\n/* The rightmost segment rounds only its right corners. */\n.check_2006230319:last-child,\n.checkOn_2006230319:last-child {\n border-top-right-radius: 6px;\n border-bottom-right-radius: 6px;\n}\n\n.box_2006230319 {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 14px;\n height: 14px;\n border: 1px solid color-mix(in srgb, currentColor 45%, transparent);\n border-radius: 4px;\n}\n\n/* Selected worktree: only the checkbox itself turns bluish and fills 鈥?the\n * surrounding button stays transparent so the label keeps the same\n * secondary tone. Mirrors the Claude Code toggle treatment. The inner\n * check rides the bluish fill with an inverted foreground token so the\n * glyph stays legible. */\n.checkOn_2006230319 .box_2006230319 {\n border-color: var(--dsw-alias-label-primary-bluish, #4186f0);\n background: var(--dsw-alias-label-primary-bluish, #4186f0);\n color: var(--dsw-alias-label-primary-foreground, #ffffff);\n}\n\n.checkLabel_2006230319 {\n white-space: nowrap;\n}\n\n/* Confirm flyout: the second-level panel opening right of the branch\n * card (the base Menu's submenu posture: r12, inverted hairline,\n * shadow-lv3, --dsw-specific-menu). Width is content-driven — it follows\n * the branch name in the ask line — floored at 168px (the Cancel/Confirm\n * pair plus padding: short branch names must not squeeze the buttons into\n * wrapping \"切换中…\" mid-word) and capped at 400px; BranchMenu also clamps\n * it inline to the room right of the card. Beyond the cap the ask wraps.\n * border-box so every width arm includes the card chrome. */\n.popCard_2006230319 {\n box-sizing: border-box;\n position: fixed;\n z-index: 1000;\n width: max-content;\n min-width: 168px;\n max-width: min(400px, 80vw);\n padding: 4px;\n border: 1px solid var(--dsw-alias-border-inverted);\n border-radius: 12px;\n background: var(--dsw-specific-menu, var(--dsw-alias-surface-raised, #ffffff));\n box-shadow: var(--dsw-shadow-lv3);\n display: flex;\n flex-direction: column;\n gap: 2px;\n}\n\n.popAsk_2006230319 {\n margin: 0;\n padding: 6px 8px;\n font-size: 13px;\n line-height: 20px;\n color: inherit;\n /* Branch names are long unbroken tokens — plain wrapping would let them\n * overflow the capped card instead of breaking. */\n overflow-wrap: anywhere;\n}\n\n.popActions_2006230319 {\n display: flex;\n gap: 2px;\n padding: 2px;\n}\n\n/* Menu-row-like buttons: transparent fill, hover tint, same 13px type.\n * nowrap keeps labels like 切换中… from splitting mid-word when the flyout\n * is pinned to its minimum width by a short branch name. */\n.popActions_2006230319 button {\n flex: 1 1 0;\n height: 28px;\n border: none;\n border-radius: 8px;\n background: transparent;\n color: inherit;\n font: inherit;\n font-size: 13px;\n white-space: nowrap;\n cursor: pointer;\n}\n\n.popActions_2006230319 button:hover:not(:disabled) {\n background: var(--dsw-alias-interactive-bg-hover);\n}\n\n.popActions_2006230319 button:disabled {\n opacity: 0.5;\n cursor: default;\n}\n\n.popActions_2006230319 button:last-child {\n color: var(--dsw-alias-label-primary-bluish, #4186f0);\n font-weight: 500;\n}\n\n/* ── Branch picker popup (BranchMenu) ──────────────────────────────\n * Upward-opening card pinned above the chip, in the Menu's card chrome\n * (r12, inverted hairline, shadow-lv3, --dsw-specific-menu — same family\n * as .popCard_2006230319). Three owner requirements shape the geometry:\n *\n * 1. height cap: min(420px, 60vh) on the card, only the rows area\n * scrolls (.menuRows_2006230319) — heading and search stay pinned;\n * 2. the search field sits pinned at the card's bottom edge, directly\n * above the chip, with the scrolling rows above it;\n * 3. the card is CSS-`bottom`-pinned ~6px above the chip's top and so\n * grows entirely upward — it can never cover the composer or fill\n * the viewport, whatever the branch count.\n *\n * The inline `left`/`bottom` come from BranchMenu's placement pass; the\n * width is fixed here (design 360px — 320 tree + 40 tool strip — and\n * viewport-capped) so horizontal clamping stays deterministic without\n * measuring the card. */\n\n/* The portal lands directly under document.body_2006230319, outside the shell's\n * box-sizing reset — content-box default would add padding/border on top\n * of the declared width (360 became 370, and the width:100% children\n * padded 16px past the card's right clip, shearing off their rounded\n * corners). Every width-declared box in this popup opts back into\n * border-box: the card, the toolbar, the rows, and the search input. */\n.menuCard_2006230319 {\n box-sizing: border-box;\n position: fixed;\n z-index: 1000;\n display: flex;\n flex-direction: row;\n width: min(360px, calc(100vw - 24px));\n max-height: min(420px, 60vh);\n overflow: hidden;\n padding: 4px;\n border: 1px solid var(--dsw-alias-border-inverted);\n border-radius: 12px;\n background: var(--dsw-specific-menu, var(--dsw-alias-surface-raised, #ffffff));\n box-shadow: var(--dsw-shadow-lv3);\n}\n\n/* Left tool strip (IDEA branch-panel posture at popup scale): a narrow\n * column of icon-only buttons for actions that do not belong in the tree\n * — locate the checked-out branch, expand/collapse the whole tree.\n * Buttons stack from the BOTTOM up: the card's height shrinks when the\n * repo has few branches, so a top-anchored strip would drift around and\n * the buttons would sit far from the search bar; anchoring to the bottom\n * pins them at a stable spot (beside the search row) whatever the height. */\n.menuToolbar_2006230319 {\n box-sizing: border-box;\n display: flex;\n flex-direction: column;\n justify-content: flex-end;\n gap: 2px;\n flex-shrink: 0;\n width: 32px;\n padding: 0 2px;\n margin-right: 4px;\n border-right: 1px solid color-mix(in srgb, currentColor 12%, transparent);\n}\n\n.menuToolButton_2006230319 {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 28px;\n height: 28px;\n margin: 0 auto;\n border: none;\n border-radius: 8px;\n background: transparent;\n color: inherit;\n cursor: pointer;\n}\n\n.menuToolButton_2006230319:hover:not(:disabled) {\n background: var(--dsw-alias-interactive-bg-hover, color-mix(in srgb, currentColor 8%, transparent));\n}\n\n.menuToolButton_2006230319:disabled {\n opacity: 0.4;\n cursor: default;\n}\n\n/* The main column: heading + scrollable rows + pinned search. */\n.menuMain_2006230319 {\n box-sizing: border-box;\n display: flex;\n flex-direction: column;\n flex: 1 1 auto;\n min-width: 0;\n}\n\n/* Non-interactive group heading — the Menu label row's posture. */\n.menuHeading_2006230319 {\n padding: 6px 8px 4px;\n font-size: 13px;\n line-height: 20px;\n color: var(--dsw-alias-label-secondary, #81858c);\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n flex-shrink: 0;\n}\n\n/* The only scrollable region: shrinks within the capped card so the\n * heading above and the search below stay visible while rows scroll. */\n.menuRows_2006230319 {\n flex: 1 1 auto;\n min-height: 0;\n overflow-y: auto;\n}\n\n/* Menu-row-like buttons: transparent fill, hover tint, same 13px type.\n * Weight 500 mirrors the chip's branch label (the portal escapes the\n * composer's font context, so the match must be explicit — the inherited\n * body weight is 400 and reads visibly lighter than the chip beside it). */\n.menuRow_2006230319 {\n box-sizing: border-box; /* width:100% + padding must stay inside .menuRows_2006230319 */\n display: flex;\n align-items: center;\n gap: 8px;\n width: 100%;\n min-height: 28px;\n padding: 4px 8px;\n border: none;\n border-radius: 8px;\n background: transparent;\n color: inherit;\n font: inherit;\n font-size: 13px;\n font-weight: 500;\n line-height: 20px;\n text-align: left;\n cursor: pointer;\n}\n\n.menuRow_2006230319:hover:not(:disabled) {\n background: var(--dsw-alias-interactive-bg-hover, color-mix(in srgb, currentColor 8%, transparent));\n}\n\n/* The checked-out branch: a persistent tint a step above the resting rows\n * so it reads as \"you are here\" the moment the list scrolls it into view\n * (BranchMenu centers it on open) — the trailing check alone is easy to\n * miss from a distance. */\n.menuRowSelected_2006230319,\n.menuRowSelected_2006230319:hover:not(:disabled) {\n background: color-mix(in srgb, currentColor 10%, transparent);\n}\n\n/* IDEA-style selection: the clicked row gets a bluish fill, layering over\n * the HEAD tint when the same row is both — selection communicates intent,\n * the HEAD tint communicates position, and they coexist (IDEA 4.4). */\n.menuRowPicked_2006230319,\n.menuRowPicked_2006230319:hover:not(:disabled) {\n background: color-mix(in srgb, var(--dsw-alias-label-primary-bluish, #4186f0) 18%, transparent);\n}\n\n/* Occupied-worktree branches: dimmed, not clickable. */\n.menuRow_2006230319:disabled {\n opacity: 0.45;\n cursor: default;\n}\n\n.menuRowLabel_2006230319 {\n flex: 1 1 0;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n\n/* Search hit highlight (IDEA): the matched substring gets a warm tint\n * behind it — theme-agnostic, legible in both light and dark cards. */\n.menuSearchMark_2006230319 {\n background: color-mix(in srgb, #b58900 38%, transparent);\n border-radius: 2px;\n}\n\n/* Tree group rows (folder headers) — BranchMenu's '/' prefix tree: the\n * same row geometry as .menuRow_2006230319, but labeled in the secondary tone so the\n * leaf rows pop, with a count badge and a chevron that turns on expand. */\n.menuGroup_2006230319 {\n box-sizing: border-box;\n display: flex;\n align-items: center;\n gap: 6px;\n width: 100%;\n min-height: 28px;\n padding: 4px 8px;\n border: none;\n border-radius: 8px;\n background: transparent;\n color: var(--dsw-alias-label-secondary, #81858c);\n font: inherit;\n font-size: 13px;\n font-weight: 500;\n line-height: 20px;\n text-align: left;\n cursor: pointer;\n}\n\n.menuGroup_2006230319:hover {\n background: var(--dsw-alias-interactive-bg-hover, color-mix(in srgb, currentColor 8%, transparent));\n}\n\n.menuGroupLabel_2006230319 {\n flex: 1 1 0;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n\n.menuGroupChevron_2006230319 {\n flex-shrink: 0;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 12px;\n height: 12px;\n transition: transform 120ms ease;\n}\n\n.menuGroupChevronOpen_2006230319 {\n transform: rotate(90deg);\n}\n\n.menuGroupCount_2006230319 {\n flex-shrink: 0;\n font-size: 12px;\n line-height: 20px;\n font-weight: 400;\n color: color-mix(in srgb, currentColor 55%, transparent);\n}\n\n/* Zero-search-hit state: centered secondary line inside the rows area. */\n.menuEmpty_2006230319 {\n padding: 10px 8px;\n font-size: 13px;\n line-height: 20px;\n color: var(--dsw-alias-label-secondary, #81858c);\n text-align: center;\n}\n\n/* Bottom-pinned search field, separated from the rows by a hairline.\n * Borderless so it reads as part of the card, focus shown as the\n * standard hover tint rather than an outline. */\n.menuSearchWrap_2006230319 {\n flex-shrink: 0;\n margin-top: 2px;\n padding-top: 4px;\n border-top: 1px solid color-mix(in srgb, currentColor 12%, transparent);\n}\n\n.menuSearch_2006230319 {\n box-sizing: border-box; /* width:100% + padding must stay inside the wrap */\n width: 100%;\n height: 30px;\n padding: 0 8px;\n border: none;\n border-radius: 8px;\n background: transparent;\n color: inherit;\n font: inherit;\n font-size: 13px;\n /* Weight 500 mirrors the chip's branch label (see .menuRow_2006230319) — the portal\n * escapes the composer's font context and would inherit body's 400. */\n font-weight: 500;\n line-height: 20px;\n}\n\n.menuSearch_2006230319::placeholder {\n color: var(--dsw-alias-label-secondary, #81858c);\n}\n\n.menuSearch_2006230319:focus {\n outline: none;\n background: var(--dsw-alias-interactive-bg-hover, color-mix(in srgb, currentColor 8%, transparent));\n}\n";
130
- const tagId$1 = "@laoyuehanni/dsh-git-worktree/BranchChip.module.css";
131
- if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=\"" + tagId$1 + "\"]") === null) {
198
+ //#region \0git-worktree-css:C:\Users\OYW\.dsh\gitworktree\dsh-worktree-origin-feature-0.1.2-alpha.3\src\client\BranchChip.module.css?inline
199
+ const css$3 = "/* Branch chip row inside the composer tool row (conversation.input_1419641174.left_1419641174,\n * right of the mode chips). Modeled as a single rounded-rectangle\n * segmented control: the branch picker and the worktree toggle share one\n * container with a thin divider between them, so they read as one\n * affordance instead of two loose buttons.\n *\n * Geometry mirrors the composer trigger chips in the DSH base (see\n * PermissionSelect / ModelSelect): 28px height, 13/20 medium-secondary\n * label, transparent fill, no outline 鈥?the dock stays at the same\n * visual weight as the surrounding chips (dsh-worktree select, standard\n * mode select, Workspace Write, MiniMax-M3 High). The corners stop short\n * of the base's full pill (24px) so the silhouette stays a chip rather\n * than a capsule, per the design brief. */\n\n/* Shared trigger geometry 鈥?copied 1:1 from the base composer triggers\n * (PermissionSelect .trigger_1419641174 / ModelSelect .trigger_1419641174). Centralizing here\n * keeps the two segments visually fused so the divider reads as part of\n * one component, not two loose buttons. */\n.dock_1419641174 {\n display: inline-flex;\n align-items: stretch;\n height: 28px;\n border-radius: 6px;\n background: transparent;\n color: var(--dsw-alias-label-secondary, #81858c);\n font-size: 13px;\n line-height: 20px;\n font-weight: 500;\n min-height: 28px;\n overflow: hidden;\n}\n\n/* Vertical separator between the two segments. Uses the secondary label\n * color so it stays in the same tonal family as the surrounding trigger\n * outlines and chevrons. */\n.divider_1419641174 {\n width: 1px;\n margin: 6px 0;\n background: color-mix(in srgb, currentColor 22%, transparent);\n flex-shrink: 0;\n}\n\n.chip_1419641174 {\n display: inline-flex;\n align-items: center;\n gap: 4px;\n height: 100%;\n padding: 0 8px 0 8px;\n border: none;\n border-radius: 0;\n background: transparent;\n color: inherit;\n font: inherit;\n font-size: 13px;\n line-height: 20px;\n font-weight: 500;\n cursor: pointer;\n}\n\n.chip_1419641174:hover {\n background: var(--dsw-alias-interactive-bg-hover, color-mix(in srgb, currentColor 8%, transparent));\n}\n\n/* The leftmost segment rounds only its left corners so it tucks into the dock. */\n.chip_1419641174:first-child {\n border-top-left-radius: 6px;\n border-bottom-left-radius: 6px;\n}\n\n/* Started sessions drop the worktree segment: the lone chip rounds all\n * corners and reads as a plain button, not a broken-off half control. */\n.chip_1419641174:only-child {\n border-radius: 6px;\n}\n\n.branch_1419641174 {\n max-width: 16em;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n\n.check_1419641174,\n.checkOn_1419641174 {\n display: inline-flex;\n align-items: center;\n gap: 4px;\n height: 100%;\n padding: 0 4px 0 8px;\n border: none;\n border-radius: 0;\n background: transparent;\n color: inherit;\n font: inherit;\n font-size: 13px;\n line-height: 20px;\n font-weight: 500;\n cursor: pointer;\n}\n\n.check_1419641174:hover,\n.checkOn_1419641174:hover {\n background: var(--dsw-alias-interactive-bg-hover, color-mix(in srgb, currentColor 8%, transparent));\n}\n\n/* The rightmost segment rounds only its right corners. */\n.check_1419641174:last-child,\n.checkOn_1419641174:last-child {\n border-top-right-radius: 6px;\n border-bottom-right-radius: 6px;\n}\n\n.box_1419641174 {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 14px;\n height: 14px;\n border: 1px solid color-mix(in srgb, currentColor 45%, transparent);\n border-radius: 4px;\n}\n\n/* Selected worktree: only the checkbox itself turns bluish and fills 鈥?the\n * surrounding button stays transparent so the label keeps the same\n * secondary tone. Mirrors the Claude Code toggle treatment. The inner\n * check rides the bluish fill with an inverted foreground token so the\n * glyph stays legible. */\n.checkOn_1419641174 .box_1419641174 {\n border-color: var(--dsw-alias-label-primary-bluish, #4186f0);\n background: var(--dsw-alias-label-primary-bluish, #4186f0);\n color: var(--dsw-alias-label-primary-foreground, #ffffff);\n}\n\n.checkLabel_1419641174 {\n white-space: nowrap;\n}\n\n/* Confirm flyout: the second-level panel opening right of the branch\n * card (the base Menu's submenu posture: r12, inverted hairline,\n * shadow-lv3, --dsw-specific-menu). Width is content-driven — it follows\n * the longest line (for remote picks that is the subject line's branch\n * name) — floored at 168px (the Cancel/Confirm pair plus padding: short\n * branch names must not squeeze the buttons into wrapping \"切换中…\"\n * mid-word) and capped at 400px; BranchMenu also clamps it inline to the\n * room right of the card. Beyond the cap the lines wrap. border-box so\n * every width arm includes the card chrome. */\n.popCard_1419641174 {\n box-sizing: border-box;\n position: fixed;\n z-index: 1000;\n width: max-content;\n min-width: 168px;\n max-width: min(400px, 80vw);\n padding: 4px;\n border: 1px solid var(--dsw-alias-border-inverted);\n border-radius: 12px;\n background: var(--dsw-specific-menu, var(--dsw-alias-surface-raised, #ffffff));\n box-shadow: var(--dsw-shadow-lv3);\n display: flex;\n flex-direction: column;\n gap: 2px;\n}\n\n.popAsk_1419641174 {\n margin: 0;\n padding: 6px 8px;\n font-size: 13px;\n line-height: 20px;\n color: inherit;\n /* Branch names are long unbroken tokens — plain wrapping would let them\n * overflow the capped card instead of breaking. */\n overflow-wrap: anywhere;\n}\n\n/* Remote confirm's name line: the branch itself, weight 500 like the leaf\n * rows — the subject the ask line refers to (\"该远程分支\"). A dedicated\n * line keeps the long unbroken token away from the sentence, so wraps\n * happen inside the name instead of shredding the Chinese around it. */\n.popSubject_1419641174 {\n margin: 0;\n padding: 0 8px 2px;\n font-size: 13px;\n line-height: 20px;\n font-weight: 500;\n color: inherit;\n overflow-wrap: anywhere;\n}\n\n.popActions_1419641174 {\n display: flex;\n gap: 2px;\n padding: 2px;\n}\n\n/* Menu-row-like buttons: transparent fill, hover tint, same 13px type.\n * nowrap keeps labels like 切换中… from splitting mid-word when the flyout\n * is pinned to its minimum width by a short branch name. */\n.popActions_1419641174 button {\n flex: 1 1 0;\n height: 28px;\n border: none;\n border-radius: 8px;\n background: transparent;\n color: inherit;\n font: inherit;\n font-size: 13px;\n white-space: nowrap;\n cursor: pointer;\n}\n\n.popActions_1419641174 button:hover:not(:disabled) {\n background: var(--dsw-alias-interactive-bg-hover);\n}\n\n.popActions_1419641174 button:disabled {\n opacity: 0.5;\n cursor: default;\n}\n\n.popActions_1419641174 button:last-child {\n color: var(--dsw-alias-label-primary-bluish, #4186f0);\n font-weight: 500;\n}\n\n/* ── Branch picker popup (BranchMenu) ──────────────────────────────\n * Upward-opening card pinned above the chip, in the Menu's card chrome\n * (r12, inverted hairline, shadow-lv3, --dsw-specific-menu — same family\n * as .popCard_1419641174). Three owner requirements shape the geometry:\n *\n * 1. height cap: min(420px, 60vh) on the card, only the rows area\n * scrolls (.menuRows_1419641174) — heading and search stay pinned;\n * 2. the search field sits pinned at the card's bottom edge, directly\n * above the chip, with the scrolling rows above it;\n * 3. the card is CSS-`bottom`-pinned ~6px above the chip's top and so\n * grows entirely upward — it can never cover the composer or fill\n * the viewport, whatever the branch count.\n *\n * The inline `left`/`bottom` come from BranchMenu's placement pass; the\n * width is fixed here (design 360px — 320 tree + 40 tool strip — and\n * viewport-capped) so horizontal clamping stays deterministic without\n * measuring the card. */\n\n/* The portal lands directly under document.body_1419641174, outside the shell's\n * box-sizing reset — content-box default would add padding/border on top\n * of the declared width (360 became 370, and the width:100% children\n * padded 16px past the card's right clip, shearing off their rounded\n * corners). Every width-declared box in this popup opts back into\n * border-box: the card, the toolbar, the rows, and the search input. */\n.menuCard_1419641174 {\n box-sizing: border-box;\n position: fixed;\n z-index: 1000;\n display: flex;\n flex-direction: row;\n width: min(360px, calc(100vw - 24px));\n max-height: min(420px, 60vh);\n overflow: hidden;\n padding: 4px;\n border: 1px solid var(--dsw-alias-border-inverted);\n border-radius: 12px;\n background: var(--dsw-specific-menu, var(--dsw-alias-surface-raised, #ffffff));\n box-shadow: var(--dsw-shadow-lv3);\n}\n\n/* Left tool strip (IDEA branch-panel posture at popup scale): a narrow\n * column of icon-only buttons for actions that do not belong in the tree\n * — locate the checked-out branch, expand/collapse the whole tree.\n * Buttons stack from the BOTTOM up: the card's height shrinks when the\n * repo has few branches, so a top-anchored strip would drift around and\n * the buttons would sit far from the search bar; anchoring to the bottom\n * pins them at a stable spot (beside the search row) whatever the height. */\n.menuToolbar_1419641174 {\n box-sizing: border-box;\n display: flex;\n flex-direction: column;\n justify-content: flex-end;\n gap: 2px;\n flex-shrink: 0;\n width: 32px;\n padding: 0 2px;\n margin-right: 4px;\n border-right: 1px solid color-mix(in srgb, currentColor 12%, transparent);\n}\n\n.menuToolButton_1419641174 {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 28px;\n height: 28px;\n margin: 0 auto;\n border: none;\n border-radius: 8px;\n background: transparent;\n color: inherit;\n cursor: pointer;\n}\n\n.menuToolButton_1419641174:hover:not(:disabled) {\n background: var(--dsw-alias-interactive-bg-hover, color-mix(in srgb, currentColor 8%, transparent));\n}\n\n.menuToolButton_1419641174:disabled {\n opacity: 0.4;\n cursor: default;\n}\n\n/* The sync tools while their action runs: a soft opacity pulse. The glyph\n * is a directional arrow, so the circular-refresh spin read as garbled\n * rotation — pulsing keeps the arrow legible while clearly \"live\", and the\n * button keeps full opacity (the usual disabled dim would read as broken\n * for an in-flight network operation). */\n.menuToolButtonRunning_1419641174 svg {\n animation: menuToolPulse 700ms ease-in-out infinite alternate;\n}\n\n.menuToolButtonRunning_1419641174:disabled {\n opacity: 1;\n cursor: progress;\n}\n\n@keyframes menuToolPulse {\n from { opacity: 1; }\n to { opacity: 0.25; }\n}\n\n/* The main column: heading + scrollable rows + pinned search. */\n.menuMain_1419641174 {\n box-sizing: border-box;\n display: flex;\n flex-direction: column;\n flex: 1 1 auto;\n min-width: 0;\n}\n\n/* Non-interactive group heading — the Menu label row's posture. */\n.menuHeading_1419641174 {\n padding: 6px 8px 4px;\n font-size: 13px;\n line-height: 20px;\n color: var(--dsw-alias-label-secondary, #81858c);\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n flex-shrink: 0;\n}\n\n/* The only scrollable region: shrinks within the capped card so the\n * heading above and the search below stay visible while rows scroll. */\n.menuRows_1419641174 {\n flex: 1 1 auto;\n min-height: 0;\n overflow-y: auto;\n}\n\n/* Menu-row-like buttons: transparent fill, hover tint, same 13px type.\n * Weight 500 mirrors the chip's branch label (the portal escapes the\n * composer's font context, so the match must be explicit — the inherited\n * body weight is 400 and reads visibly lighter than the chip beside it). */\n.menuRow_1419641174 {\n box-sizing: border-box; /* width:100% + padding must stay inside .menuRows_1419641174 */\n display: flex;\n align-items: center;\n gap: 8px;\n width: 100%;\n min-height: 28px;\n padding: 4px 8px;\n border: none;\n border-radius: 8px;\n background: transparent;\n color: inherit;\n font: inherit;\n font-size: 13px;\n font-weight: 500;\n line-height: 20px;\n text-align: left;\n cursor: pointer;\n}\n\n.menuRow_1419641174:hover:not(:disabled) {\n background: var(--dsw-alias-interactive-bg-hover, color-mix(in srgb, currentColor 8%, transparent));\n}\n\n/* Locked rows (a linked-worktree session answers every non-current pick\n * with the main-checkout toast): dimmed with a default cursor, but KEEP\n * the click path alive — no disabled attribute, the double-click is the\n * toast's stage. Hover stays quiet: nothing is on offer here. */\n.menuRowLocked_1419641174 {\n opacity: 0.45;\n cursor: default;\n}\n\n.menuRowLocked_1419641174:hover {\n background: transparent;\n}\n\n/* The checked-out branch: a persistent tint a step above the resting rows\n * so it reads as \"you are here\" the moment the list scrolls it into view\n * (BranchMenu centers it on open) — the trailing check alone is easy to\n * miss from a distance. */\n.menuRowSelected_1419641174,\n.menuRowSelected_1419641174:hover:not(:disabled) {\n background: color-mix(in srgb, currentColor 10%, transparent);\n}\n\n/* IDEA-style selection: the clicked row gets a bluish fill, layering over\n * the HEAD tint when the same row is both — selection communicates intent,\n * the HEAD tint communicates position, and they coexist (IDEA 4.4). */\n.menuRowPicked_1419641174,\n.menuRowPicked_1419641174:hover:not(:disabled) {\n background: color-mix(in srgb, var(--dsw-alias-label-primary-bluish, #4186f0) 18%, transparent);\n}\n\n.menuRowLabel_1419641174 {\n flex: 1 1 0;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n\n/* Upstream divergence arrows (↑N/↓N) trailing a local branch row, before\n * the HEAD check: the count badge tone at a smaller size so a busy list\n * still reads the name first. Plain text arrows — no base-set icon pairs\n * a direction with a count. tabular-nums keeps ↑10 from nudging neighbors\n * as the digits tick. */\n.menuRowArrow_1419641174 {\n flex-shrink: 0;\n font-size: 11px;\n line-height: 20px;\n font-weight: 400;\n font-variant-numeric: tabular-nums;\n color: color-mix(in srgb, currentColor 55%, transparent);\n}\n\n/* Search hit highlight (IDEA): the matched substring gets a warm tint\n * behind it — theme-agnostic, legible in both light and dark cards. */\n.menuSearchMark_1419641174 {\n background: color-mix(in srgb, #b58900 38%, transparent);\n border-radius: 2px;\n}\n\n/* Tree group rows (folder headers) — BranchMenu's '/' prefix tree: the\n * same row geometry as .menuRow_1419641174, but labeled in the secondary tone so the\n * leaf rows pop, with a count badge and a chevron that turns on expand. */\n.menuGroup_1419641174 {\n box-sizing: border-box;\n display: flex;\n align-items: center;\n gap: 6px;\n width: 100%;\n min-height: 28px;\n padding: 4px 8px;\n border: none;\n border-radius: 8px;\n background: transparent;\n color: var(--dsw-alias-label-secondary, #81858c);\n font: inherit;\n font-size: 13px;\n font-weight: 500;\n line-height: 20px;\n text-align: left;\n cursor: pointer;\n}\n\n.menuGroup_1419641174:hover {\n background: var(--dsw-alias-interactive-bg-hover, color-mix(in srgb, currentColor 8%, transparent));\n}\n\n/* The two top-level section headers (local/remote branches) step ABOVE the\n * folder headers they contain: primary label tone like the leaf rows plus\n * a heavier weight, so the nav hierarchy reads group > row > folder — the\n * folder headers keep the secondary tone that alone would leave the\n * sections as the faintest (and most important) rows on the list. */\n.menuGroupTop_1419641174 {\n color: inherit;\n font-weight: 600;\n}\n\n.menuGroupLabel_1419641174 {\n flex: 1 1 0;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n\n.menuGroupChevron_1419641174 {\n flex-shrink: 0;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 12px;\n height: 12px;\n transition: transform 120ms ease;\n}\n\n.menuGroupChevronOpen_1419641174 {\n transform: rotate(90deg);\n}\n\n.menuGroupCount_1419641174 {\n flex-shrink: 0;\n font-size: 12px;\n line-height: 20px;\n font-weight: 400;\n color: color-mix(in srgb, currentColor 55%, transparent);\n}\n\n/* Zero-search-hit state: centered secondary line inside the rows area. */\n.menuEmpty_1419641174 {\n padding: 10px 8px;\n font-size: 13px;\n line-height: 20px;\n color: var(--dsw-alias-label-secondary, #81858c);\n text-align: center;\n}\n\n/* Bottom-pinned search field, separated from the rows by a hairline.\n * Borderless so it reads as part of the card, focus shown as the\n * standard hover tint rather than an outline. */\n.menuSearchWrap_1419641174 {\n flex-shrink: 0;\n margin-top: 2px;\n padding-top: 4px;\n border-top: 1px solid color-mix(in srgb, currentColor 12%, transparent);\n}\n\n.menuSearch_1419641174 {\n box-sizing: border-box; /* width:100% + padding must stay inside the wrap */\n width: 100%;\n height: 30px;\n padding: 0 8px;\n border: none;\n border-radius: 8px;\n background: transparent;\n color: inherit;\n font: inherit;\n font-size: 13px;\n /* Weight 500 mirrors the chip's branch label (see .menuRow_1419641174) — the portal\n * escapes the composer's font context and would inherit body's 400. */\n font-weight: 500;\n line-height: 20px;\n}\n\n.menuSearch_1419641174::placeholder {\n color: var(--dsw-alias-label-secondary, #81858c);\n}\n\n.menuSearch_1419641174:focus {\n outline: none;\n background: var(--dsw-alias-interactive-bg-hover, color-mix(in srgb, currentColor 8%, transparent));\n}\n\n/* ── New-branch create flyout (BranchMenu toolbar plus) ─────────────\n * Opens to the RIGHT of the card (the confirm flyout's posture) and holds\n * the whole flow in one panel: ask line, naming input, live hint, and the\n * Cancel/Create pair — typing the name and pressing Create fires the\n * create in one stroke, no second confirm step. */\n\n/* The toolbar plus in its active (flyout open) state: a bluish tint\n * layering the same way the picked row does, so the toggled state reads at\n * a glance. */\n.menuToolButtonOn_1419641174,\n.menuToolButtonOn_1419641174:hover:not(:disabled) {\n background: color-mix(in srgb, var(--dsw-alias-label-primary-bluish, #4186f0) 18%, transparent);\n color: var(--dsw-alias-label-primary-bluish, #4186f0);\n}\n\n/* The naming input inside the flyout: borderless, part of the card, focus\n * shown as the standard hover tint. Fixed width — the popCard is\n * max-content, so a percentage width would chase the input's own default\n * size instead of the design width. */\n.menuCreate_1419641174 {\n box-sizing: border-box;\n width: 248px;\n height: 30px;\n padding: 0 8px;\n border: none;\n border-radius: 8px;\n background: transparent;\n color: inherit;\n font: inherit;\n font-size: 13px;\n /* Weight 500 mirrors the chip's branch label (see .menuSearch_1419641174). */\n font-weight: 500;\n line-height: 20px;\n}\n\n.menuCreate_1419641174::placeholder {\n color: var(--dsw-alias-label-secondary, #81858c);\n}\n\n.menuCreate_1419641174:focus {\n outline: none;\n background: var(--dsw-alias-interactive-bg-hover, color-mix(in srgb, currentColor 8%, transparent));\n}\n\n.menuCreate_1419641174:disabled {\n opacity: 0.5;\n}\n\n/* The error line under the input — only rendered while the draft is\n * unacceptable with a non-empty reason; the input itself stays neutral,\n * the line carries the state. */\n.menuCreateHintBad_1419641174 {\n margin: 0;\n padding: 0 8px;\n font-size: 12px;\n line-height: 16px;\n color: var(--dsw-alias-label-error);\n}\n";
200
+ const tagId$3 = "@laoyuehanni/dsh-git-worktree/BranchChip.module.css";
201
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=\"" + tagId$3 + "\"]") === null) {
132
202
  const tag = document.createElement("style");
133
203
  tag.dataset.plugin = "@laoyuehanni/dsh-git-worktree";
134
- tag.dataset.pluginCss = tagId$1;
135
- tag.textContent = css$1;
204
+ tag.dataset.pluginCss = tagId$3;
205
+ tag.textContent = css$3;
136
206
  document.head.appendChild(tag);
137
207
  }
138
208
  var BranchChip_module_default = {
139
- "input": "input_2006230319",
140
- "left": "left_2006230319",
141
- "trigger": "trigger_2006230319",
142
- "dock": "dock_2006230319",
143
- "divider": "divider_2006230319",
144
- "chip": "chip_2006230319",
145
- "branch": "branch_2006230319",
146
- "check": "check_2006230319",
147
- "checkOn": "checkOn_2006230319",
148
- "box": "box_2006230319",
149
- "checkLabel": "checkLabel_2006230319",
150
- "popCard": "popCard_2006230319",
151
- "popAsk": "popAsk_2006230319",
152
- "popActions": "popActions_2006230319",
153
- "menuRows": "menuRows_2006230319",
154
- "body": "body_2006230319",
155
- "menuCard": "menuCard_2006230319",
156
- "menuToolbar": "menuToolbar_2006230319",
157
- "menuToolButton": "menuToolButton_2006230319",
158
- "menuMain": "menuMain_2006230319",
159
- "menuHeading": "menuHeading_2006230319",
160
- "menuRow": "menuRow_2006230319",
161
- "menuRowSelected": "menuRowSelected_2006230319",
162
- "menuRowPicked": "menuRowPicked_2006230319",
163
- "menuRowLabel": "menuRowLabel_2006230319",
164
- "menuSearchMark": "menuSearchMark_2006230319",
165
- "menuGroup": "menuGroup_2006230319",
166
- "menuGroupLabel": "menuGroupLabel_2006230319",
167
- "menuGroupChevron": "menuGroupChevron_2006230319",
168
- "menuGroupChevronOpen": "menuGroupChevronOpen_2006230319",
169
- "menuGroupCount": "menuGroupCount_2006230319",
170
- "menuEmpty": "menuEmpty_2006230319",
171
- "menuSearchWrap": "menuSearchWrap_2006230319",
172
- "menuSearch": "menuSearch_2006230319"
209
+ "input": "input_1419641174",
210
+ "left": "left_1419641174",
211
+ "trigger": "trigger_1419641174",
212
+ "dock": "dock_1419641174",
213
+ "divider": "divider_1419641174",
214
+ "chip": "chip_1419641174",
215
+ "branch": "branch_1419641174",
216
+ "check": "check_1419641174",
217
+ "checkOn": "checkOn_1419641174",
218
+ "box": "box_1419641174",
219
+ "checkLabel": "checkLabel_1419641174",
220
+ "popCard": "popCard_1419641174",
221
+ "popAsk": "popAsk_1419641174",
222
+ "popSubject": "popSubject_1419641174",
223
+ "popActions": "popActions_1419641174",
224
+ "menuRows": "menuRows_1419641174",
225
+ "body": "body_1419641174",
226
+ "menuCard": "menuCard_1419641174",
227
+ "menuToolbar": "menuToolbar_1419641174",
228
+ "menuToolButton": "menuToolButton_1419641174",
229
+ "menuToolButtonRunning": "menuToolButtonRunning_1419641174",
230
+ "menuMain": "menuMain_1419641174",
231
+ "menuHeading": "menuHeading_1419641174",
232
+ "menuRow": "menuRow_1419641174",
233
+ "menuRowLocked": "menuRowLocked_1419641174",
234
+ "menuRowSelected": "menuRowSelected_1419641174",
235
+ "menuRowPicked": "menuRowPicked_1419641174",
236
+ "menuRowLabel": "menuRowLabel_1419641174",
237
+ "menuRowArrow": "menuRowArrow_1419641174",
238
+ "menuSearchMark": "menuSearchMark_1419641174",
239
+ "menuGroup": "menuGroup_1419641174",
240
+ "menuGroupTop": "menuGroupTop_1419641174",
241
+ "menuGroupLabel": "menuGroupLabel_1419641174",
242
+ "menuGroupChevron": "menuGroupChevron_1419641174",
243
+ "menuGroupChevronOpen": "menuGroupChevronOpen_1419641174",
244
+ "menuGroupCount": "menuGroupCount_1419641174",
245
+ "menuEmpty": "menuEmpty_1419641174",
246
+ "menuSearchWrap": "menuSearchWrap_1419641174",
247
+ "menuSearch": "menuSearch_1419641174",
248
+ "menuToolButtonOn": "menuToolButtonOn_1419641174",
249
+ "menuCreate": "menuCreate_1419641174",
250
+ "menuCreateHintBad": "menuCreateHintBad_1419641174"
173
251
  };
174
252
  //#endregion
175
253
  //#region src/client/BranchMenu.tsx
@@ -192,15 +270,35 @@ window.__ModuleLoader__.load({
192
270
  * never cover the composer, whatever the branch count.
193
271
  *
194
272
  * Layout (IDEA branch-panel posture at popup scale): a narrow tool strip
195
- * on the left (locate-current + expand/collapse-all), then a main column
196
- * of heading / tree / search. Selection model borrowed from IDEA: a
197
- * single click SELECTS a row (blue); double-click or Enter then OPENS the
273
+ * on the left (locate-current + expand/collapse-all + new-branch), then a
274
+ * main column of heading / tree / search. The list renders in TWO
275
+ * top-level collapsible groups — local branches first, then remote
276
+ * branches (each a folder-header-style row with chevron + count): under a
277
+ * SINGLE remote the remote rows drop their `<remote>/` prefix (the header
278
+ * already says "remote"; a stripped display name can never collide with a
279
+ * local row because the host hides remote branches that have a local
280
+ * twin), with SEVERAL remotes the full names stay so `origin`/`upstream`
281
+ * become the folder layer beneath the header. Picking a remote row hands
282
+ * the owner the real `<remote>/name` (see pick) — the remote confirms are
283
+ * the owner's wording (tracking-twin switch / twin-in-worktree).
284
+ * Selection model borrowed from
285
+ * IDEA: a single click SELECTS a row (blue); double-click or Enter then OPENS the
198
286
  * right-side confirm flyout for that row — the switch itself always goes
199
287
  * through the confirmation step, never straight away. While the confirm
200
288
  * flyout is open, clicking another row re-anchors it (the old one-click
201
289
  * pick flow).
202
290
  *
203
- * The confirm step is a second-level flyout opening to the RIGHT of the
291
+ * The new-branch tool (the toolbar's plus) opens the create flyout to the
292
+ * RIGHT of the card (the confirm flyout's submenu posture): the flyout
293
+ * holds the naming input — validated as you type (git ref-name rules plus
294
+ * a duplicate check against the rows) with a live hint naming the issue
295
+ * or, while the draft is acceptable, the branch the cut starts from — and
296
+ * the Cancel/Create pair. Confirming fires the create in ONE stroke
297
+ * (create AND in-place switch; no second confirm step — typing the name
298
+ * into the flyout and pressing Create IS the intent). While the create
299
+ * runs the flyout freezes (busy disables input and buttons); a failure
300
+ * toasts and leaves the flyout open for a renamed retry.
301
+ * The confirm flyout is a second-level portal opening to the RIGHT of the
204
302
  * branch card (the base Menu's submenu posture): the chip sits in the
205
303
  * bottom composer, so the old below-the-chip bubble landed off-viewport.
206
304
  * The flyout is a separate portal (not clipped by the card's
@@ -208,20 +306,53 @@ window.__ModuleLoader__.load({
208
306
  * can never overlap the branch list — and vertically centered on the
209
307
  * picked row. Its width is content-driven, capped in CSS, wrapping.
210
308
  *
211
- * Close semantics: outside pointerdown (card, flyout, and chip excluded)
309
+ * Close semantics: outside pointerdown (card, flyouts, and chip excluded)
212
310
  * cancels the confirm and closes the menu; Escape unwinds tier by tier —
213
- * confirm, then search text, then selection, then the menu; Enter in the
214
- * search field commits the first enabled visible row.
311
+ * confirm, then the create flyout, then search text, then selection, then
312
+ * the menu; Enter in the search field commits the first enabled visible row.
215
313
  *
216
314
  * Long names and many branches: a clipped label shows the full name on
217
- * hover via the native title (gated to actually-clipped rows only). When
218
- * the list grows past TREE_MIN_ROWS it renders as a full-depth '/' prefix
219
- * tree instead: folder-header rows (chevron + count) toggle; under an
220
- * expanded folder, child rows show only their own segment (indentation
221
- * carries the hierarchy — no repeated path, no color distinction); linear
222
- * chains compress into one row; the checked-out branch's chain opens by
223
- * default (centering still lands it mid-viewport).
315
+ * hover via the native title (gated to actually-clipped rows only). The
316
+ * list ALWAYS renders as a full-depth '/' prefix tree: folder-header rows
317
+ * (chevron + count) toggle; under an expanded folder, child rows show only
318
+ * their own segment (indentation carries the hierarchy — no repeated path,
319
+ * no color distinction); linear chains compress into one row. TREE_MIN_ROWS
320
+ * only sets the DEFAULT opening depth: past it, just the checked-out
321
+ * branch's chain starts open (centering still lands it mid-viewport); at
322
+ * or under it, every folder starts open — few branches have nothing to hide.
323
+ */
324
+ /**
325
+ * The fetch/update glyph in IDEA's posture: a diagonal running from the
326
+ * top-right down to a bottom-left arrowhead. `dashed` marks the metadata
327
+ * move (fetch touches remote-tracking refs only, never working-tree
328
+ * content); the solid variant is the in-place branch update (fetch +
329
+ * fast-forward) — the pairing is IDEA's dashed/solid synchronize/update
330
+ * language. The base library has no such glyph, so both are drawn here,
331
+ * local to the menu; the sync spin animation targets `svg` descendants of
332
+ * the tool button and applies to them unchanged.
224
333
  */
334
+ function FetchGlyph({ size = 16, dashed = true }) {
335
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
336
+ width: size,
337
+ height: size,
338
+ viewBox: "0 0 16 16",
339
+ fill: "none",
340
+ "aria-hidden": "true",
341
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
342
+ d: "M13 3 L5.9 10.1",
343
+ stroke: "currentColor",
344
+ strokeWidth: "1.3",
345
+ strokeLinecap: "round",
346
+ strokeDasharray: dashed ? "2.4 1.6" : void 0
347
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
348
+ d: "M5 5.9 V11 H10.1",
349
+ stroke: "currentColor",
350
+ strokeWidth: "1.3",
351
+ strokeLinecap: "round",
352
+ strokeLinejoin: "round"
353
+ })]
354
+ });
355
+ }
225
356
  /** Viewport edge clearance, mirroring the base Menu portal margin. */
226
357
  const MARGIN = 12;
227
358
  /** Gap kept between the chip's top edge and the card's bottom edge. */
@@ -240,13 +371,58 @@ window.__ModuleLoader__.load({
240
371
  top: "0px",
241
372
  visibility: "hidden"
242
373
  };
243
- /** Below this many rows the picker stays a flat list: in small repos a
244
- * tree would hide real branches behind one-entry folders, buying nothing. */
374
+ /** Past this many rows the tree starts with ONLY the checked-out branch's
375
+ * chain open; at or under it every folder starts open (few branches have
376
+ * nothing to hide). The tree itself always renders — this threshold is
377
+ * about the default opening depth, never about flat vs tree. */
245
378
  const TREE_MIN_ROWS = 8;
379
+ /** Leaf rows indent one chevron slot PAST their tree depth. Folder headers
380
+ * lead with a collapsing chevron (12px icon + 6px gap) that leaf rows lack
381
+ * — without compensation a leaf's text starts LEFT of its own group header's
382
+ * text and same-level leaves read shallower than folders. The extra 18px
383
+ * aligns same-level leaf TEXT with folder TEXT (the VS Code file-tree
384
+ * posture: a chevron column marks foldable rows, a text column carries
385
+ * content), so leaf padding is 8 + 12×depth + 18. */
386
+ const LEAF_CHEVRON_SLOT = 18;
387
+ /** Every folder path that renders a header, walking the tree depth-first. */
388
+ function collectFolderPaths(nodes, out = []) {
389
+ for (const node of nodes) if (node.children.length > 0) {
390
+ out.push(node.path);
391
+ collectFolderPaths(node.children, out);
392
+ }
393
+ return out;
394
+ }
246
395
  const segCmp = (a, b) => a.localeCompare(b, void 0, {
247
396
  numeric: true,
248
397
  sensitivity: "base"
249
398
  });
399
+ /** Split rows into the three groups and derive the remote display names. */
400
+ function groupRows(rows) {
401
+ const localRows = [];
402
+ const remoteRows = [];
403
+ const worktreeRows = [];
404
+ for (const row of rows) if (row.kind === "remote") remoteRows.push(row);
405
+ else if (row.kind === "worktree") worktreeRows.push(row);
406
+ else localRows.push(row);
407
+ const first = remoteRows[0]?.name ?? "";
408
+ const slash = first.indexOf("/");
409
+ const soleRemote = slash > 0 && remoteRows.every((row) => row.name.startsWith(first.slice(0, slash + 1))) ? first.slice(0, slash) : void 0;
410
+ const display = (name) => soleRemote === void 0 ? name : name.slice(soleRemote.length + 1);
411
+ return {
412
+ localRows,
413
+ remoteDisplayRows: remoteRows.map((row) => ({
414
+ ...row,
415
+ name: display(row.name)
416
+ })),
417
+ worktreeRows,
418
+ remoteNameMap: new Map(remoteRows.map((row) => [display(row.name), row.name]))
419
+ };
420
+ }
421
+ /** Expanded-key space: folder paths carry their group prefix so a local
422
+ * folder can never share a toggle state with a same-named remote display
423
+ * folder (`feat/x` on both sides). Group OPEN flags stay booleans beside
424
+ * this set — they are not part of the path namespace at all. */
425
+ const groupKey = (group, path) => `${group}:${path}`;
250
426
  /** Build the prefix tree of the rows (see TreeNode). */
251
427
  function buildTree(rows) {
252
428
  const root = [];
@@ -256,11 +432,13 @@ window.__ModuleLoader__.load({
256
432
  let level = root;
257
433
  let path = "";
258
434
  for (let i = 0; i < segs.length; i += 1) {
259
- path = path === "" ? segs[i] : `${path}/${segs[i]}`;
260
- let node = find(level, segs[i]);
435
+ const seg = segs[i];
436
+ if (seg === void 0) break;
437
+ path = path === "" ? seg : `${path}/${seg}`;
438
+ let node = find(level, seg);
261
439
  if (node === void 0) {
262
440
  node = {
263
- segment: segs[i],
441
+ segment: seg,
264
442
  path,
265
443
  depth: i,
266
444
  leaf: null,
@@ -298,7 +476,9 @@ window.__ModuleLoader__.load({
298
476
  const set = /* @__PURE__ */ new Set();
299
477
  let path = "";
300
478
  for (let i = 0; i < segs.length - 1; i += 1) {
301
- path = path === "" ? segs[i] : `${path}/${segs[i]}`;
479
+ const seg = segs[i];
480
+ if (seg === void 0) break;
481
+ path = path === "" ? seg : `${path}/${seg}`;
302
482
  set.add(path);
303
483
  }
304
484
  return set;
@@ -322,7 +502,7 @@ window.__ModuleLoader__.load({
322
502
  * @param props - anchor, rows, confirm bundle, callbacks, and the class sheet.
323
503
  * @returns null while closed or unplaced; otherwise the portaled card (+flyout).
324
504
  */
325
- function BranchMenu({ open, anchorRef, rows, currentBranch, confirm, onSelect, onClose, t }) {
505
+ function BranchMenu({ open, anchorRef, rows, currentBranch, confirm, onSelect, canCreate, canAdopt, onCreate, busy, onFetch, fetchBusy, onUpdate, updateBusy, onClose, t }) {
326
506
  const cardRef = (0, react.useRef)(null);
327
507
  const inputRef = (0, react.useRef)(null);
328
508
  /**
@@ -332,10 +512,29 @@ window.__ModuleLoader__.load({
332
512
  * still unmounted — its focus() no-ops against a null ref. Focusing at
333
513
  * mount time is immune to that race by construction.
334
514
  */
335
- const holdSearchFocus = (el) => {
515
+ /**
516
+ * Search-field ref callback: focus the field the moment it mounts. The
517
+ * card mounts in two stages (open flips, then pos resolves a render
518
+ * later), so an [open]-keyed passive effect fires while the input is
519
+ * still unmounted — its focus() no-ops against a null ref. Focusing at
520
+ * mount time is immune to that race by construction. The callback MUST
521
+ * be referentially stable: a fresh closure per render makes React
522
+ * detach and re-attach it on every commit, and the re-attach runs
523
+ * focus() again — each re-render (a click selection, a status refresh,
524
+ * a sessions push) would yank focus back to the field, flickering its
525
+ * focus tint. Stable identity = attach happens only at mount.
526
+ */
527
+ const holdSearchFocus = (0, react.useCallback)((el) => {
336
528
  inputRef.current = el;
337
529
  if (el !== null) el.focus();
338
- };
530
+ }, []);
531
+ /** Same mount-time focus trick for the new-branch input: the form mounts
532
+ * when the toolbar plus flips `creating`, mid-card-lifecycle, so the ref
533
+ * callback is the only reliable focus point. Stable for the same reason
534
+ * as holdSearchFocus — typing would otherwise re-focus on every render. */
535
+ const holdCreateFocus = (0, react.useCallback)((el) => {
536
+ if (el !== null) el.focus();
537
+ }, []);
339
538
  const flyRef = (0, react.useRef)(null);
340
539
  const flyConfirmRef = (0, react.useRef)(null);
341
540
  /** The row whose pick is awaiting confirmation (anchoring element). */
@@ -347,17 +546,43 @@ window.__ModuleLoader__.load({
347
546
  const [pos, setPos] = (0, react.useState)(null);
348
547
  const [flyPos, setFlyPos] = (0, react.useState)(null);
349
548
  const [query, setQuery] = (0, react.useState)("");
350
- /** Expanded folder set, keyed by node path. Re-seeded on every open so
351
- * the current branch's chain is visible without re-expanding by hand. */
549
+ /** Expanded folder set, keyed by group-prefixed node path (see groupKey).
550
+ * Re-seeded on every open so the current branch's chain is visible
551
+ * without re-expanding by hand. */
352
552
  const [expanded, setExpanded] = (0, react.useState)(/* @__PURE__ */ new Set());
553
+ /** Top-level group open flags, beside the expanded set (which owns
554
+ * folder paths only — a group header is not a path node). Re-seeded on
555
+ * every open: past TREE_MIN_ROWS the remote group starts closed so the
556
+ * list leads with the local branches. The WORKTREE group starts open
557
+ * unconditionally — it is the blank session's quick-hop entry, always
558
+ * worth its few rows. */
559
+ const [localGroupOpen, setLocalGroupOpen] = (0, react.useState)(true);
560
+ const [remoteGroupOpen, setRemoteGroupOpen] = (0, react.useState)(true);
561
+ const [worktreeGroupOpen, setWorktreeGroupOpen] = (0, react.useState)(true);
353
562
  /** IDEA-style selection: clicked row (blue). Zero or one at a time. */
354
563
  const [selected, setSelected] = (0, react.useState)(null);
564
+ /** The create flyout: open flag plus the live draft. Opening the menu
565
+ * (or closing the flyout) resets both — see the open-reset effect. */
566
+ const [creating, setCreating] = (0, react.useState)(false);
567
+ const [draft, setDraft] = (0, react.useState)("");
568
+ /** The create flyout element and its placed position (see its place
569
+ * pass below; same measure-then-place posture as the confirm flyout). */
570
+ const createFlyRef = (0, react.useRef)(null);
571
+ const [createFlyPos, setCreateFlyPos] = (0, react.useState)(null);
355
572
  const confirmRef = (0, react.useRef)(confirm);
356
573
  confirmRef.current = confirm;
357
574
  const queryRef = (0, react.useRef)(query);
358
575
  queryRef.current = query;
359
576
  const selectedRef = (0, react.useRef)(selected);
360
577
  selectedRef.current = selected;
578
+ /** Fresh creating flag for the stale-safe document keydown listener. */
579
+ const creatingRef = (0, react.useRef)(creating);
580
+ creatingRef.current = creating;
581
+ /** Latest rows for the open-reset effect: the effect must NOT re-run when
582
+ * a mid-open refresh swaps the rows (that would reset folders the user
583
+ * has toggled), but the reset itself still needs the freshest list. */
584
+ const latestRows = (0, react.useRef)(rows);
585
+ latestRows.current = rows;
361
586
  /** Always-fresh pick for the stale-safe document keydown listener. */
362
587
  const pickRef = (0, react.useRef)(() => {});
363
588
  const confirmOpen = confirm !== null;
@@ -377,40 +602,50 @@ window.__ModuleLoader__.load({
377
602
  };
378
603
  /** Stage a pick: remember the row element (the flyout anchors beside
379
604
  * it), then hand the branch to the owner. All pick paths — search Enter,
380
- * keyboard Enter on a selected row — funnel through here. */
605
+ * keyboard Enter on a selected row — funnel through here. A remote row
606
+ * carries its DISPLAY name through selection and anchors; the owner
607
+ * always receives the real `<remote>/name` action name. */
381
608
  const pick = (el, name) => {
382
609
  if (el !== null) pendingRef.current = {
383
610
  name,
384
611
  el
385
612
  };
386
613
  setPendingName(name);
387
- onSelect(name);
614
+ onSelect(remoteNameMapRef.current.get(name) ?? name);
388
615
  };
389
616
  pickRef.current = pick;
390
- /** Prefix tree when the list is big enough to need one; null (flat list)
391
- * below TREE_MIN_ROWS. Built once per rows change. */
392
- const tree = (0, react.useMemo)(() => rows.length > TREE_MIN_ROWS ? buildTree(rows) : null, [rows]);
393
- /** Every folder path that renders a header — the expand/collapse-all
394
- * button's scope. */
395
- const folderPaths = (0, react.useMemo)(() => {
396
- const out = [];
397
- const walk = (nodes) => {
398
- for (const node of nodes) {
399
- if (node.children.length > 0) out.push(node.path);
400
- walk(node.children);
401
- }
402
- };
403
- if (tree !== null) walk(tree);
404
- return out;
405
- }, [tree]);
406
- const allExpanded = folderPaths.length > 0 && folderPaths.every((p) => expanded.has(p));
617
+ /** The two-group model of the rows (see groupRows) and each group's '/'
618
+ * prefix tree — always on; TREE_MIN_ROWS only sets the default opening
619
+ * depth (see the open-reset effect). */
620
+ const grouped = (0, react.useMemo)(() => groupRows(rows), [rows]);
621
+ const localTree = (0, react.useMemo)(() => buildTree(grouped.localRows), [grouped.localRows]);
622
+ const remoteTree = (0, react.useMemo)(() => buildTree(grouped.remoteDisplayRows), [grouped.remoteDisplayRows]);
623
+ /** Fresh display→action map for the stale-safe document keydown listener
624
+ * (its Enter path funnels through pick, which reads the ref). */
625
+ const remoteNameMapRef = (0, react.useRef)(grouped.remoteNameMap);
626
+ remoteNameMapRef.current = grouped.remoteNameMap;
627
+ /** Every folder key that renders a header — the expand/collapse-all
628
+ * button's scope (group-prefixed, see groupKey). */
629
+ const folderPaths = (0, react.useMemo)(() => [...collectFolderPaths(localTree).map((p) => groupKey("local", p)), ...collectFolderPaths(remoteTree).map((p) => groupKey("remote", p))], [localTree, remoteTree]);
630
+ /** Locked row names (dimmed, pick-answered-with-hint) — a Set for the
631
+ * click gate. MUST sit before the `!open` early return: a hook after it
632
+ * would change the hook count between a closed and an open menu
633
+ * (React #310, seen live as the whole dock unmounting on first open). */
634
+ const lockedRows = (0, react.useMemo)(() => new Set(rows.filter((r) => r.locked === true).map((r) => r.name)), [rows]);
635
+ const allExpanded = folderPaths.every((p) => expanded.has(p)) && localGroupOpen && remoteGroupOpen && (!canAdopt || worktreeGroupOpen);
407
636
  const toggleAll = () => {
408
- setExpanded(allExpanded ? /* @__PURE__ */ new Set() : new Set(folderPaths));
637
+ const next = !allExpanded;
638
+ setLocalGroupOpen(next);
639
+ setRemoteGroupOpen(next);
640
+ setWorktreeGroupOpen(next);
641
+ setExpanded(next ? new Set(folderPaths) : /* @__PURE__ */ new Set());
409
642
  };
410
643
  const locateCurrent = () => {
644
+ setLocalGroupOpen(true);
645
+ if (grouped.worktreeRows.some((row) => row.name === currentBranch)) setWorktreeGroupOpen(true);
411
646
  setExpanded((prev) => {
412
647
  const next = new Set(prev);
413
- for (const p of chainExpanded(currentBranch)) next.add(p);
648
+ for (const p of chainExpanded(currentBranch)) next.add(groupKey("local", p));
414
649
  return next;
415
650
  });
416
651
  requestAnimationFrame(() => {
@@ -421,7 +656,17 @@ window.__ModuleLoader__.load({
421
656
  if (!open) return;
422
657
  setQuery("");
423
658
  setSelected(null);
424
- setExpanded(chainExpanded(currentBranch));
659
+ setCreating(false);
660
+ setDraft("");
661
+ const currentRows = latestRows.current;
662
+ const current = groupRows(currentRows);
663
+ const localPaths = collectFolderPaths(buildTree(current.localRows)).map((p) => groupKey("local", p));
664
+ const remotePaths = collectFolderPaths(buildTree(current.remoteDisplayRows)).map((p) => groupKey("remote", p));
665
+ const many = currentRows.length > TREE_MIN_ROWS;
666
+ setLocalGroupOpen(true);
667
+ setRemoteGroupOpen(!many);
668
+ setWorktreeGroupOpen(true);
669
+ setExpanded(many ? new Set([...chainExpanded(currentBranch)].map((p) => groupKey("local", p))) : /* @__PURE__ */ new Set([...localPaths, ...remotePaths]));
425
670
  }, [open, currentBranch]);
426
671
  (0, react.useEffect)(() => {
427
672
  if (selected !== null && !rows.some((r) => r.name === selected)) setSelected(null);
@@ -523,6 +768,37 @@ window.__ModuleLoader__.load({
523
768
  window.removeEventListener("scroll", place, true);
524
769
  };
525
770
  }, [confirmOpen, pendingName]);
771
+ (0, react.useLayoutEffect)(() => {
772
+ if (!creating) {
773
+ setCreateFlyPos(null);
774
+ return;
775
+ }
776
+ const place = () => {
777
+ const fly = createFlyRef.current;
778
+ const card = cardRef.current;
779
+ if (fly === null || card === null) return;
780
+ const cr = card.getBoundingClientRect();
781
+ const vw = window.innerWidth;
782
+ const vh = window.innerHeight;
783
+ const left = cr.right + GAP;
784
+ const room = Math.min(FLY_MAX_WIDTH, Math.max(200, vw - MARGIN - left));
785
+ fly.style.maxWidth = `${room}px`;
786
+ const fw = fly.offsetWidth;
787
+ const fh = fly.offsetHeight;
788
+ const top = Math.min(Math.max(cr.top + cr.height / 2 - fh / 2, MARGIN), Math.max(MARGIN, vh - fh - MARGIN));
789
+ setCreateFlyPos({
790
+ left: Math.min(left, vw - MARGIN - fw),
791
+ top
792
+ });
793
+ };
794
+ place();
795
+ window.addEventListener("resize", place);
796
+ window.addEventListener("scroll", place, true);
797
+ return () => {
798
+ window.removeEventListener("resize", place);
799
+ window.removeEventListener("scroll", place, true);
800
+ };
801
+ }, [creating]);
526
802
  (0, react.useEffect)(() => {
527
803
  if (confirmOpen && pendingName !== null) {
528
804
  const raf = requestAnimationFrame(() => {
@@ -542,6 +818,7 @@ window.__ModuleLoader__.load({
542
818
  const onPointerDown = (event) => {
543
819
  if (cardRef.current?.contains(event.target) === true) return;
544
820
  if (flyRef.current?.contains(event.target) === true) return;
821
+ if (createFlyRef.current?.contains(event.target) === true) return;
545
822
  if (anchorRef.current?.contains(event.target) === true) return;
546
823
  confirmRef.current?.onCancel();
547
824
  onClose();
@@ -553,6 +830,11 @@ window.__ModuleLoader__.load({
553
830
  confirmRef.current.onCancel();
554
831
  return;
555
832
  }
833
+ if (creatingRef.current) {
834
+ setCreating(false);
835
+ setDraft("");
836
+ return;
837
+ }
556
838
  if (queryRef.current.trim() !== "") {
557
839
  setQuery("");
558
840
  return;
@@ -567,7 +849,8 @@ window.__ModuleLoader__.load({
567
849
  const card = cardRef.current;
568
850
  const active = document.activeElement;
569
851
  if (card === null || active === null || !card.contains(active)) return;
570
- if (active === card.querySelector("input")) return;
852
+ const inputs = card.querySelectorAll("input");
853
+ if (inputs.length > 0 && [...inputs].includes(active)) return;
571
854
  const leaves = [...card.querySelectorAll("button[role=\"menuitem\"][data-branch]")];
572
855
  if (key === "ArrowDown" || key === "ArrowUp") {
573
856
  event.preventDefault();
@@ -577,6 +860,7 @@ window.__ModuleLoader__.load({
577
860
  if (key === "ArrowDown") next = idx < 0 ? 0 : Math.min(leaves.length - 1, idx + 1);
578
861
  else next = idx <= 0 ? leaves.length - 1 : idx - 1;
579
862
  const target = leaves[next];
863
+ if (target === void 0) return;
580
864
  const name = target.dataset.branch ?? null;
581
865
  if (name !== null) setSelected(name);
582
866
  target.focus();
@@ -600,30 +884,88 @@ window.__ModuleLoader__.load({
600
884
  ]);
601
885
  if (!open || pos === null) return null;
602
886
  const needle = query.trim().toLowerCase();
603
- const visible = needle === "" ? rows : rows.filter((row) => row.name.toLowerCase().includes(needle));
604
- /** Enter in the search field: commit the first enabled visible row
605
- * (its rendered button is the anchor — found by its data-branch key; the
606
- * label text alone can't identify a row inside a tree). */
887
+ const visible = needle === "" ? rows : [
888
+ ...grouped.localRows,
889
+ ...grouped.worktreeRows,
890
+ ...grouped.remoteDisplayRows
891
+ ].filter((row) => row.name.toLowerCase().includes(needle));
892
+ /** Enter in the search field: commit the first visible row (its rendered
893
+ * button is the anchor — found by its data-branch key; the label text
894
+ * alone can't identify a row inside a tree). */
607
895
  const commitFirst = () => {
608
- const first = visible.find((row) => !row.disabled);
896
+ const first = visible[0];
609
897
  if (first === void 0) return;
610
898
  const card = cardRef.current;
611
899
  if (card === null) return;
612
900
  const el = card.querySelector(`button[data-branch="${CSS.escape(first.name)}"]`);
613
901
  pick(el, first.name);
614
902
  };
615
- /** Row class composition: base + HEAD tint + selection (selection wins). */
616
- const rowClass = (name) => {
617
- let cls = BranchChip_module_default.menuRow;
903
+ /** New-branch draft validation: git ref-name rules first, then a duplicate
904
+ * check against every EXISTING local branch — local rows and worktree
905
+ * rows alike (a worktree row IS a checked-out branch, just filed under
906
+ * its own group). A remote display name is not a claim on a new local
907
+ * branch's name (its twin could not even coexist with one; the host
908
+ * hides such remote rows). */
909
+ const createIssue = branchNameIssue(draft);
910
+ const existsLocally = (name) => grouped.localRows.some((row) => row.name === name) || grouped.worktreeRows.some((row) => row.name === name);
911
+ const createDuplicate = createIssue === null && existsLocally(draft);
912
+ const createValid = createIssue === null && !createDuplicate;
913
+ /** Error line under the input, ONLY while the draft is unacceptable with
914
+ * a non-empty reason (the ask line above already names the cut point, and
915
+ * an untouched input needs no error) — the Create button disables in
916
+ * lockstep. */
917
+ const createHint = createDuplicate ? t("menuNewBranchExists") : t("menuNewBranchBad");
918
+ const showCreateHint = createIssue !== null && createIssue !== "empty" || createDuplicate;
919
+ /** Fire the create in one stroke — the flyout's whole point. Invalid
920
+ * drafts and a running create are no-ops (the Create button disables in
921
+ * lockstep); the owner closes the menu on success, toasts on failure and
922
+ * leaves the flyout open for a renamed retry. */
923
+ const commitCreate = () => {
924
+ if (!createValid || busy) return;
925
+ onCreate(draft);
926
+ };
927
+ /** Row class composition: base + HEAD tint + selection (selection wins)
928
+ * + the locked dim. (`css` is an index-signature record, so noUncheckedIndexedAccess
929
+ * types every class as possibly absent — the base falls back to ''.) */
930
+ const rowClass = (row, name) => {
931
+ let cls = BranchChip_module_default.menuRow ?? "";
618
932
  if (name === currentBranch) cls += ` ${BranchChip_module_default.menuRowSelected}`;
619
933
  if (name === selected) cls += ` ${BranchChip_module_default.menuRowPicked}`;
934
+ if (row?.locked === true) cls += ` ${BranchChip_module_default.menuRowLocked}`;
620
935
  return cls;
621
936
  };
937
+ /** Locked rows keep the click path ALIVE (the owner answers picks with
938
+ * the main-checkout toast) but stay unselected — a dimmed row wearing
939
+ * the blue selection would read as "chosen yet unusable". */
940
+ const isLocked = (name) => lockedRows.has(name);
941
+ /** The upstream divergence arrows of a local row (IDEA's ↑N/↓N) ahead of
942
+ * the trailing check: plain text marks in the secondary tone — no base
943
+ * icon pairs a direction with a count. Absent without an upstream or
944
+ * when in sync. */
945
+ const renderArrows = (row) => {
946
+ if (row === null) return null;
947
+ const marks = [];
948
+ if ((row.ahead ?? 0) > 0) marks.push(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
949
+ className: BranchChip_module_default.menuRowArrow,
950
+ title: t("aheadTitle", { n: row.ahead }),
951
+ children: ["↑", row.ahead]
952
+ }, "ahead"));
953
+ if ((row.behind ?? 0) > 0) marks.push(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
954
+ className: BranchChip_module_default.menuRowArrow,
955
+ title: t("behindTitle", { n: row.behind }),
956
+ children: ["↓", row.behind]
957
+ }, "behind"));
958
+ return marks;
959
+ };
622
960
  /** A row's click behavior: with the confirm flyout open, clicking a row
623
961
  * re-picks it (the old one-click flow — the flyout re-anchors); without
624
962
  * one it just selects (IDEA model — double-click or Enter opens the
625
- * confirm flyout for the selected row). */
963
+ * confirm flyout for the selected row). Locked rows do neither: dimmed
964
+ * rows are not selectable, the double-click is the hint's stage. `el` is
965
+ * nullable like {@link pick}'s anchor: a row whose button is already
966
+ * unmounted still selects/picks, it just re-anchors nothing. */
626
967
  const rowClick = (el, name) => {
968
+ if (isLocked(name)) return;
627
969
  if (confirmOpen) pick(el, name);
628
970
  else setSelected(name);
629
971
  };
@@ -658,12 +1000,75 @@ window.__ModuleLoader__.load({
658
1000
  }
659
1001
  return false;
660
1002
  };
661
- /** One tree group-header row: its own segment (a compressed chain's
1003
+ /** One top-level group header (local/remote branches): the folder-header
1004
+ * posture with its own open flag — toggling flips the flag, never a key
1005
+ * in the expanded path set. `menuGroupTop` lifts the tone above the
1006
+ * folder headers (see the CSS note). In the search view (onToggle
1007
+ * absent) it renders inert: the matched subtrees below are force-open
1008
+ * anyway. */
1009
+ const renderGroupHeader = (label, count, open, onToggle) => {
1010
+ const cls = `${BranchChip_module_default.menuGroup} ${BranchChip_module_default.menuGroupTop}`;
1011
+ return onToggle === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1012
+ className: cls,
1013
+ role: "presentation",
1014
+ style: { paddingLeft: 8 },
1015
+ children: [
1016
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronDownOutline14, {
1017
+ size: 12,
1018
+ className: BranchChip_module_default.menuGroupChevron
1019
+ }),
1020
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1021
+ className: BranchChip_module_default.menuGroupLabel,
1022
+ children: label
1023
+ }),
1024
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1025
+ className: BranchChip_module_default.menuGroupCount,
1026
+ children: [
1027
+ "(",
1028
+ count,
1029
+ ")"
1030
+ ]
1031
+ })
1032
+ ]
1033
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1034
+ type: "button",
1035
+ className: cls,
1036
+ "aria-expanded": open,
1037
+ onClick: () => {
1038
+ if (guardActive()) return;
1039
+ onToggle();
1040
+ armShiftGuard();
1041
+ },
1042
+ children: [
1043
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronRightOutline14, {
1044
+ size: 12,
1045
+ className: open ? `${BranchChip_module_default.menuGroupChevron} ${BranchChip_module_default.menuGroupChevronOpen}` : BranchChip_module_default.menuGroupChevron
1046
+ }),
1047
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1048
+ className: BranchChip_module_default.menuGroupLabel,
1049
+ children: label
1050
+ }),
1051
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1052
+ className: BranchChip_module_default.menuGroupCount,
1053
+ children: [
1054
+ "(",
1055
+ count,
1056
+ ")"
1057
+ ]
1058
+ })
1059
+ ]
1060
+ });
1061
+ };
1062
+ /**
1063
+ * One tree group-header row: its own segment (a compressed chain's
662
1064
  * walked segments join the label), a count badge, and a chevron that
663
1065
  * turns for expansion. Clicking toggles. One color throughout — the
664
- * folder path is not color-distinguished from the name. */
665
- const renderHeader = (node, label, depth) => {
666
- const isOpen = expanded.has(node.path);
1066
+ * folder path is not color-distinguished from the name. `prefix` scopes
1067
+ * the expanded-key space to the owning group (see groupKey) and keeps
1068
+ * React keys unique across the two trees.
1069
+ */
1070
+ const renderHeader = (node, label, depth, prefix) => {
1071
+ const isOpen = expanded.has(`${prefix}${node.path}`);
667
1072
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
668
1073
  type: "button",
669
1074
  className: BranchChip_module_default.menuGroup,
@@ -672,7 +1077,7 @@ window.__ModuleLoader__.load({
672
1077
  "aria-expanded": isOpen,
673
1078
  onClick: () => {
674
1079
  if (guardActive()) return;
675
- toggle(node.path);
1080
+ toggle(`${prefix}${node.path}`);
676
1081
  armShiftGuard();
677
1082
  },
678
1083
  children: [
@@ -693,19 +1098,24 @@ window.__ModuleLoader__.load({
693
1098
  ]
694
1099
  })
695
1100
  ]
696
- }, `group:${node.path}`);
1101
+ }, `${prefix}group:${node.path}`);
697
1102
  };
698
1103
  /** One tree leaf row: under an expanded folder it shows only its own
699
1104
  * segment (indentation carries the hierarchy — no repeated full path);
700
1105
  * a compressed linear chain keeps its walked segments in the label so
701
- * the context survives without a pointless one-entry folder. */
702
- const renderLeaf = (node, label, depth) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1106
+ * the context survives without a pointless one-entry folder. The
1107
+ * data-branch key stays the group-local DISPLAY name — unique across
1108
+ * all groups (a remote display name can never equal a local row; a
1109
+ * worktree row's branch has left the local group) — which is what the
1110
+ * buttonOf/commitFirst/center lookups rely on. */
1111
+ const renderLeaf = (node, label, depth, prefix) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
703
1112
  type: "button",
704
1113
  role: "menuitem",
705
1114
  "data-branch": node.path,
706
- className: rowClass(node.path),
707
- disabled: node.leaf?.disabled ?? false,
708
- style: { paddingLeft: 8 + depth * 12 },
1115
+ "data-kind": node.leaf?.kind,
1116
+ className: rowClass(node.leaf ?? null, node.path),
1117
+ title: node.leaf?.locked === true ? t("mainRepoOnly") : void 0,
1118
+ style: { paddingLeft: 8 + depth * 12 + LEAF_CHEVRON_SLOT },
709
1119
  onClick: () => {
710
1120
  if (guardActive()) return;
711
1121
  rowClick(buttonOf(node.path), node.path);
@@ -720,35 +1130,76 @@ window.__ModuleLoader__.load({
720
1130
  onMouseLeave: (event) => {
721
1131
  clearTooltip(event.currentTarget);
722
1132
  },
1133
+ children: [
1134
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1135
+ className: BranchChip_module_default.menuRowLabel,
1136
+ children: label
1137
+ }),
1138
+ renderArrows(node.leaf),
1139
+ node.path === currentBranch && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconCheckOutline16, { size: 14 })
1140
+ ]
1141
+ }, `${prefix}${node.path}`);
1142
+ /** One flat worktree row: a direct hop target, one per linked worktree
1143
+ * — no tree (worktree names rarely fork, and the group is a launcher,
1144
+ * not a taxonomy), no confirm (the double-click IS the hop; the owner
1145
+ * picks it up through onSelect). The native title carries the worktree
1146
+ * DIRECTORY — the fact a branch row cannot show. The row the session
1147
+ * currently lives in keeps the trailing check + HEAD tint: it is the
1148
+ * "you are here" mark the local group no longer holds (its branch was
1149
+ * filed into THIS group). */
1150
+ const renderFlatLeaf = (row, prefix) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1151
+ type: "button",
1152
+ role: "menuitem",
1153
+ "data-branch": row.name,
1154
+ "data-kind": row.kind,
1155
+ className: rowClass(row, row.name),
1156
+ title: row.locked === true ? t("mainRepoOnly") : row.path,
1157
+ style: { paddingLeft: 38 },
1158
+ onClick: () => {
1159
+ if (guardActive()) return;
1160
+ rowClick(buttonOf(row.name), row.name);
1161
+ },
1162
+ onDoubleClick: (event) => {
1163
+ if (guardActive()) return;
1164
+ pick(event.currentTarget, row.name);
1165
+ },
1166
+ onMouseEnter: (event) => {
1167
+ gateTooltip(event.currentTarget, row.name);
1168
+ },
1169
+ onMouseLeave: (event) => {
1170
+ clearTooltip(event.currentTarget);
1171
+ },
723
1172
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
724
1173
  className: BranchChip_module_default.menuRowLabel,
725
- children: label
726
- }), node.path === currentBranch && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconCheckOutline16, { size: 14 })]
727
- }, node.path);
1174
+ children: row.name
1175
+ }), row.name === currentBranch && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconCheckOutline16, { size: 14 })]
1176
+ }, `${prefix}${row.name}`);
728
1177
  /** Recursive tree renderer. Linear chains — nodes that are neither a
729
1178
  * branch nor a real fork — compress into the next row's label, so
730
1179
  * `feature/优化` stays a single flat row instead of a pointless one-entry
731
1180
  * folder, while a real fork (`a/deep/tree` holding leaf1+leaf2) gets a
732
1181
  * header whose children show only their own segments. */
733
- const renderTree = (nodes, depth) => {
1182
+ const renderTree = (nodes, depth, prefix) => {
734
1183
  const out = [];
735
1184
  for (const node of nodes) {
736
1185
  let cur = node;
737
1186
  const parts = [];
738
1187
  while (cur.leaf === null && cur.children.length === 1) {
1188
+ const next = cur.children[0];
1189
+ if (next === void 0) break;
739
1190
  parts.push(cur.segment);
740
- cur = cur.children[0];
1191
+ cur = next;
741
1192
  }
742
1193
  const label = parts.length === 0 ? cur.segment : `${parts.join("/")}/${cur.segment}`;
743
1194
  if (cur.leaf !== null) {
744
- out.push(renderLeaf(cur, label, depth));
1195
+ out.push(renderLeaf(cur, label, depth, prefix));
745
1196
  if (cur.children.length > 0) {
746
- out.push(renderHeader(cur, label, depth));
747
- if (expanded.has(cur.path)) out.push(...renderTree(cur.children, depth + 1));
1197
+ out.push(renderHeader(cur, label, depth, prefix));
1198
+ if (expanded.has(`${prefix}${cur.path}`)) out.push(...renderTree(cur.children, depth + 1, prefix));
748
1199
  }
749
1200
  } else {
750
- out.push(renderHeader(cur, label, depth));
751
- if (expanded.has(cur.path)) out.push(...renderTree(cur.children, depth + 1));
1201
+ out.push(renderHeader(cur, label, depth, prefix));
1202
+ if (expanded.has(`${prefix}${cur.path}`)) out.push(...renderTree(cur.children, depth + 1, prefix));
752
1203
  }
753
1204
  }
754
1205
  return out;
@@ -757,7 +1208,11 @@ window.__ModuleLoader__.load({
757
1208
  * filter keeps the path), hide non-matching siblings, force every kept
758
1209
  * folder open, and highlight the hit substring. No chain compression —
759
1210
  * the full ancestor path is exactly the context the search is for. */
760
- const renderSearch = (nodes, depth) => {
1211
+ /** Needle-matching leaf count of a tree: the search-view group header
1212
+ * must count the MATCHES under it, not the whole group — a full count
1213
+ * above two filtered rows reads as a lie. */
1214
+ const searchLeafCount = (nodes) => nodes.reduce((sum, node) => sum + (node.leaf !== null && node.leaf.name.toLowerCase().includes(needle) ? 1 : 0) + searchLeafCount(node.children), 0);
1215
+ const renderSearch = (nodes, depth, prefix) => {
761
1216
  const out = [];
762
1217
  for (const node of nodes) {
763
1218
  const leafHit = node.leaf !== null && node.leaf.name.toLowerCase().includes(needle);
@@ -766,9 +1221,10 @@ window.__ModuleLoader__.load({
766
1221
  type: "button",
767
1222
  role: "menuitem",
768
1223
  "data-branch": node.path,
769
- className: rowClass(node.path),
770
- disabled: node.leaf?.disabled ?? false,
771
- style: { paddingLeft: 8 + depth * 12 },
1224
+ "data-kind": node.leaf?.kind,
1225
+ className: rowClass(node.leaf ?? null, node.path),
1226
+ title: node.leaf?.locked === true ? t("mainRepoOnly") : void 0,
1227
+ style: { paddingLeft: 8 + depth * 12 + LEAF_CHEVRON_SLOT },
772
1228
  onClick: () => {
773
1229
  if (guardActive()) return;
774
1230
  rowClick(buttonOf(node.path), node.path);
@@ -783,11 +1239,15 @@ window.__ModuleLoader__.load({
783
1239
  onMouseLeave: (event) => {
784
1240
  clearTooltip(event.currentTarget);
785
1241
  },
786
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
787
- className: BranchChip_module_default.menuRowLabel,
788
- children: renderLabel(node.segment)
789
- }), node.path === currentBranch && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconCheckOutline16, { size: 14 })]
790
- }, node.path));
1242
+ children: [
1243
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1244
+ className: BranchChip_module_default.menuRowLabel,
1245
+ children: renderLabel(node.segment)
1246
+ }),
1247
+ renderArrows(node.leaf),
1248
+ node.path === currentBranch && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconCheckOutline16, { size: 14 })
1249
+ ]
1250
+ }, `${prefix}${node.path}`));
791
1251
  if (childHit) {
792
1252
  out.push(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
793
1253
  role: "presentation",
@@ -812,8 +1272,8 @@ window.__ModuleLoader__.load({
812
1272
  ]
813
1273
  })
814
1274
  ]
815
- }, `search:${node.path}`));
816
- out.push(...renderSearch(node.children, depth + 1));
1275
+ }, `${prefix}search:${node.path}`));
1276
+ out.push(...renderSearch(node.children, depth + 1, prefix));
817
1277
  }
818
1278
  }
819
1279
  return out;
@@ -821,140 +1281,233 @@ window.__ModuleLoader__.load({
821
1281
  /** The rendered button for a branch name (flyout anchor on click-select
822
1282
  * paths, where the handler only has the name at hand). */
823
1283
  const buttonOf = (name) => cardRef.current?.querySelector(`button[data-branch="${CSS.escape(name)}"]`) ?? null;
824
- /** One flat row (small repos, and search results there). */
825
- const renderRow = (row, highlight) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
826
- type: "button",
827
- role: "menuitem",
828
- "data-branch": row.name,
829
- className: rowClass(row.name),
830
- disabled: row.disabled,
831
- onClick: () => {
832
- if (guardActive()) return;
833
- rowClick(buttonOf(row.name), row.name);
834
- },
835
- onDoubleClick: (event) => {
836
- if (guardActive()) return;
837
- pick(event.currentTarget, row.name);
838
- },
839
- onMouseEnter: (event) => {
840
- gateTooltip(event.currentTarget, row.name);
841
- },
842
- onMouseLeave: (event) => {
843
- clearTooltip(event.currentTarget);
844
- },
845
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
846
- className: BranchChip_module_default.menuRowLabel,
847
- children: highlight ? renderLabel(row.name) : row.name
848
- }), row.name === currentBranch && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconCheckOutline16, { size: 14 })]
849
- }, row.name);
850
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [(0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
851
- ref: cardRef,
852
- className: BranchChip_module_default.menuCard,
853
- style: {
854
- left: pos.left,
855
- bottom: pos.bottom
856
- },
857
- role: "menu",
858
- "aria-label": t("menuLocalBranches"),
859
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
860
- className: BranchChip_module_default.menuToolbar,
861
- role: "toolbar",
862
- "aria-label": t("menuLocalBranches"),
863
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
864
- type: "button",
865
- className: BranchChip_module_default.menuToolButton,
866
- title: t("menuLocate"),
867
- "aria-label": t("menuLocate"),
868
- onClick: locateCurrent,
869
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconGoalOutline16, { size: 16 })
870
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
871
- type: "button",
872
- className: BranchChip_module_default.menuToolButton,
873
- title: allExpanded ? t("menuCollapseAll") : t("menuExpandAll"),
874
- "aria-label": allExpanded ? t("menuCollapseAll") : t("menuExpandAll"),
875
- disabled: tree === null || folderPaths.length === 0,
876
- onClick: toggleAll,
877
- children: allExpanded ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronUpOutline14, { size: 14 }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronDownOutline14, { size: 14 })
1284
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
1285
+ (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1286
+ ref: cardRef,
1287
+ className: BranchChip_module_default.menuCard,
1288
+ style: {
1289
+ left: pos.left,
1290
+ bottom: pos.bottom
1291
+ },
1292
+ role: "menu",
1293
+ "aria-label": t("menuBranches"),
1294
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1295
+ className: BranchChip_module_default.menuToolbar,
1296
+ role: "toolbar",
1297
+ "aria-label": t("menuBranches"),
1298
+ children: [
1299
+ canCreate && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1300
+ type: "button",
1301
+ className: creating ? `${BranchChip_module_default.menuToolButton} ${BranchChip_module_default.menuToolButtonOn}` : BranchChip_module_default.menuToolButton,
1302
+ title: t("menuNewBranch"),
1303
+ "aria-label": t("menuNewBranch"),
1304
+ "aria-pressed": creating,
1305
+ onClick: () => {
1306
+ confirmRef.current?.onCancel();
1307
+ const next = !creating;
1308
+ setCreating(next);
1309
+ if (!next) setDraft("");
1310
+ },
1311
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconPlusOutline16, { size: 16 })
1312
+ }),
1313
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1314
+ type: "button",
1315
+ className: BranchChip_module_default.menuToolButton,
1316
+ title: t("menuLocate"),
1317
+ "aria-label": t("menuLocate"),
1318
+ onClick: locateCurrent,
1319
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconGoalOutline16, { size: 16 })
1320
+ }),
1321
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1322
+ type: "button",
1323
+ className: updateBusy ? `${BranchChip_module_default.menuToolButton} ${BranchChip_module_default.menuToolButtonRunning}` : BranchChip_module_default.menuToolButton,
1324
+ title: t("menuUpdate"),
1325
+ "aria-label": t("menuUpdate"),
1326
+ disabled: busy || fetchBusy,
1327
+ onClick: () => {
1328
+ confirmRef.current?.onCancel();
1329
+ onUpdate();
1330
+ },
1331
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FetchGlyph, { dashed: false })
1332
+ }),
1333
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1334
+ type: "button",
1335
+ className: fetchBusy ? `${BranchChip_module_default.menuToolButton} ${BranchChip_module_default.menuToolButtonRunning}` : BranchChip_module_default.menuToolButton,
1336
+ title: t("menuFetch"),
1337
+ "aria-label": t("menuFetch"),
1338
+ disabled: busy || updateBusy,
1339
+ onClick: () => {
1340
+ confirmRef.current?.onCancel();
1341
+ onFetch();
1342
+ },
1343
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FetchGlyph, {})
1344
+ }),
1345
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1346
+ type: "button",
1347
+ className: BranchChip_module_default.menuToolButton,
1348
+ title: allExpanded ? t("menuCollapseAll") : t("menuExpandAll"),
1349
+ "aria-label": allExpanded ? t("menuCollapseAll") : t("menuExpandAll"),
1350
+ disabled: rows.length === 0,
1351
+ onClick: toggleAll,
1352
+ children: allExpanded ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronUpOutline14, { size: 14 }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronDownOutline14, { size: 14 })
1353
+ })
1354
+ ]
1355
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1356
+ className: BranchChip_module_default.menuMain,
1357
+ children: [
1358
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1359
+ className: BranchChip_module_default.menuHeading,
1360
+ children: t("menuBranches")
1361
+ }),
1362
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1363
+ className: BranchChip_module_default.menuRows,
1364
+ role: "presentation",
1365
+ ref: holdRowsCenter,
1366
+ children: [needle === "" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
1367
+ grouped.localRows.length > 0 && renderGroupHeader(t("menuLocalBranches"), grouped.localRows.length, localGroupOpen, () => setLocalGroupOpen((value) => !value)),
1368
+ localGroupOpen && renderTree(localTree, 1, "local:"),
1369
+ canAdopt && grouped.worktreeRows.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [renderGroupHeader(t("menuWorktrees"), grouped.worktreeRows.length, worktreeGroupOpen, () => setWorktreeGroupOpen((value) => !value)), worktreeGroupOpen && grouped.worktreeRows.map((row) => renderFlatLeaf(row, "worktree:"))] }),
1370
+ grouped.remoteDisplayRows.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [renderGroupHeader(t("menuRemoteBranches"), grouped.remoteDisplayRows.length, remoteGroupOpen, () => setRemoteGroupOpen((value) => !value)), remoteGroupOpen && renderTree(remoteTree, 1, "remote:")] })
1371
+ ] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
1372
+ grouped.localRows.some((row) => row.name.toLowerCase().includes(needle)) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [renderGroupHeader(t("menuLocalBranches"), searchLeafCount(localTree), true), renderSearch(localTree, 1, "local:")] }),
1373
+ canAdopt && grouped.worktreeRows.some((row) => row.name.toLowerCase().includes(needle)) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [renderGroupHeader(t("menuWorktrees"), grouped.worktreeRows.filter((row) => row.name.toLowerCase().includes(needle)).length, true), grouped.worktreeRows.filter((row) => row.name.toLowerCase().includes(needle)).map((row) => renderFlatLeaf(row, "worktree:"))] }),
1374
+ grouped.remoteDisplayRows.some((row) => row.name.toLowerCase().includes(needle)) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [renderGroupHeader(t("menuRemoteBranches"), searchLeafCount(remoteTree), true), renderSearch(remoteTree, 1, "remote:")] })
1375
+ ] }), visible.length === 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1376
+ className: BranchChip_module_default.menuEmpty,
1377
+ children: rows.length === 0 ? t("menuNoBranches") : t("menuNoMatches")
1378
+ })]
1379
+ }),
1380
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1381
+ className: BranchChip_module_default.menuSearchWrap,
1382
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1383
+ ref: holdSearchFocus,
1384
+ className: BranchChip_module_default.menuSearch,
1385
+ type: "text",
1386
+ value: query,
1387
+ placeholder: t("menuSearchPlaceholder"),
1388
+ "aria-label": t("menuSearchPlaceholder"),
1389
+ spellCheck: false,
1390
+ onChange: (event) => {
1391
+ setQuery(event.target.value);
1392
+ },
1393
+ onKeyDown: (event) => {
1394
+ if (event.key === "Enter") {
1395
+ event.preventDefault();
1396
+ commitFirst();
1397
+ }
1398
+ }
1399
+ })
1400
+ })
1401
+ ]
878
1402
  })]
879
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
880
- className: BranchChip_module_default.menuMain,
1403
+ }), document.body),
1404
+ confirm !== null && (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1405
+ ref: flyRef,
1406
+ className: BranchChip_module_default.popCard,
1407
+ style: flyPos ?? FLY_MEASURE,
1408
+ role: "dialog",
1409
+ "aria-label": confirm.ask,
881
1410
  children: [
882
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
883
- className: BranchChip_module_default.menuHeading,
884
- children: t("menuLocalBranches")
1411
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1412
+ className: BranchChip_module_default.popAsk,
1413
+ children: confirm.ask
1414
+ }),
1415
+ confirm.subject !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1416
+ className: BranchChip_module_default.popSubject,
1417
+ children: confirm.subject
885
1418
  }),
886
1419
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
887
- className: BranchChip_module_default.menuRows,
888
- role: "presentation",
889
- ref: holdRowsCenter,
890
- children: [tree === null ? (needle === "" ? rows : visible).map((row) => renderRow(row, needle !== "")) : needle === "" ? renderTree(tree, 0) : renderSearch(tree, 0), visible.length === 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
891
- className: BranchChip_module_default.menuEmpty,
892
- children: t("menuNoMatches")
1420
+ className: BranchChip_module_default.popActions,
1421
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1422
+ type: "button",
1423
+ disabled: confirm.busy,
1424
+ onClick: confirm.onCancel,
1425
+ children: confirm.cancelLabel
1426
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1427
+ ref: flyConfirmRef,
1428
+ type: "button",
1429
+ disabled: confirm.busy,
1430
+ onClick: confirm.onConfirm,
1431
+ children: confirm.confirmLabel
893
1432
  })]
1433
+ })
1434
+ ]
1435
+ }), document.body),
1436
+ creating && (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1437
+ ref: createFlyRef,
1438
+ className: BranchChip_module_default.popCard,
1439
+ style: createFlyPos ?? FLY_MEASURE,
1440
+ role: "dialog",
1441
+ "aria-label": t("createBranchTitle", { branch: currentBranch }),
1442
+ children: [
1443
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1444
+ className: BranchChip_module_default.popAsk,
1445
+ children: t("createBranchTitle", { branch: currentBranch })
894
1446
  }),
895
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
896
- className: BranchChip_module_default.menuSearchWrap,
897
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
898
- ref: holdSearchFocus,
899
- className: BranchChip_module_default.menuSearch,
900
- type: "text",
901
- value: query,
902
- placeholder: t("menuSearchPlaceholder"),
903
- "aria-label": t("menuSearchPlaceholder"),
904
- spellCheck: false,
905
- onChange: (event) => {
906
- setQuery(event.target.value);
907
- },
908
- onKeyDown: (event) => {
909
- if (event.key === "Enter") {
910
- event.preventDefault();
911
- commitFirst();
912
- }
1447
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1448
+ ref: holdCreateFocus,
1449
+ className: BranchChip_module_default.menuCreate,
1450
+ type: "text",
1451
+ value: draft,
1452
+ placeholder: t("menuNewBranchPlaceholder"),
1453
+ "aria-label": t("menuNewBranchPlaceholder"),
1454
+ "aria-invalid": createIssue !== null && createIssue !== "empty",
1455
+ spellCheck: false,
1456
+ disabled: busy,
1457
+ onChange: (event) => {
1458
+ setDraft(event.target.value);
1459
+ },
1460
+ onKeyDown: (event) => {
1461
+ if (event.key === "Enter") {
1462
+ event.preventDefault();
1463
+ commitCreate();
913
1464
  }
914
- })
1465
+ }
1466
+ }),
1467
+ showCreateHint && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1468
+ className: BranchChip_module_default.menuCreateHintBad,
1469
+ role: "status",
1470
+ children: createHint
1471
+ }),
1472
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1473
+ className: BranchChip_module_default.popActions,
1474
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1475
+ type: "button",
1476
+ disabled: busy,
1477
+ onClick: () => {
1478
+ setCreating(false);
1479
+ setDraft("");
1480
+ },
1481
+ children: t("actionCancel")
1482
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1483
+ type: "button",
1484
+ disabled: !createValid || busy,
1485
+ onClick: commitCreate,
1486
+ children: busy ? t("createBranchBusy") : t("actionConfirm")
1487
+ })]
915
1488
  })
916
1489
  ]
917
- })]
918
- }), document.body), confirm !== null && (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
919
- ref: flyRef,
920
- className: BranchChip_module_default.popCard,
921
- style: flyPos ?? FLY_MEASURE,
922
- role: "dialog",
923
- "aria-label": confirm.ask,
924
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
925
- className: BranchChip_module_default.popAsk,
926
- children: confirm.ask
927
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
928
- className: BranchChip_module_default.popActions,
929
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
930
- type: "button",
931
- disabled: confirm.busy,
932
- onClick: confirm.onCancel,
933
- children: confirm.cancelLabel
934
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
935
- ref: flyConfirmRef,
936
- type: "button",
937
- disabled: confirm.busy,
938
- onClick: confirm.onConfirm,
939
- children: confirm.confirmLabel
940
- })]
941
- })]
942
- }), document.body)] });
1490
+ }), document.body)
1491
+ ] });
943
1492
  }
944
1493
  //#endregion
945
1494
  //#region src/client/BranchChip.tsx
946
1495
  /**
947
1496
  * BranchChipDock: the composer tool-row entry (conversation.input.left, right
948
1497
  * of the mode chips) for sessions inside a git repository. Blank sessions
949
- * get the full segmented control — branch picker plus the worktree
950
- * isolation toggle — because that is the moment to choose the environment
951
- * for the conversation. Once the session starts, the worktree toggle is
952
- * withdrawn: a started session may still switch branches in place (a
953
- * switch inside a linked worktree checks out within that worktree —
954
- * probeRepo roots at the session directory's toplevel, never the main
955
- * checkout), but its directory is fixed. Non-git directories and load
956
- * failures render nothing. The confirm dialogs and the error toast live
957
- * here too.
1498
+ * OF THE MAIN checkout get the full segmented control — branch picker plus
1499
+ * the worktree isolation toggle — because that is the moment to choose the
1500
+ * environment for the conversation, and starting a worktree is a main-repo
1501
+ * decision. Once the session starts, the worktree toggle is withdrawn (its
1502
+ * directory is fixed). A session inside a LINKED worktree scopes the whole
1503
+ * entry down: blank, the menu lists every branch for READING but every
1504
+ * pick but the current branch answers with the main-checkout hint (and
1505
+ * neither the toggle nor the in-place new-branch tool exists there);
1506
+ * started, the menu shows nothing but the session's own branch — fetch and
1507
+ * update-current stay, since neither moves the checkout (probeRepo still
1508
+ * roots at the session directory's toplevel, never the main checkout).
1509
+ * Non-git directories and load failures render nothing. The confirm
1510
+ * dialogs and the error toast live here too.
958
1511
  *
959
1512
  * Checking the worktree toggle pops the cutout confirm dialog right away:
960
1513
  * confirming it cuts a NEW branch (`<current>-wt`, suffixes past taken
@@ -966,6 +1519,25 @@ window.__ModuleLoader__.load({
966
1519
  * current branch stages the same cutout confirm. Dismissing the dialog and
967
1520
  * sending the message anyway means the user knowingly stays in the current
968
1521
  * directory — no separate notice fires on send.
1522
+ *
1523
+ * In-place branch creation (the menu toolbar's plus, worktree mode off)
1524
+ * opens the create flyout right of the branch card: type the name, press
1525
+ * Create — the new branch is cut from the session directory's current
1526
+ * checkout and checked out there in one stroke, the worktree-less sibling
1527
+ * of the cutout flow. A failure toasts and leaves the flyout open.
1528
+ *
1529
+ * Remote branches join the picker under their own menu group: picking one
1530
+ * stages the remote-twin confirm — the switch creates the local tracking
1531
+ * branch in place (git's dwim), the worktree pick creates the twin inside
1532
+ * its fresh worktree. Both rides go through the existing /switch and
1533
+ * /worktree routes, which already resolve `<remote>/name` display names.
1534
+ *
1535
+ * Branches held by linked worktrees get their own 「工作树」 group (blank
1536
+ * sessions only): they have left the local group — git refuses to check
1537
+ * them out twice, so a local-group row would be a dead end — and a
1538
+ * double-click hops the session straight into that worktree directory
1539
+ * (adoptWorktree; no git action, no confirm). A started session's
1540
+ * directory is fixed, so the group only exists while blank.
969
1541
  */
970
1542
  /**
971
1543
  * Heavier check glyph for the worktree toggle. The base's IconCheckOutline16
@@ -989,6 +1561,17 @@ window.__ModuleLoader__.load({
989
1561
  })
990
1562
  });
991
1563
  }
1564
+ /** First free `<base>-wt` name against the local branch list — the prefilled
1565
+ * draft of the cutout dialog (same shape as the host's suffix walk, minus
1566
+ * the storage-folder probe the client cannot see). */
1567
+ function firstFreeCutoutName(base, taken) {
1568
+ const stem = `${base}-wt`;
1569
+ if (!taken.includes(stem)) return stem;
1570
+ for (let i = 2;; i += 1) {
1571
+ const candidate = `${stem}${i}`;
1572
+ if (!taken.includes(candidate)) return candidate;
1573
+ }
1574
+ }
992
1575
  /**
993
1576
  * Read the repository status for a directory; refetch on demand.
994
1577
  * @param cwd - absolute session directory.
@@ -1037,30 +1620,56 @@ window.__ModuleLoader__.load({
1037
1620
  return branch.length <= BRANCH_DISPLAY_MAX ? branch : `${branch.slice(0, 24)}…`;
1038
1621
  }
1039
1622
  /**
1040
- * Build the branch rows for the picker: local branches only (remote
1041
- * branches are not offered). A branch already checked out by a live
1042
- * worktree is disabled while the worktree toggle is off (git refuses such
1043
- * a switch); with the toggle on it is the reuse path, so it stays
1044
- * selectable. The selected row's trailing check is BranchMenu's own
1045
- * affordance — no leading icon.
1623
+ * Build the branch rows for the picker in three kinds: LOCAL branches not
1624
+ * held by a linked worktree, REMOTE branches, and one WORKTREE row per
1625
+ * linked worktree. A branch held by a worktree LEAVES the local group —
1626
+ * git refuses to check it out twice, so the row would be a dead end; the
1627
+ * worktree group is the way INTO it instead (a direct session hop, see
1628
+ * the owner's onAdoptWorktree). The main worktree and detached worktrees
1629
+ * don't come along: the main checkout is home, not a hop target, and a
1630
+ * detached worktree has no branch name to offer.
1631
+ *
1632
+ * Inside a linked-worktree session every row but the current branch is
1633
+ * LOCKED (dimmed, still clickable): a pick reaches the owner, which
1634
+ * answers with the main-checkout hint — the dimming reads as "not usable
1635
+ * here" at a glance while the click keeps its explanation.
1046
1636
  */
1047
- function buildBranchRows(branches, worktrees, currentBranch, worktreeMode) {
1048
- const occupied = new Set(worktrees.flatMap((w) => w.branch === void 0 ? [] : [w.branch]));
1049
- return branches.filter((b) => b.kind === "local").map((branch) => ({
1050
- name: branch.name,
1051
- disabled: branch.name !== currentBranch && !worktreeMode && occupied.has(localBranchName(branch.name))
1052
- }));
1637
+ function buildBranchRows(branches, worktrees, currentBranch, inLinkedWorktree) {
1638
+ const held = new Set(worktrees.flatMap((w) => w.main || w.branch === void 0 ? [] : [w.branch]));
1639
+ const lock = (name) => inLinkedWorktree && name !== currentBranch;
1640
+ return [
1641
+ ...branches.filter((b) => b.kind === "local" && !held.has(b.name)).map((b) => ({
1642
+ name: b.name,
1643
+ kind: "local",
1644
+ ...b.ahead === void 0 ? {} : { ahead: b.ahead },
1645
+ ...b.behind === void 0 ? {} : { behind: b.behind },
1646
+ locked: lock(b.name)
1647
+ })),
1648
+ ...branches.filter((b) => b.kind === "remote").map((b) => ({
1649
+ name: b.name,
1650
+ kind: "remote",
1651
+ locked: lock(b.name)
1652
+ })),
1653
+ ...worktrees.flatMap((w) => w.main || w.branch === void 0 ? [] : [{
1654
+ name: w.branch,
1655
+ kind: "worktree",
1656
+ path: w.path,
1657
+ locked: lock(w.branch)
1658
+ }])
1659
+ ];
1053
1660
  }
1054
1661
  /**
1055
1662
  * The check-time confirm dialog, rendered while the branch menu is closed:
1056
1663
  * the same popCard chrome as BranchMenu's flyout, but bottom-pinned above
1057
1664
  * the chip in the menu card's posture — the flyout's right-of-card anchor
1058
1665
  * has no card to sit beside here. Outside pointerdown and Escape cancel;
1059
- * the confirm button takes focus so Enter commits.
1666
+ * the naming input (cutout flow) takes focus when present, else the
1667
+ * confirm button does so Enter commits.
1060
1668
  */
1061
- function ChipConfirm({ anchorRef, ask, confirmLabel, cancelLabel, busy, onConfirm, onCancel }) {
1669
+ function ChipConfirm({ anchorRef, ask, subject, confirmLabel, cancelLabel, busy, draft, onDraftChange, draftPlaceholder, draftInvalid, draftHint, onConfirm, onCancel }) {
1062
1670
  const popRef = (0, react.useRef)(null);
1063
1671
  const confirmRef = (0, react.useRef)(null);
1672
+ const draftInputRef = (0, react.useRef)(null);
1064
1673
  const [pos, setPos] = (0, react.useState)(null);
1065
1674
  (0, react.useLayoutEffect)(() => {
1066
1675
  const place = () => {
@@ -1086,7 +1695,7 @@ window.__ModuleLoader__.load({
1086
1695
  }, [anchorRef]);
1087
1696
  (0, react.useEffect)(() => {
1088
1697
  const raf = requestAnimationFrame(() => {
1089
- confirmRef.current?.focus();
1698
+ (draftInputRef.current ?? confirmRef.current)?.focus();
1090
1699
  });
1091
1700
  return () => {
1092
1701
  cancelAnimationFrame(raf);
@@ -1114,34 +1723,71 @@ window.__ModuleLoader__.load({
1114
1723
  style: pos ?? POP_MEASURE,
1115
1724
  role: "dialog",
1116
1725
  "aria-label": ask,
1117
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1118
- className: BranchChip_module_default.popAsk,
1119
- children: ask
1120
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1121
- className: BranchChip_module_default.popActions,
1122
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1123
- type: "button",
1726
+ children: [
1727
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1728
+ className: BranchChip_module_default.popAsk,
1729
+ children: ask
1730
+ }),
1731
+ subject !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1732
+ className: BranchChip_module_default.popSubject,
1733
+ children: subject
1734
+ }),
1735
+ onDraftChange !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1736
+ ref: draftInputRef,
1737
+ className: BranchChip_module_default.menuCreate,
1738
+ type: "text",
1739
+ value: draft,
1740
+ placeholder: draftPlaceholder,
1741
+ "aria-label": draftPlaceholder,
1742
+ "aria-invalid": draftInvalid,
1743
+ spellCheck: false,
1124
1744
  disabled: busy,
1125
- onClick: onCancel,
1126
- children: cancelLabel
1127
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1128
- ref: confirmRef,
1129
- type: "button",
1130
- disabled: busy,
1131
- onClick: onConfirm,
1132
- children: confirmLabel
1133
- })]
1134
- })]
1745
+ onChange: (event) => {
1746
+ onDraftChange(event.target.value);
1747
+ },
1748
+ onKeyDown: (event) => {
1749
+ if (event.key === "Enter" && draftInvalid !== true && !busy) {
1750
+ event.preventDefault();
1751
+ onConfirm();
1752
+ }
1753
+ }
1754
+ }), draftInvalid === true && draftHint !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1755
+ className: BranchChip_module_default.menuCreateHintBad,
1756
+ role: "status",
1757
+ children: draftHint
1758
+ })] }),
1759
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1760
+ className: BranchChip_module_default.popActions,
1761
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1762
+ type: "button",
1763
+ disabled: busy,
1764
+ onClick: onCancel,
1765
+ children: cancelLabel
1766
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1767
+ ref: confirmRef,
1768
+ type: "button",
1769
+ disabled: busy || draftInvalid === true,
1770
+ onClick: onConfirm,
1771
+ children: confirmLabel
1772
+ })]
1773
+ })
1774
+ ]
1135
1775
  }), document.body);
1136
1776
  }
1137
1777
  /** The tool-row entry registered into conversation.input.left. */
1138
- function BranchChipDock({ session, sessionId, useSessions, adoptWorktree, t }) {
1139
- const cwd = useSessions((state) => state.byId[sessionId])?.cwd;
1778
+ function BranchChipDock({ session, adoptWorktree, sessionsList, t }) {
1779
+ const sessionId = session?.sessionId;
1780
+ const cwd = (0, react.useSyncExternalStore)(sessionsList.subscribe, () => sessionId === void 0 ? void 0 : sessionsList.getSnapshot().byId[sessionId])?.cwd;
1140
1781
  const [repo, refresh] = useRepoStatus(cwd);
1141
1782
  const [menuOpen, setMenuOpen] = (0, react.useState)(false);
1142
1783
  const [worktreeMode, setWorktreeMode] = (0, react.useState)(false);
1143
1784
  const [confirm, setConfirm] = (0, react.useState)(null);
1144
1785
  const [busy, setBusy] = (0, react.useState)(false);
1786
+ /** Which arrow is spinning: fetch and update are single-flight against
1787
+ * the SAME busyRef (mutually exclusive), but the spinning state must be
1788
+ * per-tool — one shared flag made both arrows rotate at once. */
1789
+ const [fetchBusy, setFetchBusy] = (0, react.useState)(false);
1790
+ const [updateBusy, setUpdateBusy] = (0, react.useState)(false);
1145
1791
  const [toast, setToast] = (0, react.useState)(null);
1146
1792
  const chipRef = (0, react.useRef)(null);
1147
1793
  const busyRef = (0, react.useRef)(false);
@@ -1203,48 +1849,177 @@ window.__ModuleLoader__.load({
1203
1849
  refresh,
1204
1850
  runGuarded
1205
1851
  ]);
1206
- /** Worktree flow: POST /worktree (create-or-reuse, or cut out a new
1207
- * branch), register the directory, hop sessions. */
1208
- const doWorktree = (0, react.useCallback)((branch, cutout) => runGuarded(async () => {
1852
+ /** Create-branch flow: POST /branch (create from the current checkout and
1853
+ * switch to it in place), then refetch the status — the menu closed by
1854
+ * then, and the chip label must name the new branch. Fired directly by
1855
+ * the menu's create flyout (no confirm kind): typing the name into the
1856
+ * flyout and pressing Create is the intent. */
1857
+ const doCreateBranch = (0, react.useCallback)((name) => runGuarded(async () => {
1209
1858
  if (cwd === void 0) return "no session directory";
1210
- const result = cutout ? await requestWorktreeCutout(cwd, branch) : await requestWorktree(cwd, branch);
1859
+ const result = await requestCreateBranch(cwd, name);
1211
1860
  if (!result.ok) return result.error;
1212
- try {
1213
- await adoptWorktree(result.path);
1214
- } catch (cause) {
1215
- return cause instanceof Error ? cause.message : String(cause);
1216
- }
1861
+ await refresh();
1217
1862
  }), [
1218
- adoptWorktree,
1219
1863
  cwd,
1864
+ refresh,
1220
1865
  runGuarded
1221
1866
  ]);
1222
- const facts = repo.facts;
1223
- const rows = (0, react.useMemo)(() => facts === null ? [] : buildBranchRows(facts.branches, facts.worktrees, facts.currentBranch, worktreeMode), [facts, worktreeMode]);
1224
- if (facts === null) return null;
1225
- const confirmLocalName = confirm === null ? "" : localBranchName(confirm.branch);
1226
- const existingWorktree = confirm === null || confirm.kind !== "worktree" ? void 0 : facts.worktrees.find((w) => w.branch === confirmLocalName);
1227
- /** One confirm bundle shared by the menu flyout and the standalone
1228
- * dialog (whichever is showing). */
1229
- const confirmBundle = confirm === null ? null : {
1230
- ask: confirm.kind === "worktree-cutout" ? t("worktreeAskCutOut", { branch: confirmLocalName }) : confirm.kind === "worktree" ? t(existingWorktree !== void 0 ? "worktreeAskReuse" : "worktreeAskNew", { branch: confirmLocalName }) : t("switchAsk", { branch: confirm.branch }),
1231
- confirmLabel: busy ? confirm.kind === "worktree" || confirm.kind === "worktree-cutout" ? t("worktreeBusy") : t("switchBusy") : t("actionConfirm"),
1232
- cancelLabel: t("actionCancel"),
1233
- busy,
1234
- onConfirm: () => {
1235
- if (confirm.kind === "worktree" || confirm.kind === "worktree-cutout") doWorktree(confirm.branch, confirm.kind === "worktree-cutout");
1236
- else doSwitch(confirm.branch);
1237
- },
1238
- onCancel: () => {
1239
- if (!busy) setConfirm(null);
1867
+ /** Remote-sync flow: POST /fetch (fetch every remote + prune), then
1868
+ * refetch the status. Deliberately NOT runGuarded: its success closes the
1869
+ * menu, while the whole point of a sync is watching the refreshed branch
1870
+ * list in place. Single-flight shares busyRef with the other actions, so
1871
+ * a sync and a confirm action can never interleave. A network fetch has
1872
+ * NO visible side effect when the remote moved not — the spinning tool
1873
+ * (menu side) and the done toast here ARE the feedback. */
1874
+ const doFetch = (0, react.useCallback)(async () => {
1875
+ if (busyRef.current) return;
1876
+ busyRef.current = true;
1877
+ setBusy(true);
1878
+ setFetchBusy(true);
1879
+ const failure = await (async () => {
1880
+ if (cwd === void 0) return "no session directory";
1881
+ const result = await requestFetch(cwd);
1882
+ if (!result.ok) return result.error;
1883
+ })();
1884
+ busyRef.current = false;
1885
+ setBusy(false);
1886
+ setFetchBusy(false);
1887
+ if (failure !== void 0) {
1888
+ showError(failure);
1889
+ return;
1240
1890
  }
1241
- };
1242
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
1243
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1244
- className: BranchChip_module_default.dock,
1245
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1246
- ref: chipRef,
1247
- type: "button",
1891
+ await refresh();
1892
+ setToast({
1893
+ seq: Date.now(),
1894
+ text: t("fetchDone")
1895
+ });
1896
+ }, [
1897
+ cwd,
1898
+ refresh,
1899
+ showError,
1900
+ t
1901
+ ]);
1902
+ /** Update-current-branch flow: POST /update (fetch every remote, then
1903
+ * fast-forward the checked-out branch to its upstream), then refetch the
1904
+ * status in place — same keep-the-menu-open semantics as the fetch sync.
1905
+ * The toast tells the two apart: fast-forwarded vs already up to date. */
1906
+ const doUpdate = (0, react.useCallback)(async () => {
1907
+ if (busyRef.current) return;
1908
+ busyRef.current = true;
1909
+ setBusy(true);
1910
+ setUpdateBusy(true);
1911
+ const result = cwd === void 0 ? void 0 : await requestUpdate(cwd);
1912
+ busyRef.current = false;
1913
+ setBusy(false);
1914
+ setUpdateBusy(false);
1915
+ if (result === void 0) {
1916
+ showError("no session directory");
1917
+ return;
1918
+ }
1919
+ if (!result.ok) {
1920
+ showError(result.error);
1921
+ return;
1922
+ }
1923
+ await refresh();
1924
+ setToast({
1925
+ seq: Date.now(),
1926
+ text: result.updated ? t("updateDone", { branch: result.branch }) : t("updateUpToDate")
1927
+ });
1928
+ }, [
1929
+ cwd,
1930
+ refresh,
1931
+ showError,
1932
+ t
1933
+ ]);
1934
+ /** Worktree-group flow: hop the session into the EXISTING worktree
1935
+ * directory. No git action, no confirm — the double-click IS the hop
1936
+ * (a directory jump is reversible and touches nothing), and the owner's
1937
+ * adoptWorktree registers the folder and opens a blank session there. */
1938
+ const doAdoptWorktree = (0, react.useCallback)((path) => {
1939
+ if (busyRef.current) return;
1940
+ busyRef.current = true;
1941
+ setBusy(true);
1942
+ adoptWorktree(path).then(() => {
1943
+ setMenuOpen(false);
1944
+ }).catch((cause) => {
1945
+ showError(cause instanceof Error ? cause.message : String(cause));
1946
+ }).finally(() => {
1947
+ busyRef.current = false;
1948
+ setBusy(false);
1949
+ });
1950
+ }, [adoptWorktree, showError]);
1951
+ /** Worktree flow: POST /worktree (create-or-reuse, or cut out a new
1952
+ * branch under an explicit name), register the directory, hop sessions. */
1953
+ const doWorktree = (0, react.useCallback)((branch, cutout, name) => runGuarded(async () => {
1954
+ if (cwd === void 0) return "no session directory";
1955
+ const result = cutout ? await requestWorktreeCutout(cwd, branch, name) : await requestWorktree(cwd, branch);
1956
+ if (!result.ok) return result.error;
1957
+ try {
1958
+ await adoptWorktree(result.path);
1959
+ } catch (cause) {
1960
+ return cause instanceof Error ? cause.message : String(cause);
1961
+ }
1962
+ }), [
1963
+ adoptWorktree,
1964
+ cwd,
1965
+ runGuarded
1966
+ ]);
1967
+ const facts = repo.facts;
1968
+ const inLinkedWorktree = facts !== null && facts.worktrees.find((w) => w.main)?.path !== facts.repoRoot;
1969
+ const rows = (0, react.useMemo)(() => {
1970
+ if (facts === null) return [];
1971
+ if (inLinkedWorktree && !session.blank) {
1972
+ const current = facts.branches.find((b) => b.kind === "local" && b.name === facts.currentBranch);
1973
+ return current === void 0 ? [] : [{
1974
+ name: current.name,
1975
+ kind: "local",
1976
+ ...current.ahead === void 0 ? {} : { ahead: current.ahead },
1977
+ ...current.behind === void 0 ? {} : { behind: current.behind }
1978
+ }];
1979
+ }
1980
+ return buildBranchRows(facts.branches, facts.worktrees, facts.currentBranch, inLinkedWorktree);
1981
+ }, [
1982
+ facts,
1983
+ inLinkedWorktree,
1984
+ session.blank
1985
+ ]);
1986
+ const localNames = (0, react.useMemo)(() => rows.filter((row) => row.kind !== "remote").map((row) => row.name), [rows]);
1987
+ if (facts === null) return null;
1988
+ const confirmLocalName = confirm === null ? "" : localBranchName(confirm.branch);
1989
+ const isCutout = confirm?.kind === "worktree-cutout";
1990
+ const cutoutDraft = isCutout ? confirm.draft ?? "" : "";
1991
+ const cutoutIssue = isCutout ? branchNameIssue(cutoutDraft) : null;
1992
+ const cutoutDuplicate = isCutout && cutoutIssue === null && localNames.includes(cutoutDraft);
1993
+ const cutoutValid = cutoutIssue === null && !cutoutDuplicate;
1994
+ const cutoutHint = cutoutDuplicate ? t("menuNewBranchExists") : cutoutIssue !== null && cutoutIssue !== "empty" ? t("menuNewBranchBad") : void 0;
1995
+ const existingWorktree = confirm === null || confirm.kind !== "worktree" ? void 0 : facts.worktrees.find((w) => w.branch === confirmLocalName);
1996
+ /** One confirm bundle shared by the menu flyout and the standalone
1997
+ * dialog (whichever is showing). Remote picks keep the ask line SHORT (a
1998
+ * wrapping sentence with long branch names breaks badly) and name the
1999
+ * branch on its own weight-500 line — the dwim/worktree consequences are
2000
+ * git's default behavior, not worth a third line. */
2001
+ const confirmBundle = confirm === null ? null : {
2002
+ ask: confirm.kind === "worktree-cutout" ? t("worktreeAskCutOut", { branch: confirmLocalName }) : confirm.kind === "worktree" ? confirm.remote === true ? t("worktreeAskRemote") : t(existingWorktree !== void 0 ? "worktreeAskReuse" : "worktreeAskNew", { branch: confirmLocalName }) : confirm.remote === true ? t("switchAskRemote") : t("switchAsk", { branch: confirm.branch }),
2003
+ ...confirm.remote === true ? { subject: confirm.branch } : {},
2004
+ confirmLabel: busy ? confirm.kind === "worktree" || confirm.kind === "worktree-cutout" ? t("worktreeBusy") : t("switchBusy") : t("actionConfirm"),
2005
+ cancelLabel: t("actionCancel"),
2006
+ busy,
2007
+ onConfirm: () => {
2008
+ if (confirm.kind === "worktree" || confirm.kind === "worktree-cutout") {
2009
+ if (confirm.kind === "worktree-cutout" && !cutoutValid) return;
2010
+ doWorktree(confirm.branch, confirm.kind === "worktree-cutout", confirm.draft);
2011
+ } else doSwitch(confirm.branch);
2012
+ },
2013
+ onCancel: () => {
2014
+ if (!busy) setConfirm(null);
2015
+ }
2016
+ };
2017
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
2018
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
2019
+ className: BranchChip_module_default.dock,
2020
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
2021
+ ref: chipRef,
2022
+ type: "button",
1248
2023
  className: BranchChip_module_default.chip,
1249
2024
  title: facts.currentBranch,
1250
2025
  onClick: () => {
@@ -1257,7 +2032,7 @@ window.__ModuleLoader__.load({
1257
2032
  className: BranchChip_module_default.branch,
1258
2033
  children: displayBranch(facts.currentBranch)
1259
2034
  })]
1260
- }), session.blank && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2035
+ }), session.blank && !inLinkedWorktree && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1261
2036
  className: BranchChip_module_default.divider,
1262
2037
  "aria-hidden": "true"
1263
2038
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
@@ -1270,7 +2045,8 @@ window.__ModuleLoader__.load({
1270
2045
  if (next) {
1271
2046
  setConfirm({
1272
2047
  kind: "worktree-cutout",
1273
- branch: facts.currentBranch
2048
+ branch: facts.currentBranch,
2049
+ draft: firstFreeCutoutName(localBranchName(facts.currentBranch), localNames)
1274
2050
  });
1275
2051
  if (!busyRef.current) refresh();
1276
2052
  } else setConfirm(null);
@@ -1291,18 +2067,47 @@ window.__ModuleLoader__.load({
1291
2067
  rows,
1292
2068
  currentBranch: facts.currentBranch,
1293
2069
  confirm: confirmBundle,
2070
+ canCreate: !worktreeMode && !inLinkedWorktree,
2071
+ canAdopt: session.blank,
2072
+ busy,
2073
+ onCreate: (name) => {
2074
+ doCreateBranch(name);
2075
+ },
2076
+ onFetch: () => {
2077
+ doFetch();
2078
+ },
2079
+ fetchBusy,
2080
+ onUpdate: () => {
2081
+ doUpdate();
2082
+ },
2083
+ updateBusy,
1294
2084
  onSelect: (branch) => {
1295
2085
  if (branch === facts.currentBranch) {
1296
2086
  if (worktreeMode) setConfirm({
1297
2087
  kind: "worktree-cutout",
1298
- branch
2088
+ branch,
2089
+ draft: firstFreeCutoutName(localBranchName(branch), localNames)
1299
2090
  });
1300
2091
  else setMenuOpen(false);
1301
2092
  return;
1302
2093
  }
2094
+ if (inLinkedWorktree) {
2095
+ setToast({
2096
+ seq: Date.now(),
2097
+ text: t("mainRepoOnly")
2098
+ });
2099
+ return;
2100
+ }
2101
+ const row = rows.find((r) => r.name === branch);
2102
+ if (row?.kind === "worktree" && row.path !== void 0) {
2103
+ doAdoptWorktree(row.path);
2104
+ return;
2105
+ }
2106
+ const remote = row?.kind === "remote";
1303
2107
  setConfirm({
1304
2108
  kind: worktreeMode ? "worktree" : "switch",
1305
- branch
2109
+ branch,
2110
+ remote
1306
2111
  });
1307
2112
  },
1308
2113
  onClose: () => {
@@ -1312,7 +2117,17 @@ window.__ModuleLoader__.load({
1312
2117
  }),
1313
2118
  confirmBundle !== null && !menuOpen && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChipConfirm, {
1314
2119
  anchorRef: chipRef,
1315
- ...confirmBundle
2120
+ ...confirmBundle,
2121
+ ...isCutout ? { draft: cutoutDraft } : {},
2122
+ ...isCutout ? { onDraftChange: (value) => {
2123
+ setConfirm((current) => current?.kind === "worktree-cutout" ? {
2124
+ ...current,
2125
+ draft: value
2126
+ } : current);
2127
+ } } : {},
2128
+ draftPlaceholder: t("menuNewBranchPlaceholder"),
2129
+ ...isCutout && !cutoutValid ? { draftInvalid: true } : {},
2130
+ ...cutoutHint === void 0 ? {} : { draftHint: cutoutHint }
1316
2131
  }),
1317
2132
  toast !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Toast, {
1318
2133
  text: toast.text,
@@ -1332,21 +2147,30 @@ window.__ModuleLoader__.load({
1332
2147
  * The form publishes through a snapshot store because the slot component
1333
2148
  * reads through a snapshot selector while both the scope and the local draft
1334
2149
  * change underneath; every projection is rebuilt from the two together. The
1335
- * field is staged only when the user touched it, so a save writes a sparse
1336
- * patch and never restates fields it did not see.
2150
+ * root field is staged only when the user touched it, so a save writes a
2151
+ * sparse patch and never restates fields it did not see. The grouping switch
2152
+ * is not staged: a set optimistic-publishes, yields a frame so the spinner
2153
+ * can paint, then writes; pending holds until the seat callback settles.
1337
2154
  */
1338
2155
  var CardForm = class {
1339
2156
  scope;
2157
+ afterGroupSidebarWrite;
1340
2158
  snapshotValue;
1341
2159
  listeners = /* @__PURE__ */ new Set();
1342
2160
  draft;
1343
2161
  saving = false;
1344
2162
  failed = false;
2163
+ groupingPending = false;
2164
+ groupingDraft;
1345
2165
  /**
1346
2166
  * @param scope - the bound settings scope for the `git-worktree` namespace.
2167
+ * @param afterGroupSidebarWrite - awaited after the setting lands, until
2168
+ * the sidebar seat has actually swapped (facts in on enable, native
2169
+ * paint on disable). Absent in unit tests that only cover the write.
1347
2170
  */
1348
- constructor(scope) {
2171
+ constructor(scope, afterGroupSidebarWrite) {
1349
2172
  this.scope = scope;
2173
+ this.afterGroupSidebarWrite = afterGroupSidebarWrite;
1350
2174
  this.snapshotValue = this.project();
1351
2175
  scope.subscribe(() => {
1352
2176
  this.publish();
@@ -1367,7 +2191,7 @@ window.__ModuleLoader__.load({
1367
2191
  }
1368
2192
  };
1369
2193
  }
1370
- /** @returns the edit, clear, save, and discard actions bound to this form. */
2194
+ /** @returns the edit, clear, save, discard, and grouping-switch actions bound to this form. */
1371
2195
  actions() {
1372
2196
  return {
1373
2197
  editRoot: (text) => {
@@ -1386,10 +2210,39 @@ window.__ModuleLoader__.load({
1386
2210
  this.draft = void 0;
1387
2211
  this.failed = false;
1388
2212
  this.publish();
1389
- }
2213
+ },
2214
+ setGroupSidebar: (value) => this.setGroupSidebar(value)
1390
2215
  };
1391
2216
  }
1392
2217
  /**
2218
+ * Flip the grouping switch immediately, then persist.
2219
+ *
2220
+ * `scope.set` only stores the document; the visible sidebar swap (inject
2221
+ * + `/group` facts, or dispose + native paint) happens after. Pending
2222
+ * stays up until that callback settles so the spinner matches what the
2223
+ * user sees, not the write round-trip.
2224
+ */
2225
+ async setGroupSidebar(value) {
2226
+ if (this.groupingPending) return;
2227
+ if (value === this.effectiveGroupSidebar()) return;
2228
+ this.groupingPending = true;
2229
+ this.groupingDraft = value;
2230
+ this.publish();
2231
+ await yieldForPaint();
2232
+ try {
2233
+ await this.scope.set("groupSidebar", value);
2234
+ if (this.afterGroupSidebarWrite !== void 0) await this.afterGroupSidebarWrite(value);
2235
+ } finally {
2236
+ this.groupingPending = false;
2237
+ this.groupingDraft = void 0;
2238
+ this.publish();
2239
+ }
2240
+ }
2241
+ /** Resolved grouping switch, preferring an in-flight optimistic draft. */
2242
+ effectiveGroupSidebar() {
2243
+ return this.groupingDraft ?? this.scope.getSnapshot().value?.groupSidebar ?? true;
2244
+ }
2245
+ /**
1393
2246
  * Write the staged edit, then re-seed from what the Host accepted.
1394
2247
  *
1395
2248
  * The Host is the only authority on acceptance — an empty draft clears the
@@ -1445,7 +2298,9 @@ window.__ModuleLoader__.load({
1445
2298
  overridden: this.draft !== void 0 ? this.draft.trim() !== "" : this.storedRoot(),
1446
2299
  dirty: this.draft !== void 0 && this.draft !== this.effectiveRoot(),
1447
2300
  saving: this.saving,
1448
- failed: this.failed
2301
+ failed: this.failed,
2302
+ groupSidebar: this.effectiveGroupSidebar(),
2303
+ groupingPending: this.groupingPending
1449
2304
  };
1450
2305
  }
1451
2306
  /** Replace the snapshot reference and notify, only when the fact moved. */
@@ -1458,39 +2313,60 @@ window.__ModuleLoader__.load({
1458
2313
  this.store(this.project());
1459
2314
  }
1460
2315
  };
2316
+ /** Yield until after the next paint (rAF), or a macrotask when rAF is absent (tests). */
2317
+ function yieldForPaint() {
2318
+ return new Promise((resolve) => {
2319
+ if (typeof requestAnimationFrame === "function") {
2320
+ requestAnimationFrame(() => {
2321
+ resolve();
2322
+ });
2323
+ return;
2324
+ }
2325
+ setTimeout(resolve, 0);
2326
+ });
2327
+ }
1461
2328
  //#endregion
1462
- //#region \0git-worktree-css:D:\Code\dsh-worktree\src\client\GitWorktreeCard.module.css?inline
1463
- const css = "/* git-worktree settings card on the Plugins configuration tab. Visual\n * language mirrors the settings section's own card chrome (border radius,\n * layer fills, pending badge, footer buttons) so cards from different\n * packages sit in one list without reading as two designs; tokens only, no\n * literal colors. */\n\n.card_1712176718 {\n list-style: none;\n border: 1px solid var(--dsw-alias-border-l2);\n border-radius: 12px;\n background: var(--dsw-alias-bg-layer-3);\n transition: border-color .16s, background .16s;\n}\n\n.card_1712176718:hover {\n border-color: var(--dsw-alias-label-dimmed);\n}\n\n/* An open card reads as the one being worked on, not merely taller. */\n.cardOpen_1712176718 {\n background: var(--dsw-alias-bg-layer-2);\n border-color: var(--dsw-alias-label-dimmed);\n}\n\n.header_1712176718 {\n width: 100%;\n appearance: none;\n border: 0;\n background: none;\n font: inherit;\n color: inherit;\n text-align: left;\n cursor: pointer;\n display: flex;\n align-items: center;\n gap: 12px;\n padding: 14px 16px;\n border-radius: 12px;\n}\n\n.header_1712176718:focus-visible {\n outline: 2px solid var(--dsw-alias-brand-primary);\n outline-offset: -2px;\n}\n\n/* Name over description, mirroring the section's own plugin cards: the\n * description is what tells one plugin's settings from another's. */\n.headText_1712176718 {\n flex: 1;\n min-width: 0;\n display: flex;\n flex-direction: column;\n gap: 4px;\n}\n\n.name_1712176718 {\n font-size: 15px;\n font-weight: 600;\n line-height: 1.4;\n color: var(--dsw-alias-label-primary);\n}\n\n.description_1712176718 {\n font-size: 13px;\n line-height: 1.5;\n color: var(--dsw-alias-label-tertiary);\n}\n\n/* Carried on the header so a collapsed card still says it holds edits. */\n.pending_1712176718 {\n flex: none;\n border-radius: 999px;\n padding: 1px 8px;\n font-size: 11px;\n line-height: 17px;\n font-weight: 500;\n white-space: nowrap;\n background: var(--dsw-alias-bg-module-platform);\n color: var(--dsw-alias-label-secondary);\n}\n\n.chevron_1712176718 {\n flex: none;\n color: var(--dsw-alias-label-tertiary);\n transition: transform .16s;\n}\n\n.chevronOpen_1712176718 {\n transform: rotate(180deg);\n}\n\n.body_1712176718 {\n border-top: 1px solid var(--dsw-alias-border-l2);\n margin: 0 16px;\n padding: 12px 0 8px;\n display: flex;\n flex-direction: column;\n gap: 10px;\n}\n\n.note_1712176718 {\n margin: 0;\n font-size: 12px;\n line-height: 1.5;\n color: var(--dsw-alias-label-tertiary);\n}\n\n.field_1712176718 {\n display: flex;\n flex-direction: column;\n gap: 4px;\n}\n\n.fieldLabel_1712176718 {\n font-size: 12px;\n line-height: 1.5;\n color: var(--dsw-alias-label-secondary);\n}\n\n.input_1712176718 {\n box-sizing: border-box;\n width: 100%;\n padding: 4px 8px;\n font: inherit;\n font-size: 13px;\n line-height: 20px;\n color: var(--dsw-alias-label-primary);\n background-color: var(--dsw-alias-bg-layer-2);\n border: 1px solid var(--dsw-alias-border-l2);\n border-radius: 6px;\n appearance: none;\n}\n\n.input_1712176718:focus-visible {\n outline: 2px solid var(--dsw-alias-brand-primary);\n outline-offset: -1px;\n}\n\n.input_1712176718:disabled {\n opacity: 0.6;\n}\n\n/* The directory control and its native-dialog launcher share one row. */\n.inputRow_1712176718 {\n display: flex;\n align-items: center;\n gap: 6px;\n}\n\n.inputRow_1712176718 .input_1712176718 {\n flex: 1;\n min-width: 0;\n}\n\n.browse_1712176718 {\n appearance: none;\n flex: none;\n border: 1px solid var(--dsw-alias-border-l2);\n border-radius: 6px;\n padding: 4px 10px;\n font: inherit;\n font-size: 13px;\n line-height: 20px;\n color: var(--dsw-alias-label-secondary);\n background: none;\n cursor: pointer;\n white-space: nowrap;\n}\n\n.browse_1712176718:hover:not(:disabled) {\n color: var(--dsw-alias-label-primary);\n border-color: var(--dsw-alias-label-dimmed);\n}\n\n.browse_1712176718:disabled {\n opacity: 0.4;\n cursor: default;\n}\n\n.browse_1712176718:focus-visible {\n outline: 2px solid var(--dsw-alias-brand-primary);\n outline-offset: 1px;\n}\n\n.hint_1712176718 {\n margin: 0;\n font-size: 12px;\n line-height: 1.5;\n color: var(--dsw-alias-label-tertiary);\n}\n\n.footer_1712176718 {\n display: flex;\n align-items: center;\n justify-content: flex-end;\n gap: 8px;\n padding: 8px 0 4px;\n border-top: 1px solid var(--dsw-alias-border-l2);\n}\n\n.failed_1712176718 {\n flex: 1;\n min-width: 0;\n margin: 0;\n font-size: 12px;\n line-height: 1.5;\n color: var(--dsw-alias-label-error);\n}\n\n.discard_1712176718,\n.save_1712176718 {\n appearance: none;\n border: 1px solid transparent;\n border-radius: 8px;\n padding: 5px 14px;\n font: inherit;\n font-size: 13px;\n line-height: 1.5;\n cursor: pointer;\n}\n\n.discard_1712176718 {\n border-color: var(--dsw-alias-border-l2);\n background: none;\n color: var(--dsw-alias-label-secondary);\n}\n\n.discard_1712176718:hover:not(:disabled) {\n color: var(--dsw-alias-label-primary);\n border-color: var(--dsw-alias-label-dimmed);\n}\n\n.save_1712176718 {\n background: var(--dsw-alias-label-primary);\n color: var(--dsw-alias-bg-layer-3);\n}\n\n.discard_1712176718:disabled,\n.save_1712176718:disabled {\n opacity: 0.4;\n cursor: default;\n}\n\n.discard_1712176718:focus-visible,\n.save_1712176718:focus-visible {\n outline: 2px solid var(--dsw-alias-brand-primary);\n outline-offset: 1px;\n}\n";
1464
- const tagId = "@laoyuehanni/dsh-git-worktree/GitWorktreeCard.module.css";
1465
- if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=\"" + tagId + "\"]") === null) {
2329
+ //#region \0git-worktree-css:C:\Users\OYW\.dsh\gitworktree\dsh-worktree-origin-feature-0.1.2-alpha.3\src\client\GitWorktreeCard.module.css?inline
2330
+ const css$2 = "/* git-worktree settings card on the Plugins configuration tab. Visual\n * language mirrors the settings section's own card chrome (border radius,\n * layer fills, pending badge, footer buttons) so cards from different\n * packages sit in one list without reading as two designs; tokens only, no\n * literal colors. */\n\n.card_1870175511 {\n list-style: none;\n border: 1px solid var(--dsw-alias-border-l2);\n border-radius: 12px;\n background: var(--dsw-alias-bg-layer-3);\n transition: border-color .16s, background .16s;\n}\n\n.card_1870175511:hover {\n border-color: var(--dsw-alias-label-dimmed);\n}\n\n/* An open card reads as the one being worked on, not merely taller. */\n.cardOpen_1870175511 {\n background: var(--dsw-alias-bg-layer-2);\n border-color: var(--dsw-alias-label-dimmed);\n}\n\n.header_1870175511 {\n width: 100%;\n appearance: none;\n border: 0;\n background: none;\n font: inherit;\n color: inherit;\n text-align: left;\n cursor: pointer;\n display: flex;\n align-items: center;\n gap: 12px;\n padding: 14px 16px;\n border-radius: 12px;\n}\n\n.header_1870175511:focus-visible {\n outline: 2px solid var(--dsw-alias-brand-primary);\n outline-offset: -2px;\n}\n\n/* Name over description, mirroring the section's own plugin cards: the\n * description is what tells one plugin's settings from another's. */\n.headText_1870175511 {\n flex: 1;\n min-width: 0;\n display: flex;\n flex-direction: column;\n gap: 4px;\n}\n\n.name_1870175511 {\n font-size: 15px;\n font-weight: 600;\n line-height: 1.4;\n color: var(--dsw-alias-label-primary);\n}\n\n.description_1870175511 {\n font-size: 13px;\n line-height: 1.5;\n color: var(--dsw-alias-label-tertiary);\n}\n\n/* Carried on the header so a collapsed card still says it holds edits. */\n.pending_1870175511 {\n flex: none;\n border-radius: 999px;\n padding: 1px 8px;\n font-size: 11px;\n line-height: 17px;\n font-weight: 500;\n white-space: nowrap;\n background: var(--dsw-alias-bg-module-platform);\n color: var(--dsw-alias-label-secondary);\n}\n\n.chevron_1870175511 {\n flex: none;\n color: var(--dsw-alias-label-tertiary);\n transition: transform .16s;\n}\n\n.chevronOpen_1870175511 {\n transform: rotate(180deg);\n}\n\n.body_1870175511 {\n border-top: 1px solid var(--dsw-alias-border-l2);\n margin: 0 16px;\n padding: 12px 0 8px;\n display: flex;\n flex-direction: column;\n gap: 10px;\n}\n\n.note_1870175511 {\n margin: 0;\n font-size: 12px;\n line-height: 1.5;\n color: var(--dsw-alias-label-tertiary);\n}\n\n.field_1870175511 {\n display: flex;\n flex-direction: column;\n gap: 4px;\n}\n\n.fieldLabel_1870175511 {\n font-size: 12px;\n line-height: 1.5;\n color: var(--dsw-alias-label-secondary);\n}\n\n.input_1870175511 {\n box-sizing: border-box;\n width: 100%;\n padding: 4px 8px;\n font: inherit;\n font-size: 13px;\n line-height: 20px;\n color: var(--dsw-alias-label-primary);\n background-color: var(--dsw-alias-bg-layer-2);\n border: 1px solid var(--dsw-alias-border-l2);\n border-radius: 6px;\n appearance: none;\n}\n\n.input_1870175511:focus-visible {\n outline: 2px solid var(--dsw-alias-brand-primary);\n outline-offset: -1px;\n}\n\n.input_1870175511:disabled {\n opacity: 0.6;\n}\n\n/* The directory control and its native-dialog launcher share one row. */\n.inputRow_1870175511 {\n display: flex;\n align-items: center;\n gap: 6px;\n}\n\n.inputRow_1870175511 .input_1870175511 {\n flex: 1;\n min-width: 0;\n}\n\n.browse_1870175511 {\n appearance: none;\n flex: none;\n border: 1px solid var(--dsw-alias-border-l2);\n border-radius: 6px;\n padding: 4px 10px;\n font: inherit;\n font-size: 13px;\n line-height: 20px;\n color: var(--dsw-alias-label-secondary);\n background: none;\n cursor: pointer;\n white-space: nowrap;\n}\n\n.browse_1870175511:hover:not(:disabled) {\n color: var(--dsw-alias-label-primary);\n border-color: var(--dsw-alias-label-dimmed);\n}\n\n.browse_1870175511:disabled {\n opacity: 0.4;\n cursor: default;\n}\n\n.browse_1870175511:focus-visible {\n outline: 2px solid var(--dsw-alias-brand-primary);\n outline-offset: 1px;\n}\n\n.hint_1870175511 {\n margin: 0;\n font-size: 12px;\n line-height: 1.5;\n color: var(--dsw-alias-label-tertiary);\n}\n\n.footer_1870175511 {\n display: flex;\n align-items: center;\n justify-content: flex-end;\n gap: 8px;\n padding: 8px 0 4px;\n border-top: 1px solid var(--dsw-alias-border-l2);\n}\n\n.failed_1870175511 {\n flex: 1;\n min-width: 0;\n margin: 0;\n font-size: 12px;\n line-height: 1.5;\n color: var(--dsw-alias-label-error);\n}\n\n.discard_1870175511,\n.save_1870175511 {\n appearance: none;\n border: 1px solid transparent;\n border-radius: 8px;\n padding: 5px 14px;\n font: inherit;\n font-size: 13px;\n line-height: 1.5;\n cursor: pointer;\n}\n\n.discard_1870175511 {\n border-color: var(--dsw-alias-border-l2);\n background: none;\n color: var(--dsw-alias-label-secondary);\n}\n\n.discard_1870175511:hover:not(:disabled) {\n color: var(--dsw-alias-label-primary);\n border-color: var(--dsw-alias-label-dimmed);\n}\n\n.save_1870175511 {\n background: var(--dsw-alias-label-primary);\n color: var(--dsw-alias-bg-layer-3);\n}\n\n.discard_1870175511:disabled,\n.save_1870175511:disabled {\n opacity: 0.4;\n cursor: default;\n}\n\n.discard_1870175511:focus-visible,\n.save_1870175511:focus-visible {\n outline: 2px solid var(--dsw-alias-brand-primary);\n outline-offset: 1px;\n}\n\n/* Sidebar-grouping switch: title + hint + caution beside a checkbox. */\n.toggleRow_1870175511 {\n margin-top: 10px;\n flex-direction: row;\n align-items: flex-start;\n gap: 10px;\n}\n\n.toggleText_1870175511 {\n flex: 1;\n display: flex;\n flex-direction: column;\n gap: 2px;\n}\n\n.toggleLabel_1870175511 {\n color: var(--dsw-alias-label-primary);\n font-weight: 500;\n}\n\n.toggleMark_1870175511 {\n margin-left: 4px;\n font-weight: 400;\n color: var(--dsw-alias-label-tertiary);\n}\n\n.toggleHint_1870175511 {\n color: var(--dsw-alias-label-tertiary);\n font-size: 12px;\n line-height: 18px;\n}\n\n.toggleNote_1870175511 {\n font-size: 12px;\n line-height: 18px;\n color: var(--dsw-alias-label-tertiary);\n}\n\n.toggleControl_1870175511 {\n display: flex;\n align-items: center;\n gap: 6px;\n flex: none;\n margin-top: 2px;\n}\n\n.spinner_1870175511 {\n display: flex;\n color: var(--dsw-alias-label-tertiary);\n animation: spin 0.7s linear infinite;\n}\n\n@keyframes spin {\n to { transform: rotate(360deg); }\n}\n\n.toggle_1870175511 {\n width: 16px;\n height: 16px;\n accent-color: var(--dsw-alias-brand-primary);\n cursor: pointer;\n}\n\n.toggle_1870175511:disabled {\n cursor: progress;\n}\n";
2331
+ const tagId$2 = "@laoyuehanni/dsh-git-worktree/GitWorktreeCard.module.css";
2332
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=\"" + tagId$2 + "\"]") === null) {
1466
2333
  const tag = document.createElement("style");
1467
2334
  tag.dataset.plugin = "@laoyuehanni/dsh-git-worktree";
1468
- tag.dataset.pluginCss = tagId;
1469
- tag.textContent = css;
2335
+ tag.dataset.pluginCss = tagId$2;
2336
+ tag.textContent = css$2;
1470
2337
  document.head.appendChild(tag);
1471
2338
  }
1472
2339
  var GitWorktreeCard_module_default = {
1473
- "card": "card_1712176718",
1474
- "cardOpen": "cardOpen_1712176718",
1475
- "header": "header_1712176718",
1476
- "headText": "headText_1712176718",
1477
- "name": "name_1712176718",
1478
- "description": "description_1712176718",
1479
- "pending": "pending_1712176718",
1480
- "chevron": "chevron_1712176718",
1481
- "chevronOpen": "chevronOpen_1712176718",
1482
- "body": "body_1712176718",
1483
- "note": "note_1712176718",
1484
- "field": "field_1712176718",
1485
- "fieldLabel": "fieldLabel_1712176718",
1486
- "input": "input_1712176718",
1487
- "inputRow": "inputRow_1712176718",
1488
- "browse": "browse_1712176718",
1489
- "hint": "hint_1712176718",
1490
- "footer": "footer_1712176718",
1491
- "failed": "failed_1712176718",
1492
- "discard": "discard_1712176718",
1493
- "save": "save_1712176718"
2340
+ "card": "card_1870175511",
2341
+ "cardOpen": "cardOpen_1870175511",
2342
+ "header": "header_1870175511",
2343
+ "headText": "headText_1870175511",
2344
+ "name": "name_1870175511",
2345
+ "description": "description_1870175511",
2346
+ "pending": "pending_1870175511",
2347
+ "chevron": "chevron_1870175511",
2348
+ "chevronOpen": "chevronOpen_1870175511",
2349
+ "body": "body_1870175511",
2350
+ "note": "note_1870175511",
2351
+ "field": "field_1870175511",
2352
+ "fieldLabel": "fieldLabel_1870175511",
2353
+ "input": "input_1870175511",
2354
+ "inputRow": "inputRow_1870175511",
2355
+ "browse": "browse_1870175511",
2356
+ "hint": "hint_1870175511",
2357
+ "footer": "footer_1870175511",
2358
+ "failed": "failed_1870175511",
2359
+ "discard": "discard_1870175511",
2360
+ "save": "save_1870175511",
2361
+ "toggleRow": "toggleRow_1870175511",
2362
+ "toggleText": "toggleText_1870175511",
2363
+ "toggleLabel": "toggleLabel_1870175511",
2364
+ "toggleMark": "toggleMark_1870175511",
2365
+ "toggleHint": "toggleHint_1870175511",
2366
+ "toggleNote": "toggleNote_1870175511",
2367
+ "toggleControl": "toggleControl_1870175511",
2368
+ "spinner": "spinner_1870175511",
2369
+ "toggle": "toggle_1870175511"
1494
2370
  };
1495
2371
  //#endregion
1496
2372
  //#region src/client/GitWorktreeCard.tsx
@@ -1607,6 +2483,46 @@ window.__ModuleLoader__.load({
1607
2483
  className: GitWorktreeCard_module_default.hint,
1608
2484
  children: [t("cardRootDirHint"), state.overridden ? ` ${t("cardOverridden")}` : ""]
1609
2485
  }),
2486
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
2487
+ className: `${GitWorktreeCard_module_default.field} ${GitWorktreeCard_module_default.toggleRow}`,
2488
+ "aria-busy": state.groupingPending,
2489
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
2490
+ className: GitWorktreeCard_module_default.toggleText,
2491
+ children: [
2492
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
2493
+ className: GitWorktreeCard_module_default.toggleLabel,
2494
+ children: [t("cardGroupSidebarLabel"), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2495
+ className: GitWorktreeCard_module_default.toggleMark,
2496
+ children: t("cardGroupSidebarMark")
2497
+ })]
2498
+ }),
2499
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2500
+ className: GitWorktreeCard_module_default.toggleHint,
2501
+ children: t("cardGroupSidebarHint")
2502
+ }),
2503
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2504
+ className: GitWorktreeCard_module_default.toggleNote,
2505
+ children: t("cardGroupSidebarNote")
2506
+ })
2507
+ ]
2508
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
2509
+ className: GitWorktreeCard_module_default.toggleControl,
2510
+ children: [state.groupingPending ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2511
+ className: GitWorktreeCard_module_default.spinner,
2512
+ role: "status",
2513
+ "aria-label": t("cardGroupSidebarBusy"),
2514
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconLoadingOutline16, { size: 14 })
2515
+ }) : null, /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
2516
+ className: GitWorktreeCard_module_default.toggle,
2517
+ type: "checkbox",
2518
+ disabled: lockInput || state.groupingPending,
2519
+ checked: state.groupSidebar,
2520
+ onChange: (event) => {
2521
+ props.setGroupSidebar(event.target.checked);
2522
+ }
2523
+ })]
2524
+ })]
2525
+ }),
1610
2526
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1611
2527
  className: GitWorktreeCard_module_default.footer,
1612
2528
  children: [
@@ -1636,23 +2552,1959 @@ window.__ModuleLoader__.load({
1636
2552
  });
1637
2553
  }
1638
2554
  //#endregion
2555
+ //#region src/client/sidebar-groups.ts
2556
+ /**
2557
+ * Derive the sidebar groups.
2558
+ *
2559
+ * Rules (the shipped design): git facts absent/null → plain single row;
2560
+ * same-`repoRoot` workspaces cluster into one repo group; inside a group the
2561
+ * main worktree leads and linked members keep registry order; a repo cluster
2562
+ * with exactly ONE member degrades to a plain row (zero visual intrusion for
2563
+ * repositories without worktrees); a group renders where its FIRST member
2564
+ * sits in the registry order (the main worktree's slot).
2565
+ * @param items - workspace list items in registry order.
2566
+ * @param facts - per-path git facts from the /group route (absent = unknown).
2567
+ * @returns groups in render order.
2568
+ */
2569
+ function deriveSidebarGroups(items, facts) {
2570
+ const bucketOrder = [];
2571
+ const buckets = /* @__PURE__ */ new Map();
2572
+ const singles = [];
2573
+ items.forEach((workspace, index) => {
2574
+ const pathFacts = facts?.[workspace.path];
2575
+ if (pathFacts === void 0 || pathFacts === null) {
2576
+ singles.push({
2577
+ index,
2578
+ group: singleGroup(workspace)
2579
+ });
2580
+ return;
2581
+ }
2582
+ const bucketKey = `repo:${pathFacts.repoRoot}`;
2583
+ let bucket = buckets.get(bucketKey);
2584
+ if (bucket === void 0) {
2585
+ bucket = {
2586
+ index,
2587
+ mainSeen: false,
2588
+ members: []
2589
+ };
2590
+ buckets.set(bucketKey, bucket);
2591
+ bucketOrder.push(bucketKey);
2592
+ }
2593
+ bucket.members.push({
2594
+ workspace,
2595
+ label: pathFacts.main ? {
2596
+ type: "main",
2597
+ branch: pathFacts.branch
2598
+ } : {
2599
+ type: "linked",
2600
+ branch: pathFacts.branch
2601
+ }
2602
+ });
2603
+ if (pathFacts.main) bucket.mainSeen = true;
2604
+ });
2605
+ const repoGroups = /* @__PURE__ */ new Map();
2606
+ for (const key of bucketOrder) {
2607
+ const bucket = buckets.get(key);
2608
+ if (bucket === void 0) continue;
2609
+ const ordered = bucket.mainSeen ? [...bucket.members].sort((a, b) => Number(b.label.type === "main") - Number(a.label.type === "main")) : bucket.members;
2610
+ const first = ordered[0];
2611
+ if (first === void 0) continue;
2612
+ const repoName = facts?.[first.workspace.path]?.repoName ?? first.workspace.title;
2613
+ if (ordered.length === 1) {
2614
+ singles.push({
2615
+ index: bucket.index,
2616
+ group: singleGroup(first.workspace)
2617
+ });
2618
+ continue;
2619
+ }
2620
+ repoGroups.set(key, {
2621
+ key,
2622
+ kind: "repo",
2623
+ repoName,
2624
+ members: ordered
2625
+ });
2626
+ }
2627
+ const slots = [...singles, ...[...repoGroups.values()].map((group) => {
2628
+ return {
2629
+ index: buckets.get(group.key)?.index ?? Number.MAX_SAFE_INTEGER,
2630
+ group
2631
+ };
2632
+ })];
2633
+ slots.sort((a, b) => a.index - b.index);
2634
+ return slots.map((slot) => slot.group);
2635
+ }
2636
+ /** A plain single-row group for one workspace. */
2637
+ function singleGroup(workspace) {
2638
+ return {
2639
+ key: `ws:${workspace.workspaceId}`,
2640
+ kind: "single",
2641
+ repoName: void 0,
2642
+ members: [{
2643
+ workspace,
2644
+ label: { type: "plain" }
2645
+ }]
2646
+ };
2647
+ }
2648
+ /**
2649
+ * Session ids a member row shows, in the workspace's stored order — the
2650
+ * native browser's visibility rule: archived hidden everywhere, subagent
2651
+ * rows never listed, and a blank row visible only while it IS the current
2652
+ * selection (a blank is the provisional New Session row).
2653
+ * @param workspace - the member's workspace.
2654
+ * @param sessions - session list snapshot.
2655
+ * @param archivedSessionIds - registry-global archive set.
2656
+ * @returns visible session ids in stored order.
2657
+ */
2658
+ function visibleSessionIds(workspace, sessions, archivedSessionIds) {
2659
+ const archived = new Set(archivedSessionIds);
2660
+ const visible = [];
2661
+ for (const sessionId of workspace.sessionIds) {
2662
+ const summary = sessions.byId[sessionId];
2663
+ if (summary === void 0) continue;
2664
+ if (summary.origin === "subagent") continue;
2665
+ if (archived.has(sessionId)) continue;
2666
+ if (summary.blank && sessionId !== sessions.current) continue;
2667
+ visible.push(sessionId);
2668
+ }
2669
+ return visible;
2670
+ }
2671
+ /** localStorage key of the sidebar expansion map (browser-local only). */
2672
+ const EXPAND_STORAGE_KEY = "dsh-git-worktree.sidebar.expand";
2673
+ /** Read the persisted expansion map; unreadable/absent answers {}. */
2674
+ function loadExpandState() {
2675
+ if (typeof localStorage === "undefined") return {};
2676
+ try {
2677
+ const raw = localStorage.getItem(EXPAND_STORAGE_KEY);
2678
+ if (raw === null) return {};
2679
+ const parsed = JSON.parse(raw);
2680
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return {};
2681
+ const out = {};
2682
+ for (const [key, value] of Object.entries(parsed)) if (typeof value === "boolean") out[key] = value;
2683
+ return out;
2684
+ } catch {
2685
+ return {};
2686
+ }
2687
+ }
2688
+ /** Persist the expansion map; write failures (quota, privacy mode) stay silent. */
2689
+ function saveExpandState(state) {
2690
+ if (typeof localStorage === "undefined") return;
2691
+ try {
2692
+ localStorage.setItem(EXPAND_STORAGE_KEY, JSON.stringify(state));
2693
+ } catch {}
2694
+ }
2695
+ /** localStorage key of grouping/order prefs (browser-local; P3 may graduate to store v5). */
2696
+ const VIEW_STORAGE_KEY = "dsh-git-worktree.sidebar.view";
2697
+ const DEFAULT_VIEW_PREFS = {
2698
+ groupBy: "workspace",
2699
+ orderBy: "updated"
2700
+ };
2701
+ /** Read persisted view prefs; unreadable/absent answers native defaults. */
2702
+ function loadViewPrefs() {
2703
+ if (typeof localStorage === "undefined") return DEFAULT_VIEW_PREFS;
2704
+ try {
2705
+ const raw = localStorage.getItem(VIEW_STORAGE_KEY);
2706
+ if (raw === null) return DEFAULT_VIEW_PREFS;
2707
+ const parsed = JSON.parse(raw);
2708
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return DEFAULT_VIEW_PREFS;
2709
+ const record = parsed;
2710
+ return {
2711
+ groupBy: record.groupBy === "flat" || record.groupBy === "workspace" ? record.groupBy : DEFAULT_VIEW_PREFS.groupBy,
2712
+ orderBy: record.orderBy === "manual" || record.orderBy === "updated" ? record.orderBy : DEFAULT_VIEW_PREFS.orderBy
2713
+ };
2714
+ } catch {
2715
+ return DEFAULT_VIEW_PREFS;
2716
+ }
2717
+ }
2718
+ /** Persist view prefs; write failures stay silent. */
2719
+ function saveViewPrefs(prefs) {
2720
+ if (typeof localStorage === "undefined") return;
2721
+ try {
2722
+ localStorage.setItem(VIEW_STORAGE_KEY, JSON.stringify(prefs));
2723
+ } catch {}
2724
+ }
2725
+ /** Recency comparator: newest first, id as the deterministic tiebreak. */
2726
+ function byRecency(a, b) {
2727
+ if (b.updatedAt !== a.updatedAt) return b.updatedAt - a.updatedAt;
2728
+ return a.id < b.id ? -1 : 1;
2729
+ }
2730
+ /**
2731
+ * Index running/total subagent descendants under each ancestor reached through
2732
+ * an uninterrupted subagent-origin chain (ordinary forks terminate propagation).
2733
+ * Mirrors `indexSubagentDescendants` without importing the runtime bundle.
2734
+ */
2735
+ function indexSubagentRunning(byId) {
2736
+ const out = /* @__PURE__ */ new Map();
2737
+ const bump = (id, running) => {
2738
+ const cur = out.get(id) ?? {
2739
+ count: 0,
2740
+ runningCount: 0
2741
+ };
2742
+ out.set(id, {
2743
+ count: cur.count + 1,
2744
+ runningCount: cur.runningCount + (running ? 1 : 0)
2745
+ });
2746
+ };
2747
+ for (const summary of Object.values(byId)) {
2748
+ if (summary === void 0 || summary.origin !== "subagent") continue;
2749
+ const running = summary.running === true;
2750
+ const seen = /* @__PURE__ */ new Set();
2751
+ let parentId = summary.parentId;
2752
+ while (parentId !== void 0 && parentId !== "" && !seen.has(parentId)) {
2753
+ seen.add(parentId);
2754
+ bump(parentId, running);
2755
+ const parent = byId[parentId];
2756
+ if (parent === void 0 || parent.origin !== "subagent") break;
2757
+ parentId = parent.parentId;
2758
+ }
2759
+ }
2760
+ return out;
2761
+ }
2762
+ /** A blank session's canonical title never enters search; the renderer localizes the label. */
2763
+ function sessionTitle(session) {
2764
+ return session.blank ? "New Session" : session.displayTitle;
2765
+ }
2766
+ /** Project a list-row summary into a renderable session node. */
2767
+ function sessionNode(session, descendants) {
2768
+ return {
2769
+ id: session.id,
2770
+ title: sessionTitle(session),
2771
+ blank: session.blank,
2772
+ running: session.running === true,
2773
+ runningSubagentCount: descendants.get(session.id)?.runningCount ?? 0,
2774
+ completed: session.completed === true,
2775
+ updatedAt: session.updatedAt ?? 0,
2776
+ ...session.pendingInteraction === void 0 ? {} : { pendingInteraction: session.pendingInteraction }
2777
+ };
2778
+ }
2779
+ /** Visible session ids, optionally newest-first when `orderBy` is `updated`. */
2780
+ function orderedVisibleSessionIds(workspace, sessions, archivedSessionIds, orderBy) {
2781
+ const ids = visibleSessionIds(workspace, sessions, archivedSessionIds);
2782
+ if (orderBy !== "updated") return ids;
2783
+ return [...ids].sort((a, b) => {
2784
+ const left = sessions.byId[a];
2785
+ const right = sessions.byId[b];
2786
+ return byRecency({
2787
+ id: a,
2788
+ updatedAt: left?.updatedAt ?? Number.NEGATIVE_INFINITY
2789
+ }, {
2790
+ id: b,
2791
+ updatedAt: right?.updatedAt ?? Number.NEGATIVE_INFINITY
2792
+ });
2793
+ });
2794
+ }
2795
+ /**
2796
+ * Flat session list ("In one list"): every visible session as a top-level
2797
+ * row. `updated` is newest-first; `manual` keeps the session-list stored order.
2798
+ */
2799
+ function deriveFlat(list, archivedSessionIds, orderBy = "updated") {
2800
+ const archived = new Set(archivedSessionIds);
2801
+ const descendants = indexSubagentRunning(list.byId);
2802
+ const rows = [];
2803
+ for (const id of list.ids) {
2804
+ const summary = list.byId[id];
2805
+ if (summary === void 0) continue;
2806
+ if (summary.origin === "subagent") continue;
2807
+ if (archived.has(id)) continue;
2808
+ if (summary.blank && id !== list.current) continue;
2809
+ rows.push(summary);
2810
+ }
2811
+ if (orderBy === "updated") rows.sort((a, b) => byRecency({
2812
+ id: a.id,
2813
+ updatedAt: a.updatedAt ?? 0
2814
+ }, {
2815
+ id: b.id,
2816
+ updatedAt: b.updatedAt ?? 0
2817
+ }));
2818
+ return rows.map((session) => sessionNode(session, descendants));
2819
+ }
2820
+ /** Display label for the ungrouped bucket row. */
2821
+ const UNGROUPED_LABEL = "Ungrouped";
2822
+ /**
2823
+ * Directory display label: basename of the path (both separators accepted).
2824
+ * Ungrouped-bucket fallback for surfaces without a workspace title.
2825
+ */
2826
+ function workspaceLabel(cwd) {
2827
+ if (cwd === void 0 || cwd === "") return UNGROUPED_LABEL;
2828
+ const base = cwd.replace(/[/\\]+$/, "").split(/[/\\]/).pop();
2829
+ return base !== void 0 && base !== "" ? base : cwd;
2830
+ }
2831
+ /**
2832
+ * Keep controlled input and RPC payload inside the session.search wire
2833
+ * contract: strip NULs, cap at 500 UTF-16 code units, and never split a
2834
+ * surrogate pair at the cut.
2835
+ */
2836
+ function sanitizeSearchQuery(value) {
2837
+ const withoutNul = value.replaceAll("\0", "");
2838
+ if (withoutNul.length <= 500) return withoutNul;
2839
+ let end = 500;
2840
+ const last = withoutNul.charCodeAt(end - 1);
2841
+ const next = withoutNul.charCodeAt(end);
2842
+ if (last >= 55296 && last <= 56319 && next >= 56320 && next <= 57343) end -= 1;
2843
+ return withoutNul.slice(0, end);
2844
+ }
2845
+ /**
2846
+ * Compact relative time for session rows, as a structured bucket the
2847
+ * renderer localizes ("now"/"5min"/"3h"/"2d"/"4mo"/"1y" in en).
2848
+ */
2849
+ function relativeTime(updatedAt, now) {
2850
+ const MIN = 6e4;
2851
+ const HOUR = 36e5;
2852
+ const DAY = 864e5;
2853
+ const diff = Math.max(0, now - updatedAt);
2854
+ if (diff < MIN) return {
2855
+ unit: "now",
2856
+ n: 0
2857
+ };
2858
+ if (diff < HOUR) return {
2859
+ unit: "minutes",
2860
+ n: Math.floor(diff / MIN)
2861
+ };
2862
+ if (diff < DAY) return {
2863
+ unit: "hours",
2864
+ n: Math.floor(diff / HOUR)
2865
+ };
2866
+ if (diff < 30 * DAY) return {
2867
+ unit: "days",
2868
+ n: Math.floor(diff / DAY)
2869
+ };
2870
+ if (diff < 365 * DAY) return {
2871
+ unit: "months",
2872
+ n: Math.floor(diff / (30 * DAY))
2873
+ };
2874
+ return {
2875
+ unit: "years",
2876
+ n: Math.floor(diff / (365 * DAY))
2877
+ };
2878
+ }
2879
+ /** Localized compact relative time ("刚刚"/"5分钟" in zh, "now"/"5min" in en). */
2880
+ function timeLabel(updatedAt, now, t) {
2881
+ const { unit, n } = relativeTime(updatedAt, now);
2882
+ if (unit === "now") return t("time.now");
2883
+ if (unit === "minutes") return t("time.minutes", { n });
2884
+ if (unit === "hours") return t("time.hours", { n });
2885
+ if (unit === "days") return t("time.days", { n });
2886
+ if (unit === "months") return t("time.months", { n });
2887
+ return t("time.years", { n });
2888
+ }
2889
+ /** Hover-card variant: distances wrap in the ago template; the now bucket stays bare. */
2890
+ function hoverTimeLabel(updatedAt, now, t) {
2891
+ const { unit, n } = relativeTime(updatedAt, now);
2892
+ if (unit === "now") return t("time.now");
2893
+ return t("time.ago", { t: unit === "minutes" ? t("time.minutes", { n }) : unit === "hours" ? t("time.hours", { n }) : unit === "days" ? t("time.days", { n }) : unit === "months" ? t("time.months", { n }) : t("time.years", { n }) });
2894
+ }
2895
+ /**
2896
+ * Absolute creation time through the dictionary's date template (the message
2897
+ * clock pattern): `toLocaleString` would follow the browser language, not the
2898
+ * app locale.
2899
+ */
2900
+ function createdLabel(createdAt, t) {
2901
+ const d = new Date(createdAt);
2902
+ const pad2 = (v) => String(v).padStart(2, "0");
2903
+ return t("hover.created", { time: `${t("date.ymd", {
2904
+ y: d.getFullYear(),
2905
+ m: d.getMonth() + 1,
2906
+ d: d.getDate()
2907
+ })} ${pad2(d.getHours())}:${pad2(d.getMinutes())}` });
2908
+ }
2909
+ /** Ordinary sessions are visible; among blanks, only the current one. */
2910
+ function sessionVisible(session, current, archived) {
2911
+ return session.origin !== "subagent" && !archived.has(session.id) && (!session.blank || session.id === current);
2912
+ }
2913
+ /**
2914
+ * Merge immediate title/Workspace substring matches with ranked Host content
2915
+ * matches. Local rows lead newest-first, content-only rows retain backend
2916
+ * order, and duplicate sessions receive the backend snippet in place.
2917
+ */
2918
+ function deriveSearchResults(list, workspaces, query, archivedSessionIds, content, limit) {
2919
+ const q = query.trim().toLowerCase();
2920
+ if (q === "") return {
2921
+ items: [],
2922
+ hasMore: false
2923
+ };
2924
+ const archived = new Set(archivedSessionIds);
2925
+ const descendants = indexSubagentRunning(list.byId);
2926
+ const workspaceBySession = /* @__PURE__ */ new Map();
2927
+ for (const workspace of workspaces) for (const sessionId of workspace.sessionIds) if (!workspaceBySession.has(sessionId)) workspaceBySession.set(sessionId, workspace.title);
2928
+ const labelOf = (summary) => workspaceBySession.get(summary.id) ?? workspaceLabel(summary.cwd);
2929
+ const contentBySession = /* @__PURE__ */ new Map();
2930
+ for (const item of content.items) if (!contentBySession.has(item.sessionId)) contentBySession.set(item.sessionId, item);
2931
+ const local = [];
2932
+ for (const id of list.ids) {
2933
+ const summary = list.byId[id];
2934
+ if (summary === void 0 || summary.blank || !sessionVisible(summary, list.current, archived)) continue;
2935
+ if (sessionTitle(summary).toLowerCase().includes(q) || labelOf(summary).toLowerCase().includes(q)) local.push(summary);
2936
+ }
2937
+ local.sort((a, b) => byRecency({
2938
+ id: a.id,
2939
+ updatedAt: a.updatedAt ?? 0
2940
+ }, {
2941
+ id: b.id,
2942
+ updatedAt: b.updatedAt ?? 0
2943
+ }));
2944
+ const ordered = [];
2945
+ const included = /* @__PURE__ */ new Set();
2946
+ const include = (summary) => {
2947
+ if (included.has(summary.id)) return;
2948
+ included.add(summary.id);
2949
+ ordered.push(summary);
2950
+ };
2951
+ for (const summary of local) include(summary);
2952
+ for (const item of content.items) {
2953
+ const summary = list.byId[item.sessionId];
2954
+ if (summary !== void 0 && !summary.blank && sessionVisible(summary, list.current, archived)) include(summary);
2955
+ }
2956
+ return {
2957
+ items: ordered.slice(0, limit).map((summary) => {
2958
+ const match = contentBySession.get(summary.id);
2959
+ const node = sessionNode(summary, descendants);
2960
+ return {
2961
+ id: node.id,
2962
+ title: node.title,
2963
+ workspace: labelOf(summary),
2964
+ running: node.running,
2965
+ runningSubagentCount: node.runningSubagentCount,
2966
+ completed: node.completed,
2967
+ ...summary.pendingInteraction === void 0 ? {} : { pendingInteraction: summary.pendingInteraction },
2968
+ ...match === void 0 ? {} : { snippet: match.snippet }
2969
+ };
2970
+ }),
2971
+ hasMore: content.hasMore || ordered.length > limit
2972
+ };
2973
+ }
2974
+ //#endregion
2975
+ //#region node_modules/.pnpm/@deepseek-ai+dsh-util-works_bc29eb1f35b7b23a837010aec86eeb5e/node_modules/@deepseek-ai/dsh-util-workspace-path/lib/index.js
2976
+ /**
2977
+ * Browser-safe Workspace path and display helpers.
2978
+ * @module @deepseek-ai/dsh-util-workspace-path
2979
+ */
2980
+ /** Whether a path uses a Windows drive or UNC prefix. */
2981
+ function isWindowsStylePath(value) {
2982
+ return /^[A-Za-z]:[/\\]/.test(value) || value.startsWith("\\\\");
2983
+ }
2984
+ /**
2985
+ * Abbreviate a POSIX home directory for display.
2986
+ * @param path - Absolute or already-short display path.
2987
+ * @param home - Host account home; absent skips abbreviation.
2988
+ * @returns `~` or `~/…` for the POSIX home and its descendants, otherwise `path`.
2989
+ */
2990
+ function abbreviateHomePath(path, home) {
2991
+ if (home === void 0 || home === "") return path;
2992
+ if (isWindowsStylePath(path) || isWindowsStylePath(home)) return path;
2993
+ const root = home.replace(/\/+$/, "");
2994
+ if (root === "" || root === "/") return path;
2995
+ if (path.replace(/\/+$/, "") === root) return "~";
2996
+ if (path.startsWith(`${root}/`)) return `~${path.slice(root.length)}`;
2997
+ return path;
2998
+ }
2999
+ //#endregion
3000
+ //#region \0git-worktree-css:C:\Users\OYW\.dsh\gitworktree\dsh-worktree-origin-feature-0.1.2-alpha.3\src\client\sidebar-rows.module.css?inline
3001
+ const css$1 = "/* Native Rows.module_73286170.css_73286170 transplanted 1:1 (DSW tokens, row-in, reduced-motion).\n * Drag marker classes (dropBefore/dropAfter) are kept for P3; unused in P2. */\n\n.projectRow_73286170,\n.sessionRow_73286170 {\n cursor: pointer;\n user-select: none;\n color: var(--dsw-alias-label-primary);\n border-radius: 8px;\n align-items: center;\n gap: 6px;\n padding: 0 8px;\n display: flex;\n}\n\n.projectRow_73286170:hover,\n.sessionRow_73286170:hover,\n.sessionRow_73286170.selected_73286170 {\n background: var(--dsw-alias-interactive-bg-hover);\n}\n\n.searchResultRow_73286170 {\n box-sizing: border-box;\n cursor: pointer;\n text-align: left;\n width: 100%;\n min-height: 48px;\n color: var(--dsw-alias-label-primary);\n background: 0 0;\n border: none;\n border-radius: 8px;\n flex-direction: column;\n align-items: stretch;\n padding: 4px 8px;\n display: flex;\n}\n\n.searchResultRow_73286170:hover,\n.searchResultRow_73286170.selected_73286170 {\n background: var(--dsw-alias-interactive-bg-hover);\n}\n\n.searchResultHeading_73286170 {\n align-items: center;\n min-width: 0;\n display: flex;\n}\n\n.searchResultTitle_73286170 {\n text-overflow: ellipsis;\n white-space: nowrap;\n min-width: 0;\n margin-left: 4px;\n font-size: 14px;\n line-height: 20px;\n overflow: hidden;\n}\n\n.searchResultMeta_73286170 {\n align-items: center;\n gap: 6px;\n min-width: 0;\n margin-left: 20px;\n display: flex;\n}\n\n.searchResultWorkspace_73286170,\n.searchResultSnippet_73286170 {\n text-overflow: ellipsis;\n white-space: nowrap;\n font-size: 12px;\n line-height: 17px;\n overflow: hidden;\n}\n\n.searchResultWorkspace_73286170 {\n max-width: 40%;\n color: var(--dsw-alias-label-tertiary);\n flex: none;\n}\n\n.searchResultSnippet_73286170 {\n min-width: 0;\n color: var(--dsw-alias-label-secondary);\n flex: 1;\n}\n\n.projectRow_73286170 {\n box-sizing: border-box;\n align-items: center;\n height: 34px;\n}\n\n.projectRow_73286170 .rowActions_73286170 {\n height: 20px;\n}\n\n.sessionRow_73286170 {\n height: 32px;\n animation: row-in 0.15s var(--ds-ease-in-out);\n gap: 0;\n}\n\n.sessionRow_73286170 .title_73286170 {\n margin: 0 6px 0 4px;\n}\n\n.flatSessionRowWithoutStatus_73286170 .title_73286170 {\n margin-left: 0;\n}\n\n@keyframes row-in {\n 0% { opacity: 0; }\n}\n\n.slot_73286170 {\n width: 16px;\n height: 20px;\n color: var(--dsw-alias-label-tertiary);\n flex: none;\n justify-content: center;\n align-items: center;\n display: inline-flex;\n}\n\n.visuallyHidden_73286170 {\n clip: rect(0 0 0 0);\n white-space: nowrap;\n width: 1px;\n height: 1px;\n position: absolute;\n overflow: hidden;\n}\n\n.folderActive_73286170 {\n color: var(--dsw-alias-state-business-primary);\n}\n\n.projectRow_73286170 .chevron_73286170 {\n display: none;\n}\n\n.projectRow_73286170:hover .chevron_73286170 {\n display: inline-flex;\n}\n\n.projectRow_73286170:hover .folder_73286170 {\n display: none;\n}\n\n.arrow_73286170 {\n transition: transform 0.15s var(--ds-ease-in-out);\n}\n\n.arrowOpen_73286170 {\n transform: rotate(90deg);\n}\n\n.projectText_73286170 {\n flex-direction: column;\n flex: 1;\n gap: 2px;\n min-width: 0;\n display: flex;\n}\n\n.title_73286170 {\n text-overflow: ellipsis;\n white-space: nowrap;\n min-width: 0;\n font-size: 14px;\n line-height: 20px;\n overflow: hidden;\n}\n\n.renameInput_73286170 {\n border: 1px solid var(--dsw-alias-border-l2);\n background: var(--dsw-alias-button-elevated-fill);\n min-width: 0;\n color: inherit;\n border-radius: 4px;\n outline: none;\n padding: 0 2px;\n font-size: 14px;\n line-height: 20px;\n}\n\n.sessionRow_73286170 .title_73286170 {\n flex: 1;\n}\n\n.meta_73286170 {\n text-overflow: ellipsis;\n white-space: nowrap;\n color: var(--dsw-alias-label-tertiary);\n font-size: 12px;\n line-height: 20px;\n overflow: hidden;\n}\n\n.time_73286170 {\n color: var(--dsw-alias-label-tertiary);\n flex: none;\n font-size: 12px;\n line-height: 20px;\n}\n\n.dot_73286170 {\n flex: none;\n}\n\n.rowActions_73286170 {\n flex: none;\n align-items: center;\n gap: 12px;\n display: none;\n}\n\n.projectRow_73286170:hover .rowActions_73286170,\n.sessionRow_73286170:hover .rowActions_73286170,\n.projectRow_73286170.menuOpen_73286170 .rowActions_73286170,\n.sessionRow_73286170.menuOpen_73286170 .rowActions_73286170 {\n display: inline-flex;\n}\n\n.sessionRow_73286170:hover .time_73286170,\n.sessionRow_73286170.menuOpen_73286170 .time_73286170 {\n display: none;\n}\n\n.projectRow_73286170.menuOpen_73286170,\n.sessionRow_73286170.menuOpen_73286170 {\n background: var(--dsw-alias-interactive-bg-hover);\n}\n\n/* P3: session drag insertion markers (unused in P2). */\n.sessionRow_73286170.dropBefore_73286170,\n.sessionRow_73286170.dropAfter_73286170 {\n position: relative;\n}\n\n.sessionRow_73286170.dropBefore_73286170:before,\n.sessionRow_73286170.dropAfter_73286170:after {\n content: \"\";\n z-index: 1;\n background:\n linear-gradient(55deg, transparent calc(50% - 1px), var(--dsw-alias-state-business-primary) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)) 0 0 / 5px 7px no-repeat,\n linear-gradient(125deg, transparent calc(50% - 1px), var(--dsw-alias-state-business-primary) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)) 0 5px / 5px 7px no-repeat,\n linear-gradient(var(--dsw-alias-state-business-primary) 0 0) 4px 5px / calc(100% - 4px) 2px no-repeat;\n pointer-events: none;\n height: 12px;\n position: absolute;\n left: 0;\n right: 4px;\n}\n\n.sessionRow_73286170.dropBefore_73286170:before {\n top: -7px;\n}\n\n.sessionRow_73286170.dropAfter_73286170:after {\n bottom: -7px;\n}\n\n.hoverContent_73286170 {\n flex-direction: column;\n gap: 8px;\n display: flex;\n}\n\n.hoverTitle_73286170 {\n color: #fff;\n overflow-wrap: break-word;\n font-size: 14px;\n line-height: 20px;\n}\n\n.hoverPath_73286170 {\n color: #cfd3d6;\n word-break: break-all;\n font-size: 12px;\n line-height: 16px;\n}\n\n.hoverTime_73286170 {\n color: #cfd3d6;\n font-size: 12px;\n line-height: 16px;\n}\n\n.hoverStatus_73286170 {\n color: #adb2b8;\n align-items: center;\n gap: 8px;\n font-size: 12px;\n line-height: 20px;\n display: flex;\n}\n\n.iconButton_73286170 {\n cursor: pointer;\n width: 16px;\n height: 16px;\n color: var(--dsw-alias-label-tertiary);\n background: 0 0;\n border: none;\n border-radius: 4px;\n flex: none;\n justify-content: center;\n align-items: center;\n padding: 0;\n display: inline-flex;\n}\n\n.iconButton_73286170:hover {\n color: var(--dsw-alias-label-primary);\n}\n\n.chevron_73286170 {\n color: var(--dsw-alias-label-caption);\n}\n\n.repoCount_73286170 {\n flex: none;\n margin-left: 8px;\n color: var(--dsw-alias-label-tertiary);\n font-size: 12px;\n line-height: 20px;\n}\n\n@media (prefers-reduced-motion: reduce) {\n .sessionRow_73286170,\n .arrow_73286170 {\n transition: none;\n animation: none;\n }\n}\n";
3002
+ const tagId$1 = "@laoyuehanni/dsh-git-worktree/sidebar-rows.module.css";
3003
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=\"" + tagId$1 + "\"]") === null) {
3004
+ const tag = document.createElement("style");
3005
+ tag.dataset.plugin = "@laoyuehanni/dsh-git-worktree";
3006
+ tag.dataset.pluginCss = tagId$1;
3007
+ tag.textContent = css$1;
3008
+ document.head.appendChild(tag);
3009
+ }
3010
+ var sidebar_rows_module_default = {
3011
+ "module": "module_73286170",
3012
+ "css": "css_73286170",
3013
+ "projectRow": "projectRow_73286170",
3014
+ "sessionRow": "sessionRow_73286170",
3015
+ "selected": "selected_73286170",
3016
+ "searchResultRow": "searchResultRow_73286170",
3017
+ "searchResultHeading": "searchResultHeading_73286170",
3018
+ "searchResultTitle": "searchResultTitle_73286170",
3019
+ "searchResultMeta": "searchResultMeta_73286170",
3020
+ "searchResultWorkspace": "searchResultWorkspace_73286170",
3021
+ "searchResultSnippet": "searchResultSnippet_73286170",
3022
+ "rowActions": "rowActions_73286170",
3023
+ "title": "title_73286170",
3024
+ "flatSessionRowWithoutStatus": "flatSessionRowWithoutStatus_73286170",
3025
+ "slot": "slot_73286170",
3026
+ "visuallyHidden": "visuallyHidden_73286170",
3027
+ "folderActive": "folderActive_73286170",
3028
+ "chevron": "chevron_73286170",
3029
+ "folder": "folder_73286170",
3030
+ "arrow": "arrow_73286170",
3031
+ "arrowOpen": "arrowOpen_73286170",
3032
+ "projectText": "projectText_73286170",
3033
+ "renameInput": "renameInput_73286170",
3034
+ "meta": "meta_73286170",
3035
+ "time": "time_73286170",
3036
+ "dot": "dot_73286170",
3037
+ "menuOpen": "menuOpen_73286170",
3038
+ "dropBefore": "dropBefore_73286170",
3039
+ "dropAfter": "dropAfter_73286170",
3040
+ "hoverContent": "hoverContent_73286170",
3041
+ "hoverTitle": "hoverTitle_73286170",
3042
+ "hoverPath": "hoverPath_73286170",
3043
+ "hoverTime": "hoverTime_73286170",
3044
+ "hoverStatus": "hoverStatus_73286170",
3045
+ "iconButton": "iconButton_73286170",
3046
+ "repoCount": "repoCount_73286170"
3047
+ };
3048
+ //#endregion
3049
+ //#region src/client/sidebar-rows.tsx
3050
+ /**
3051
+ * Workspace / session / search row components transplanted from the native
3052
+ * `Rows.js` (injected props, no ctx). Hover swaps (folder→chevron, time→⋯)
3053
+ * are CSS-only. Drag wiring is intentionally omitted — P3.
3054
+ *
3055
+ * @module git-worktree/client/sidebar-rows
3056
+ */
3057
+ function cx$1(...parts) {
3058
+ return parts.filter((part) => typeof part === "string" && part !== "").join(" ");
3059
+ }
3060
+ /** Row display title: blank rows show the localized New Session label. */
3061
+ function displayTitle(node, t) {
3062
+ return node.blank ? t("session.new") : node.title;
3063
+ }
3064
+ /** Hover-card body: workspace title, display directory path, absolute creation time. */
3065
+ function WorkspaceHoverContent({ label, cwd, createdAt, t }) {
3066
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3067
+ className: sidebar_rows_module_default.hoverContent,
3068
+ children: [
3069
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3070
+ className: sidebar_rows_module_default.hoverTitle,
3071
+ children: label
3072
+ }),
3073
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3074
+ className: sidebar_rows_module_default.hoverPath,
3075
+ children: cwd
3076
+ }),
3077
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3078
+ className: sidebar_rows_module_default.hoverTime,
3079
+ children: createdLabel(createdAt, t)
3080
+ })
3081
+ ]
3082
+ });
3083
+ }
3084
+ /**
3085
+ * Project (workspace) header row: folder + title; hover reveals the chevron
3086
+ * and create button. `containsCurrent` is a derivation fact (no renderer scan).
3087
+ * Drag wiring is not transplanted (P3 — `useNativeDragAcceptance` stays vacant).
3088
+ */
3089
+ function ProjectRowItem({ row, onToggle, onCreate, actions, home, t, badge }) {
3090
+ const active = row.expanded && row.containsCurrent;
3091
+ const [menuOpen, setMenuOpen] = (0, react.useState)(false);
3092
+ const workspaceMenuItems = [{
3093
+ id: "rename",
3094
+ label: t("rename"),
3095
+ icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconEditOutline16, {})
3096
+ }, {
3097
+ id: "delete",
3098
+ label: t("delete.workspace"),
3099
+ icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconTrashOutline16, {}),
3100
+ danger: true
3101
+ }];
3102
+ const ownRow = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3103
+ className: cx$1(sidebar_rows_module_default.projectRow, menuOpen && sidebar_rows_module_default.menuOpen),
3104
+ role: "treeitem",
3105
+ "aria-expanded": row.expanded,
3106
+ onClick: onToggle,
3107
+ children: [
3108
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3109
+ className: cx$1(sidebar_rows_module_default.slot, sidebar_rows_module_default.folder, active && sidebar_rows_module_default.folderActive),
3110
+ children: row.expanded ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconFolderOpen16, {}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconFolderClose16, {})
3111
+ }),
3112
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3113
+ className: cx$1(sidebar_rows_module_default.slot, sidebar_rows_module_default.chevron),
3114
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconTriangleRightFill14, { className: cx$1(sidebar_rows_module_default.arrow, row.expanded && sidebar_rows_module_default.arrowOpen) })
3115
+ }),
3116
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3117
+ className: sidebar_rows_module_default.projectText,
3118
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3119
+ className: sidebar_rows_module_default.title,
3120
+ children: row.label
3121
+ })
3122
+ }),
3123
+ badge !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3124
+ className: sidebar_rows_module_default.repoCount,
3125
+ children: badge
3126
+ }) : null,
3127
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
3128
+ className: sidebar_rows_module_default.rowActions,
3129
+ children: [actions !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Menu, {
3130
+ open: menuOpen,
3131
+ onClose: () => {
3132
+ setMenuOpen(false);
3133
+ },
3134
+ items: workspaceMenuItems,
3135
+ onSelect: (id) => {
3136
+ setMenuOpen(false);
3137
+ if (id !== "rename" && id !== "delete") return;
3138
+ if (id === "rename") actions.rename();
3139
+ else actions.delete();
3140
+ },
3141
+ portal: true,
3142
+ closeOnPointerLeave: true,
3143
+ anchor: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
3144
+ type: "button",
3145
+ className: sidebar_rows_module_default.iconButton,
3146
+ "aria-label": t("actions.workspace.aria", { name: row.label }),
3147
+ onClick: (e) => {
3148
+ e.stopPropagation();
3149
+ setMenuOpen((v) => !v);
3150
+ },
3151
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconEllipsisOutline16, {})
3152
+ })
3153
+ }), onCreate !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
3154
+ type: "button",
3155
+ className: sidebar_rows_module_default.iconButton,
3156
+ "aria-label": t("actions.newSession.aria", { name: row.label }),
3157
+ onClick: (e) => {
3158
+ e.stopPropagation();
3159
+ onCreate();
3160
+ },
3161
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconPlusOutline16, {})
3162
+ })]
3163
+ })
3164
+ ]
3165
+ });
3166
+ if (row.createdAt === void 0) return ownRow;
3167
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.HoverCard, {
3168
+ anchor: ownRow,
3169
+ content: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WorkspaceHoverContent, {
3170
+ label: row.label,
3171
+ cwd: row.cwd === void 0 ? void 0 : abbreviateHomePath(row.cwd, home),
3172
+ createdAt: row.createdAt,
3173
+ t
3174
+ }),
3175
+ disabled: menuOpen,
3176
+ copyText: row.cwd,
3177
+ copyLabel: t("copy"),
3178
+ copiedLabel: t("hover.copied")
3179
+ });
3180
+ }
3181
+ function assertNever(value) {
3182
+ throw new Error(`unknown pending interaction: ${String(value)}`);
3183
+ }
3184
+ /** Session status presentation; pending interaction is primary and live activity outranks completion. */
3185
+ function sessionStatuses(node, t) {
3186
+ const subagents = node.runningSubagentCount === 0 ? void 0 : {
3187
+ state: "ongoing",
3188
+ label: t(node.runningSubagentCount === 1 ? "status.subagentsRunning.one" : "status.subagentsRunning.other", { n: node.runningSubagentCount })
3189
+ };
3190
+ let pending;
3191
+ switch (node.pendingInteraction) {
3192
+ case "approval":
3193
+ pending = {
3194
+ state: "warning",
3195
+ label: t("status.waitingApproval")
3196
+ };
3197
+ break;
3198
+ case "plan-review":
3199
+ pending = {
3200
+ state: "warning",
3201
+ label: t("status.planReview")
3202
+ };
3203
+ break;
3204
+ case "question":
3205
+ pending = {
3206
+ state: "warning",
3207
+ label: t("status.waitingAnswer")
3208
+ };
3209
+ break;
3210
+ case void 0: break;
3211
+ default: return assertNever(node.pendingInteraction);
3212
+ }
3213
+ if (pending !== void 0) return subagents === void 0 ? [pending] : [pending, subagents];
3214
+ if (node.running) {
3215
+ const primary = {
3216
+ state: "ongoing",
3217
+ label: t("status.running")
3218
+ };
3219
+ return subagents === void 0 ? [primary] : [primary, subagents];
3220
+ }
3221
+ if (subagents !== void 0) return [subagents];
3222
+ if (node.completed) return [{
3223
+ state: "done",
3224
+ label: t("status.completed")
3225
+ }];
3226
+ return [{
3227
+ state: "done",
3228
+ label: t("status.idle")
3229
+ }];
3230
+ }
3231
+ /** Primary status dot plus every status's screen-reader label. */
3232
+ function SessionStatusDots({ statuses }) {
3233
+ const primary = statuses[0];
3234
+ if (primary === void 0) return null;
3235
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.StateDot, { state: primary.state }), statuses.map((status) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3236
+ className: sidebar_rows_module_default.visuallyHidden,
3237
+ children: status.label
3238
+ }, status.label))] });
3239
+ }
3240
+ /** Hover-card body: full title, relative time, and every relevant live status. */
3241
+ function SessionHoverContent({ node, now, t }) {
3242
+ const statuses = sessionStatuses(node, t);
3243
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3244
+ className: sidebar_rows_module_default.hoverContent,
3245
+ children: [
3246
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3247
+ className: sidebar_rows_module_default.hoverTitle,
3248
+ children: displayTitle(node, t)
3249
+ }),
3250
+ !node.blank && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3251
+ className: sidebar_rows_module_default.hoverTime,
3252
+ children: hoverTimeLabel(node.updatedAt, now, t)
3253
+ }),
3254
+ statuses.map((status) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3255
+ className: sidebar_rows_module_default.hoverStatus,
3256
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.StateDot, { state: status.state }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: status.label })]
3257
+ }, status.label))
3258
+ ]
3259
+ });
3260
+ }
3261
+ /** One flat search result: title, Workspace context, and optional content excerpt. */
3262
+ function SearchResultItem({ result, currentId, onOpen, t }) {
3263
+ const selected = result.id === currentId;
3264
+ const statuses = sessionStatuses(result, t);
3265
+ const primaryStatus = statuses[0];
3266
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
3267
+ type: "button",
3268
+ className: cx$1(sidebar_rows_module_default.searchResultRow, selected && sidebar_rows_module_default.selected),
3269
+ role: "treeitem",
3270
+ "aria-selected": selected,
3271
+ onClick: () => {
3272
+ onOpen(result.id);
3273
+ },
3274
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
3275
+ className: sidebar_rows_module_default.searchResultHeading,
3276
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3277
+ className: sidebar_rows_module_default.slot,
3278
+ children: primaryStatus !== void 0 && (primaryStatus.state !== "done" || result.completed) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SessionStatusDots, { statuses })
3279
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3280
+ className: sidebar_rows_module_default.searchResultTitle,
3281
+ children: result.title
3282
+ })]
3283
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
3284
+ className: sidebar_rows_module_default.searchResultMeta,
3285
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3286
+ className: sidebar_rows_module_default.searchResultWorkspace,
3287
+ children: result.workspace
3288
+ }), result.snippet !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3289
+ className: sidebar_rows_module_default.searchResultSnippet,
3290
+ children: result.snippet
3291
+ })]
3292
+ })]
3293
+ });
3294
+ }
3295
+ /**
3296
+ * One 32px session row: status dot, title, relative time, hover ⋯ menu.
3297
+ * Drag wiring is not transplanted (P3).
3298
+ */
3299
+ function SessionNodeItem({ node, currentId, now, onOpen, onRename, onFork, onArchive, flat = false, t }) {
3300
+ const title = displayTitle(node, t);
3301
+ const selected = node.id === currentId;
3302
+ const statuses = sessionStatuses(node, t);
3303
+ const showStatus = statuses[0]?.state !== "done" || node.completed;
3304
+ const [menuOpen, setMenuOpen] = (0, react.useState)(false);
3305
+ const sessionMenuItems = [
3306
+ {
3307
+ id: "rename",
3308
+ label: t("rename"),
3309
+ icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconEditOutline16, {})
3310
+ },
3311
+ {
3312
+ id: "fork",
3313
+ label: t("menu.fork"),
3314
+ icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconBranchOutline16, {})
3315
+ },
3316
+ {
3317
+ id: "archive",
3318
+ label: t("menu.archiveSession"),
3319
+ icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconArchiveOutline20, { size: 16 })
3320
+ }
3321
+ ];
3322
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.HoverCard, {
3323
+ anchor: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3324
+ className: cx$1(sidebar_rows_module_default.sessionRow, selected && sidebar_rows_module_default.selected, menuOpen && sidebar_rows_module_default.menuOpen, flat && !showStatus && sidebar_rows_module_default.flatSessionRowWithoutStatus),
3325
+ role: "treeitem",
3326
+ "aria-selected": selected,
3327
+ onClick: () => {
3328
+ onOpen(node.id);
3329
+ },
3330
+ children: [
3331
+ (!flat || showStatus) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3332
+ className: sidebar_rows_module_default.slot,
3333
+ children: showStatus && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SessionStatusDots, { statuses })
3334
+ }),
3335
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3336
+ className: sidebar_rows_module_default.title,
3337
+ children: title
3338
+ }),
3339
+ !node.blank && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3340
+ className: sidebar_rows_module_default.time,
3341
+ children: timeLabel(node.updatedAt, now, t)
3342
+ }),
3343
+ !node.blank && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3344
+ className: sidebar_rows_module_default.rowActions,
3345
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Menu, {
3346
+ open: menuOpen,
3347
+ onClose: () => {
3348
+ setMenuOpen(false);
3349
+ },
3350
+ items: sessionMenuItems,
3351
+ onSelect: (id) => {
3352
+ setMenuOpen(false);
3353
+ if (id === "rename") onRename(node.id, node.title);
3354
+ if (id === "fork") onFork(node.id);
3355
+ if (id === "archive") onArchive(node.id);
3356
+ },
3357
+ portal: true,
3358
+ closeOnPointerLeave: true,
3359
+ anchor: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
3360
+ type: "button",
3361
+ className: sidebar_rows_module_default.iconButton,
3362
+ "aria-label": t("actions.session.aria", { name: title }),
3363
+ onClick: (e) => {
3364
+ e.stopPropagation();
3365
+ setMenuOpen((v) => !v);
3366
+ },
3367
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconEllipsisOutline16, {})
3368
+ })
3369
+ })
3370
+ })
3371
+ ]
3372
+ }),
3373
+ content: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SessionHoverContent, {
3374
+ node,
3375
+ now,
3376
+ t
3377
+ }),
3378
+ disabled: menuOpen,
3379
+ copyText: node.blank ? void 0 : node.title,
3380
+ copyLabel: t("copy"),
3381
+ copiedLabel: t("hover.copied")
3382
+ });
3383
+ }
3384
+ //#endregion
3385
+ //#region src/client/pick-flow.ts
3386
+ /**
3387
+ * Edge-triggered controller for one add-workspace flow.
3388
+ *
3389
+ * `sync(open)` mirrors the dialog's open flag: only a RISING edge (closed →
3390
+ * open) starts a pick — re-syncing `true` while a run is live is a no-op, so
3391
+ * the parent's re-renders (fresh inline callbacks and all) can never
3392
+ * re-launch the chooser or drop a finished pick the way an effect keyed on
3393
+ * unstable function deps would. A falling edge invalidates any in-flight
3394
+ * run: its eventual result is discarded without a callback. `kill()` is the
3395
+ * permanent teardown — nothing fires after it.
3396
+ */
3397
+ var PickFlowController = class {
3398
+ hooks;
3399
+ started = false;
3400
+ epoch = 0;
3401
+ /** Refresh the callbacks to the latest render's closures; never restarts a run. */
3402
+ attach(hooks) {
3403
+ this.hooks = hooks;
3404
+ }
3405
+ /** Sync with the dialog's open flag (see the class doc for the edge semantics). */
3406
+ sync(open) {
3407
+ if (open) {
3408
+ if (this.started) return;
3409
+ this.started = true;
3410
+ this.epoch += 1;
3411
+ this.run(this.epoch);
3412
+ return;
3413
+ }
3414
+ this.epoch += 1;
3415
+ this.started = false;
3416
+ }
3417
+ /** Permanent teardown (unmount): no callback fires afterwards. */
3418
+ kill() {
3419
+ this.epoch += 1;
3420
+ this.started = false;
3421
+ }
3422
+ async run(token) {
3423
+ const hooks = this.hooks;
3424
+ if (hooks === void 0) return;
3425
+ let path;
3426
+ try {
3427
+ path = await hooks.pickDirectory();
3428
+ } catch (reason) {
3429
+ if (token === this.epoch) hooks.onFailed(messageOf(reason));
3430
+ return;
3431
+ }
3432
+ if (token !== this.epoch) return;
3433
+ if (path === null || path === "") {
3434
+ hooks.onCancelled();
3435
+ return;
3436
+ }
3437
+ let workspace;
3438
+ try {
3439
+ workspace = await hooks.createWorkspace({ path });
3440
+ } catch (reason) {
3441
+ if (token === this.epoch) hooks.onFailed(messageOf(reason));
3442
+ return;
3443
+ }
3444
+ if (token !== this.epoch) return;
3445
+ hooks.onPicked(workspace.workspaceId);
3446
+ }
3447
+ };
3448
+ /** Error text for a rejection of any shape. */
3449
+ function messageOf(reason) {
3450
+ return reason instanceof Error ? reason.message : String(reason);
3451
+ }
3452
+ //#endregion
3453
+ //#region \0git-worktree-css:C:\Users\OYW\.dsh\gitworktree\dsh-worktree-origin-feature-0.1.2-alpha.3\src\client\GroupedSidebar.module.css?inline
3454
+ const css = "/* Native WorkspaceBrowser.module_108469306.css_108469306 + WorkspacePicker.module_108469306.css_108469306 transplanted\n * 1:1 (DSW tokens, search expand, reduced-motion). Drag classes\n * (workspaceDrop*, listTopDrop*) are kept for P3; unused in P2.\n * Overlay: memberIndent / sessionsIndent for the repo-grouped tree. */\n\n.root_108469306 {\n --dsh-session-list-edge-inset: var(--dsh-sidebar-inline-padding);\n --dsh-session-list-scrollbar-width: 8px;\n --dsh-session-list-scrollbar-offset: 2px;\n box-sizing: border-box;\n min-height: 0;\n padding-right: var(--dsh-session-list-edge-inset);\n flex-direction: column;\n flex: 1;\n display: flex;\n}\n\n.root_108469306.rail_108469306 {\n padding-right: 0;\n}\n\n.iconButton_108469306 {\n cursor: pointer;\n width: 28px;\n height: 28px;\n color: var(--dsw-alias-label-secondary);\n background: 0 0;\n border: none;\n border-radius: 50%;\n flex: none;\n justify-content: center;\n align-items: center;\n padding: 0;\n display: inline-flex;\n}\n\n.iconButton_108469306:hover {\n background: var(--dsw-alias-interactive-bg-hover);\n}\n\n.sectionHeader_108469306 {\n box-sizing: border-box;\n height: 36px;\n color: var(--dsw-alias-label-tertiary);\n border-radius: 12px;\n flex: none;\n justify-content: flex-end;\n align-items: center;\n gap: 4px;\n margin-bottom: 4px;\n padding-left: 4px;\n display: flex;\n overflow: hidden;\n}\n\n.root_108469306:not(.rail_108469306) .sectionHeader_108469306 {\n margin-top: 2px;\n margin-right: -4px;\n}\n\n.sectionLabel_108469306 {\n white-space: nowrap;\n opacity: 1;\n visibility: visible;\n min-width: 0;\n max-width: 45%;\n transition: max-width 0.18s var(--ds-ease-in-out), margin-right 0.18s var(--ds-ease-in-out), opacity 0.12s var(--ds-ease-in-out), transform 0.18s var(--ds-ease-in-out), visibility 0s linear;\n flex: none;\n line-height: 20px;\n overflow: hidden;\n}\n\n.sectionLabelHidden_108469306 {\n opacity: 0;\n visibility: hidden;\n max-width: 0;\n margin-right: -4px;\n transition-delay: 0s, 0s, 0s, 0s, 0.18s;\n transform: translate(-4px);\n}\n\n.searchSlot_108469306 {\n box-sizing: border-box;\n min-width: 0;\n max-width: 28px;\n transition: max-width 0.18s var(--ds-ease-in-out), padding-left 0.18s var(--ds-ease-in-out);\n flex: 1;\n align-items: center;\n margin-left: auto;\n padding-left: 0;\n display: flex;\n}\n\n.searchSlotExpanded_108469306 {\n max-width: 100%;\n padding-left: 0;\n}\n\n.headerActions_108469306 {\n opacity: 1;\n visibility: visible;\n max-width: 60px;\n transition: max-width 0.18s var(--ds-ease-in-out), opacity 0.12s var(--ds-ease-in-out), transform 0.18s var(--ds-ease-in-out), visibility 0s linear;\n flex: none;\n align-items: center;\n gap: 4px;\n display: flex;\n overflow: hidden;\n}\n\n.headerActionsHidden_108469306 {\n opacity: 0;\n visibility: hidden;\n pointer-events: none;\n max-width: 0;\n transition-delay: 0s, 0s, 0s, 0.18s;\n transform: translate(4px);\n}\n\n.search_108469306 {\n box-sizing: border-box;\n cursor: text;\n width: 100%;\n height: 28px;\n color: var(--dsw-alias-label-secondary);\n transition: width 0.18s var(--ds-ease-in-out), padding 0.18s var(--ds-ease-in-out), border-color 0.18s var(--ds-ease-in-out), background-color 0.18s var(--ds-ease-in-out);\n background: 0 0;\n border: none;\n border-radius: 50%;\n flex: none;\n align-items: center;\n gap: 0;\n margin: 0;\n padding: 0;\n display: flex;\n overflow: hidden;\n}\n\n.searchExpanded_108469306 {\n border: 1px solid var(--dsw-alias-border-l2);\n width: calc(100% + 4px);\n height: 30px;\n color: var(--dsw-alias-label-caption);\n background: 0 0;\n border-radius: 10px;\n margin-inline: -2px;\n padding: 0 4px 0 0;\n}\n\n.searchButton_108469306 {\n cursor: pointer;\n width: 28px;\n height: 28px;\n color: inherit;\n background: 0 0;\n border: none;\n border-radius: 50%;\n flex: none;\n justify-content: center;\n align-items: center;\n padding: 0;\n display: inline-flex;\n}\n\n.searchExpanded_108469306 .searchButton_108469306 {\n width: 28px;\n height: 30px;\n}\n\n.searchButton_108469306:hover {\n background: var(--dsw-alias-interactive-bg-hover);\n}\n\n.searchExpanded_108469306 .searchButton_108469306:hover {\n background: 0 0;\n}\n\n.searchInput_108469306 {\n opacity: 0;\n pointer-events: none;\n width: 0;\n min-width: 0;\n color: var(--dsw-alias-label-primary);\n transition: opacity 0.12s var(--ds-ease-in-out);\n background: 0 0;\n border: none;\n outline: none;\n flex: 1;\n font-size: 13px;\n line-height: 18px;\n}\n\n.searchExpanded_108469306 .searchInput_108469306 {\n opacity: 1;\n pointer-events: auto;\n margin-left: -2px;\n}\n\n.searchInput_108469306::placeholder {\n color: var(--dsw-alias-label-tertiary);\n}\n\n.clearButton_108469306 {\n cursor: pointer;\n width: 24px;\n height: 24px;\n color: var(--dsw-alias-label-secondary);\n background: 0 0;\n border: none;\n border-radius: 50%;\n flex: none;\n justify-content: center;\n align-items: center;\n padding: 0;\n display: inline-flex;\n}\n\n.clearButton_108469306:hover {\n background: var(--dsw-alias-interactive-bg-hover);\n}\n\n.rail_108469306 .sectionHeader_108469306 {\n justify-content: flex-start;\n gap: 0;\n margin-bottom: 12px;\n padding-left: 0;\n}\n\n.rail_108469306 .headerActions_108469306 {\n max-width: none;\n}\n\n.rail_108469306 .iconButton_108469306 {\n width: 36px;\n height: 36px;\n color: var(--dsw-alias-label-primary);\n}\n\n.rail_108469306 .search_108469306 {\n background: 0 0;\n border-color: #0000;\n gap: 0;\n width: 36px;\n height: 36px;\n margin: 0 0 12px;\n padding: 0;\n}\n\n.rail_108469306 .searchButton_108469306 {\n width: 36px;\n height: 36px;\n color: var(--dsw-alias-label-primary);\n}\n\n.rail_108469306 .searchButton_108469306:hover {\n background: var(--dsw-alias-interactive-bg-hover);\n}\n\n.listArea_108469306 {\n min-height: 0;\n margin-left: -4px;\n margin-right: calc(-1 * var(--dsh-session-list-edge-inset));\n flex-direction: column;\n flex: 1;\n padding-left: 4px;\n display: flex;\n overflow: visible;\n}\n\n.rail_108469306 .listArea_108469306 {\n margin-left: 0;\n margin-right: 0;\n padding-left: 0;\n}\n\n.treeBody_108469306 {\n flex-direction: column;\n flex: 1;\n min-height: 0;\n display: flex;\n position: relative;\n}\n\n.fade_108469306 {\n left: 0;\n right: var(--dsh-session-list-edge-inset);\n background: linear-gradient(to bottom, transparent, var(--dsw-specific-sidebar-fill));\n pointer-events: none;\n height: 24px;\n position: absolute;\n bottom: 0;\n}\n\n.wide_108469306 {\n animation: wide-in 0.2s var(--ds-ease-in-out);\n}\n\n@keyframes wide-in {\n 0% { opacity: 0; }\n}\n\n.list_108469306 {\n min-height: 0;\n margin-left: -4px;\n margin-right: var(--dsh-session-list-scrollbar-offset);\n padding-left: 4px;\n padding-right: calc(var(--dsh-session-list-edge-inset) - var(--dsh-session-list-scrollbar-width) - var(--dsh-session-list-scrollbar-offset));\n scrollbar-gutter: stable;\n flex: 1;\n padding-bottom: 16px;\n overflow-y: auto;\n}\n\n.flatList_108469306 > * + *,\n.searchTree_108469306 > [role=treeitem] + [role=treeitem],\n.groupSection_108469306 > * + * {\n margin-top: 2px;\n}\n\n.searchStatus_108469306,\n.searchWarning_108469306 {\n color: var(--dsw-alias-label-tertiary);\n padding: 10px 12px;\n font-size: 12px;\n line-height: 18px;\n}\n\n.searchWarning_108469306 {\n color: var(--dsw-alias-label-secondary);\n}\n\n.groupSection_108469306 {\n position: relative;\n}\n\n.groupSection_108469306 + .groupSection_108469306 {\n margin-top: 4px;\n}\n\n/* P3: workspace drag insertion markers (unused in P2). */\n.listTopDropIndicator_108469306,\n.workspaceDropBefore_108469306:before,\n.workspaceDropAfter_108469306:after {\n content: \"\";\n z-index: 1;\n background:\n linear-gradient(55deg, transparent calc(50% - 1px), var(--dsw-alias-state-business-primary) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)) 0 0 / 5px 7px no-repeat,\n linear-gradient(125deg, transparent calc(50% - 1px), var(--dsw-alias-state-business-primary) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)) 0 5px / 5px 7px no-repeat,\n linear-gradient(var(--dsw-alias-state-business-primary) 0 0) 4px 5px / calc(100% - 4px) 2px no-repeat;\n pointer-events: none;\n height: 12px;\n position: absolute;\n left: 0;\n right: 0;\n}\n\n.listTopDropIndicator_108469306 {\n top: -8px;\n left: 0;\n right: var(--dsh-session-list-edge-inset);\n}\n\n.listTopDropActive_108469306 > .workspaceDropBefore_108469306:first-child:before {\n display: none;\n}\n\n.workspaceDropBefore_108469306:before {\n top: -8px;\n}\n\n.workspaceDropAfter_108469306:after {\n bottom: -8px;\n}\n\n.sessionOverflowButton_108469306 {\n cursor: pointer;\n text-align: left;\n width: 100%;\n height: 28px;\n color: var(--dsw-alias-label-tertiary);\n background: 0 0;\n border: none;\n border-radius: 8px;\n padding: 0 12px 0 28px;\n font-size: 12px;\n}\n\n.groupSection_108469306 > .sessionOverflowButton_108469306 {\n margin-top: 0;\n}\n\n.sessionOverflowButton_108469306:hover {\n color: var(--dsw-alias-label-secondary);\n background: 0 0;\n}\n\n.empty_108469306 {\n color: var(--dsw-alias-label-tertiary);\n padding: 16px 12px;\n font-size: 13px;\n}\n\n.renameInput_108469306 {\n box-sizing: border-box;\n border: 1px solid var(--dsw-alias-border-l2);\n width: 100%;\n height: 44px;\n color: var(--dsw-alias-label-primary);\n background: 0 0;\n border-radius: 22px;\n outline: none;\n padding: 7px 14px;\n font-size: 14px;\n font-weight: 400;\n line-height: 22px;\n}\n\n.renameInput_108469306:disabled {\n color: var(--dsw-alias-label-dimmed);\n}\n\n.renameError_108469306 {\n color: var(--dsw-alias-state-error-primary);\n margin-top: 8px;\n font-size: 12px;\n line-height: 18px;\n}\n\n.deleteAction_108469306:not(:disabled) {\n color: var(--dsw-alias-state-error-primary);\n}\n\n.deleteStatus_108469306 {\n color: var(--dsw-alias-label-secondary);\n font-size: 12px;\n line-height: 18px;\n}\n\n.modalAction_108469306 {\n min-width: 72px;\n}\n\n.modalError_108469306,\n.menuStatus_108469306 {\n margin-top: 8px;\n font-size: 12px;\n line-height: 18px;\n}\n\n.modalError_108469306 {\n color: var(--dsw-alias-state-error-primary);\n}\n\n.menuStatus_108469306 {\n color: var(--dsw-alias-label-secondary);\n}\n\n/* Aggregation overlay: indent member workspaces and their sessions. */\n.memberIndent_108469306 {\n margin-left: 16px;\n}\n\n.sessionsIndent_108469306 {\n margin-left: 8px;\n}\n\n@media (prefers-reduced-motion: reduce) {\n .wide_108469306 {\n animation: none;\n }\n\n .search_108469306,\n .sectionLabel_108469306,\n .searchSlot_108469306,\n .searchInput_108469306,\n .headerActions_108469306 {\n transition: none;\n }\n}\n";
3455
+ const tagId = "@laoyuehanni/dsh-git-worktree/GroupedSidebar.module.css";
3456
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=\"" + tagId + "\"]") === null) {
3457
+ const tag = document.createElement("style");
3458
+ tag.dataset.plugin = "@laoyuehanni/dsh-git-worktree";
3459
+ tag.dataset.pluginCss = tagId;
3460
+ tag.textContent = css;
3461
+ document.head.appendChild(tag);
3462
+ }
3463
+ var GroupedSidebar_module_default = {
3464
+ "module": "module_108469306",
3465
+ "css": "css_108469306",
3466
+ "root": "root_108469306",
3467
+ "rail": "rail_108469306",
3468
+ "iconButton": "iconButton_108469306",
3469
+ "sectionHeader": "sectionHeader_108469306",
3470
+ "sectionLabel": "sectionLabel_108469306",
3471
+ "sectionLabelHidden": "sectionLabelHidden_108469306",
3472
+ "searchSlot": "searchSlot_108469306",
3473
+ "searchSlotExpanded": "searchSlotExpanded_108469306",
3474
+ "headerActions": "headerActions_108469306",
3475
+ "headerActionsHidden": "headerActionsHidden_108469306",
3476
+ "search": "search_108469306",
3477
+ "searchExpanded": "searchExpanded_108469306",
3478
+ "searchButton": "searchButton_108469306",
3479
+ "searchInput": "searchInput_108469306",
3480
+ "clearButton": "clearButton_108469306",
3481
+ "listArea": "listArea_108469306",
3482
+ "treeBody": "treeBody_108469306",
3483
+ "fade": "fade_108469306",
3484
+ "wide": "wide_108469306",
3485
+ "list": "list_108469306",
3486
+ "flatList": "flatList_108469306",
3487
+ "searchTree": "searchTree_108469306",
3488
+ "groupSection": "groupSection_108469306",
3489
+ "searchStatus": "searchStatus_108469306",
3490
+ "searchWarning": "searchWarning_108469306",
3491
+ "listTopDropIndicator": "listTopDropIndicator_108469306",
3492
+ "workspaceDropBefore": "workspaceDropBefore_108469306",
3493
+ "workspaceDropAfter": "workspaceDropAfter_108469306",
3494
+ "listTopDropActive": "listTopDropActive_108469306",
3495
+ "sessionOverflowButton": "sessionOverflowButton_108469306",
3496
+ "empty": "empty_108469306",
3497
+ "renameInput": "renameInput_108469306",
3498
+ "renameError": "renameError_108469306",
3499
+ "deleteAction": "deleteAction_108469306",
3500
+ "deleteStatus": "deleteStatus_108469306",
3501
+ "modalAction": "modalAction_108469306",
3502
+ "modalError": "modalError_108469306",
3503
+ "menuStatus": "menuStatus_108469306",
3504
+ "memberIndent": "memberIndent_108469306",
3505
+ "sessionsIndent": "sessionsIndent_108469306"
3506
+ };
3507
+ //#endregion
3508
+ //#region src/client/GroupedSidebar.tsx
3509
+ /**
3510
+ * GroupedSidebar: the `sidebar.workspaces` seat occupant. P1 aggregation
3511
+ * (same-repository workspaces clustered from /group facts) plus a 1:1
3512
+ * transplant of the native workspace browser's search, menus, status dots,
3513
+ * relative time, view options, rail, and dialogs.
3514
+ *
3515
+ * Drag-reorder and the native `dsh.workspace.view.v5` store are P3. Adding a
3516
+ * workspace uses `workspaces.pickDirectory` rather than re-declaring the
3517
+ * `sidebar.workspaces.directoryFlow` child hole (native already declared it;
3518
+ * a second declarer throws).
3519
+ *
3520
+ * @module git-worktree/client/GroupedSidebar
3521
+ */
3522
+ function cx(...parts) {
3523
+ return parts.filter((part) => typeof part === "string" && part !== "").join(" ");
3524
+ }
3525
+ function ViewOptionsMenu({ groupBy, orderBy, onGroupPick, onOrderPick, t }) {
3526
+ const [open, setOpen] = (0, react.useState)(false);
3527
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Menu, {
3528
+ open,
3529
+ onClose: () => {
3530
+ setOpen(false);
3531
+ },
3532
+ items: [
3533
+ {
3534
+ type: "label",
3535
+ id: "group-by",
3536
+ text: t("groupBy.label")
3537
+ },
3538
+ {
3539
+ id: "workspace",
3540
+ label: t("groupBy.workspace")
3541
+ },
3542
+ {
3543
+ id: "flat",
3544
+ label: t("groupBy.flat")
3545
+ },
3546
+ {
3547
+ type: "separator",
3548
+ id: "order-by-separator"
3549
+ },
3550
+ {
3551
+ type: "label",
3552
+ id: "order-by",
3553
+ text: t("orderBy.label")
3554
+ },
3555
+ {
3556
+ id: "manual",
3557
+ label: t("orderBy.manual")
3558
+ },
3559
+ {
3560
+ id: "updated",
3561
+ label: t("orderBy.updated")
3562
+ }
3563
+ ],
3564
+ selectedIds: [groupBy, orderBy],
3565
+ onSelect: (id) => {
3566
+ if (id === "workspace" || id === "flat") onGroupPick(id);
3567
+ else if (id === "manual" || id === "updated") onOrderPick(id);
3568
+ setOpen(false);
3569
+ },
3570
+ align: "end",
3571
+ dense: true,
3572
+ portal: true,
3573
+ anchor: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tooltip, {
3574
+ label: t("viewOptions.label"),
3575
+ side: "bottom",
3576
+ delayMs: 500,
3577
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
3578
+ type: "button",
3579
+ className: cx(GroupedSidebar_module_default.iconButton, GroupedSidebar_module_default.wide),
3580
+ "aria-label": t("viewOptions.label"),
3581
+ onClick: () => {
3582
+ setOpen((v) => !v);
3583
+ },
3584
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconPersonalizationOutline16, {})
3585
+ })
3586
+ })
3587
+ });
3588
+ }
3589
+ /** Add-workspace flow: OS directory picker (cannot redeclare native's directoryFlow hole). */
3590
+ function WorkspacePickFlow({ open, onClose, onRetry, pickDirectory, createWorkspace, onPick, t }) {
3591
+ const [errorOpen, setErrorOpen] = (0, react.useState)(false);
3592
+ const [modalError, setModalError] = (0, react.useState)(null);
3593
+ const controllerRef = (0, react.useRef)(null);
3594
+ const controller = controllerRef.current ?? (controllerRef.current = new PickFlowController());
3595
+ controller.attach({
3596
+ pickDirectory,
3597
+ createWorkspace,
3598
+ onPicked: onPick,
3599
+ onCancelled: onClose,
3600
+ onFailed: (message) => {
3601
+ setModalError(message);
3602
+ setErrorOpen(true);
3603
+ onClose();
3604
+ }
3605
+ });
3606
+ (0, react.useEffect)(() => {
3607
+ controller.sync(open);
3608
+ }, [open, controller]);
3609
+ (0, react.useEffect)(() => () => {
3610
+ controller.kill();
3611
+ }, [controller]);
3612
+ const closeModal = () => {
3613
+ setErrorOpen(false);
3614
+ setModalError(null);
3615
+ };
3616
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Modal, {
3617
+ open: errorOpen,
3618
+ onClose: closeModal,
3619
+ closeLabel: t("close"),
3620
+ title: t("folderError.title"),
3621
+ footer: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
3622
+ variant: "outline",
3623
+ className: GroupedSidebar_module_default.modalAction,
3624
+ onClick: closeModal,
3625
+ children: t("cancel")
3626
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
3627
+ variant: "primary",
3628
+ className: GroupedSidebar_module_default.modalAction,
3629
+ onClick: () => {
3630
+ closeModal();
3631
+ onRetry();
3632
+ },
3633
+ children: t("folderError.retry")
3634
+ })] }),
3635
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3636
+ className: GroupedSidebar_module_default.modalError,
3637
+ role: "alert",
3638
+ children: modalError
3639
+ })
3640
+ });
3641
+ }
3642
+ function SearchResults({ list, workspaces, archivedSessionIds, query, remote, resultLimit, currentId, onOpen, t }) {
3643
+ const currentRemote = remote.query === query ? remote : {
3644
+ query,
3645
+ status: "loading",
3646
+ items: [],
3647
+ hasMore: false
3648
+ };
3649
+ const results = (0, react.useMemo)(() => deriveSearchResults(list, workspaces, query, archivedSessionIds, currentRemote, resultLimit), [
3650
+ list,
3651
+ workspaces,
3652
+ query,
3653
+ archivedSessionIds,
3654
+ currentRemote,
3655
+ resultLimit
3656
+ ]);
3657
+ const pending = currentRemote.status === "loading";
3658
+ const failed = currentRemote.status === "error";
3659
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3660
+ className: cx(GroupedSidebar_module_default.treeBody, GroupedSidebar_module_default.wide),
3661
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3662
+ className: GroupedSidebar_module_default.list,
3663
+ children: [
3664
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3665
+ className: GroupedSidebar_module_default.searchTree,
3666
+ role: "tree",
3667
+ "aria-label": t("search.results.aria"),
3668
+ children: results.items.map((result) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SearchResultItem, {
3669
+ result,
3670
+ currentId,
3671
+ onOpen,
3672
+ t
3673
+ }, result.id))
3674
+ }),
3675
+ pending && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3676
+ className: GroupedSidebar_module_default.searchStatus,
3677
+ role: "status",
3678
+ children: t("search.pending")
3679
+ }),
3680
+ failed && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3681
+ className: GroupedSidebar_module_default.searchWarning,
3682
+ role: "status",
3683
+ children: t("search.unavailable")
3684
+ }),
3685
+ !pending && results.items.length === 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3686
+ className: GroupedSidebar_module_default.empty,
3687
+ children: t("search.noMatches")
3688
+ }),
3689
+ results.hasMore && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3690
+ className: GroupedSidebar_module_default.searchStatus,
3691
+ children: t("search.hasMore", { n: resultLimit })
3692
+ })
3693
+ ]
3694
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: GroupedSidebar_module_default.fade })]
3695
+ });
3696
+ }
3697
+ function FlatListBody({ list, archivedSessionIds, orderBy, currentId, now, onOpen, onRename, onFork, onArchive, t }) {
3698
+ const rows = (0, react.useMemo)(() => deriveFlat(list, archivedSessionIds, orderBy), [
3699
+ list,
3700
+ archivedSessionIds,
3701
+ orderBy
3702
+ ]);
3703
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3704
+ className: cx(GroupedSidebar_module_default.treeBody, GroupedSidebar_module_default.wide),
3705
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3706
+ className: cx(GroupedSidebar_module_default.list, GroupedSidebar_module_default.flatList),
3707
+ role: "tree",
3708
+ "aria-label": t("section.sessions"),
3709
+ children: [rows.length === 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3710
+ className: GroupedSidebar_module_default.empty,
3711
+ children: t("empty.none")
3712
+ }), rows.map((node) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SessionNodeItem, {
3713
+ node,
3714
+ currentId,
3715
+ now,
3716
+ onOpen,
3717
+ onRename,
3718
+ onFork,
3719
+ onArchive,
3720
+ flat: true,
3721
+ t
3722
+ }, node.id))]
3723
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: GroupedSidebar_module_default.fade })]
3724
+ });
3725
+ }
3726
+ function memberLabel(member, t) {
3727
+ if (member.label.type === "main") return member.label.branch === null ? t("sidebarMain") : t("sidebarMainBranch", { branch: member.label.branch });
3728
+ if (member.label.type === "linked") return member.label.branch ?? member.workspace.title;
3729
+ return member.workspace.title;
3730
+ }
3731
+ function createdAtMs(createdAt) {
3732
+ if (createdAt === void 0 || createdAt === "") return void 0;
3733
+ const parsed = Date.parse(createdAt);
3734
+ return Number.isNaN(parsed) ? void 0 : parsed;
3735
+ }
3736
+ function GroupedTree({ groups, sessions, archived, currentSessionId, expandMap, onToggle, expandTo, orderBy, now, home, onOpen, onRename, onFork, onArchive, onWorkspaceRename, onWorkspaceDelete, startSession, t }) {
3737
+ const descendants = (0, react.useMemo)(() => indexSubagentRunning(sessions.byId), [sessions.byId]);
3738
+ const [expandedSessionGroups, setExpandedSessionGroups] = (0, react.useState)([]);
3739
+ const empty = groups.length === 0;
3740
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3741
+ className: cx(GroupedSidebar_module_default.treeBody, GroupedSidebar_module_default.wide),
3742
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3743
+ className: GroupedSidebar_module_default.list,
3744
+ role: "tree",
3745
+ "aria-label": t("section.workspaces"),
3746
+ children: [empty && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3747
+ className: GroupedSidebar_module_default.empty,
3748
+ children: t("empty.none")
3749
+ }), groups.map((group) => {
3750
+ if (group.kind === "repo") {
3751
+ const memberIds = group.members.map((member) => orderedVisibleSessionIds(member.workspace, sessions, archived, orderBy));
3752
+ const visibleCount = memberIds.reduce((sum, ids) => sum + ids.length, 0);
3753
+ const containsCurrent = group.members.some((member) => member.workspace.sessionIds.includes(currentSessionId ?? "\0"));
3754
+ const open = expandMap[group.key] ?? containsCurrent;
3755
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3756
+ className: GroupedSidebar_module_default.groupSection,
3757
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ProjectRowItem, {
3758
+ row: {
3759
+ key: group.key,
3760
+ label: group.repoName ?? group.key,
3761
+ expanded: open,
3762
+ containsCurrent
3763
+ },
3764
+ onToggle: () => {
3765
+ onToggle(group.key);
3766
+ },
3767
+ home,
3768
+ t,
3769
+ badge: String(visibleCount)
3770
+ }), open && group.members.map((member, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MemberBlock, {
3771
+ member,
3772
+ indent: true,
3773
+ sessionIds: memberIds[index] ?? [],
3774
+ sessions,
3775
+ currentSessionId,
3776
+ expandMap,
3777
+ onToggle,
3778
+ expandTo,
3779
+ descendants,
3780
+ expandedSessionGroups,
3781
+ setExpandedSessionGroups,
3782
+ now,
3783
+ home,
3784
+ onOpen,
3785
+ onRename,
3786
+ onFork,
3787
+ onArchive,
3788
+ onWorkspaceRename,
3789
+ onWorkspaceDelete,
3790
+ startSession,
3791
+ t
3792
+ }, member.workspace.workspaceId))]
3793
+ }, group.key);
3794
+ }
3795
+ const member = group.members[0];
3796
+ if (member === void 0) return null;
3797
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3798
+ className: GroupedSidebar_module_default.groupSection,
3799
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MemberBlock, {
3800
+ member,
3801
+ indent: false,
3802
+ sessionIds: orderedVisibleSessionIds(member.workspace, sessions, archived, orderBy),
3803
+ sessions,
3804
+ currentSessionId,
3805
+ expandMap,
3806
+ onToggle,
3807
+ expandTo,
3808
+ descendants,
3809
+ expandedSessionGroups,
3810
+ setExpandedSessionGroups,
3811
+ now,
3812
+ home,
3813
+ onOpen,
3814
+ onRename,
3815
+ onFork,
3816
+ onArchive,
3817
+ onWorkspaceRename,
3818
+ onWorkspaceDelete,
3819
+ startSession,
3820
+ t
3821
+ })
3822
+ }, group.key);
3823
+ })]
3824
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: GroupedSidebar_module_default.fade })]
3825
+ });
3826
+ }
3827
+ function MemberBlock({ member, indent, sessionIds, sessions, currentSessionId, expandMap, onToggle, expandTo, descendants, expandedSessionGroups, setExpandedSessionGroups, now, home, onOpen, onRename, onFork, onArchive, onWorkspaceRename, onWorkspaceDelete, startSession, t }) {
3828
+ const key = `ws:${member.workspace.workspaceId}`;
3829
+ const containsCurrent = member.workspace.sessionIds.includes(currentSessionId ?? "\0");
3830
+ const open = expandMap[key] ?? containsCurrent;
3831
+ const label = memberLabel(member, t);
3832
+ const overflowOpen = expandedSessionGroups.includes(key);
3833
+ const visibleIds = overflowOpen ? sessionIds : sessionIds.slice(0, 5);
3834
+ const nodes = [];
3835
+ for (const sessionId of visibleIds) {
3836
+ const summary = sessions.byId[sessionId];
3837
+ if (summary !== void 0) nodes.push(sessionNode(summary, descendants));
3838
+ }
3839
+ const created = createdAtMs(member.workspace.createdAt);
3840
+ const body = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ProjectRowItem, {
3841
+ row: {
3842
+ key,
3843
+ label,
3844
+ expanded: open,
3845
+ containsCurrent,
3846
+ cwd: member.workspace.path,
3847
+ ...created === void 0 ? {} : { createdAt: created }
3848
+ },
3849
+ onToggle: () => {
3850
+ onToggle(key);
3851
+ },
3852
+ onCreate: () => {
3853
+ expandTo(key);
3854
+ startSession(member.workspace.workspaceId);
3855
+ },
3856
+ actions: {
3857
+ rename: () => {
3858
+ onWorkspaceRename(member.workspace.workspaceId, member.workspace.title);
3859
+ },
3860
+ delete: () => {
3861
+ onWorkspaceDelete(member.workspace.workspaceId, member.workspace.title);
3862
+ }
3863
+ },
3864
+ home,
3865
+ t
3866
+ }), open && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3867
+ className: indent ? GroupedSidebar_module_default.sessionsIndent : void 0,
3868
+ children: [nodes.map((node) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SessionNodeItem, {
3869
+ node,
3870
+ currentId: currentSessionId,
3871
+ now,
3872
+ onOpen,
3873
+ onRename,
3874
+ onFork,
3875
+ onArchive,
3876
+ t
3877
+ }, node.id)), sessionIds.length > 5 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
3878
+ type: "button",
3879
+ className: GroupedSidebar_module_default.sessionOverflowButton,
3880
+ "aria-expanded": overflowOpen,
3881
+ onClick: () => {
3882
+ setExpandedSessionGroups((keys) => keys.includes(key) ? keys.filter((k) => k !== key) : [...keys, key]);
3883
+ },
3884
+ children: overflowOpen ? t("sessions.collapse") : t("sessions.expand", { n: sessionIds.length - 5 })
3885
+ })]
3886
+ })] });
3887
+ return indent ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3888
+ className: GroupedSidebar_module_default.memberIndent,
3889
+ children: body
3890
+ }) : body;
3891
+ }
3892
+ function GroupedSidebar(props) {
3893
+ const { t } = props;
3894
+ const workspaces = (0, react.useSyncExternalStore)(props.workspacesList.subscribe, props.workspacesList.getSnapshot);
3895
+ const sessions = (0, react.useSyncExternalStore)(props.sessionsList.subscribe, props.sessionsList.getSnapshot);
3896
+ const host = (0, react.useSyncExternalStore)(props.hostInfo.subscribe, props.hostInfo.getSnapshot);
3897
+ const directoryFlowAvailable = (0, react.useSyncExternalStore)(props.directoryFlow.subscribe, props.directoryFlow.getSnapshot);
3898
+ const items = workspaces.items;
3899
+ const home = host?.home;
3900
+ const signature = (0, react.useMemo)(() => [...items].map((item) => item.path).sort().join("\n"), [items]);
3901
+ const [factsState, setFactsState] = (0, react.useState)(null);
3902
+ const readyOnce = (0, react.useRef)(false);
3903
+ const signalReady = () => {
3904
+ if (readyOnce.current) return;
3905
+ readyOnce.current = true;
3906
+ props.onReady?.();
3907
+ };
3908
+ (0, react.useEffect)(() => {
3909
+ if (factsState?.signature === signature) {
3910
+ signalReady();
3911
+ return;
3912
+ }
3913
+ let live = true;
3914
+ props.loadFacts(items.map((item) => item.path)).then((facts) => {
3915
+ if (!live) return;
3916
+ if (facts !== void 0) setFactsState({
3917
+ signature,
3918
+ facts
3919
+ });
3920
+ signalReady();
3921
+ }, () => {
3922
+ if (live) signalReady();
3923
+ });
3924
+ return () => {
3925
+ live = false;
3926
+ };
3927
+ }, [
3928
+ signature,
3929
+ factsState?.signature,
3930
+ props.loadFacts,
3931
+ items
3932
+ ]);
3933
+ const facts = factsState?.signature === signature ? factsState.facts : void 0;
3934
+ const groups = (0, react.useMemo)(() => deriveSidebarGroups(items, facts), [items, facts]);
3935
+ const sessionList = sessions;
3936
+ const archived = workspaces.archivedSessionIds;
3937
+ const [expandMap, setExpandMap] = (0, react.useState)(() => loadExpandState());
3938
+ const toggle = (key) => {
3939
+ const next = {
3940
+ ...expandMap,
3941
+ [key]: !(expandMap[key] ?? false)
3942
+ };
3943
+ setExpandMap(next);
3944
+ saveExpandState(next);
3945
+ };
3946
+ const expandTo = (key) => {
3947
+ if (expandMap[key] === true) return;
3948
+ const next = {
3949
+ ...expandMap,
3950
+ [key]: true
3951
+ };
3952
+ setExpandMap(next);
3953
+ saveExpandState(next);
3954
+ };
3955
+ const [viewPrefs, setViewPrefs] = (0, react.useState)(() => loadViewPrefs());
3956
+ const setGroupBy = (groupBy) => {
3957
+ const next = {
3958
+ ...viewPrefs,
3959
+ groupBy
3960
+ };
3961
+ setViewPrefs(next);
3962
+ saveViewPrefs(next);
3963
+ };
3964
+ const setOrderBy = (orderBy) => {
3965
+ const next = {
3966
+ ...viewPrefs,
3967
+ orderBy
3968
+ };
3969
+ setViewPrefs(next);
3970
+ saveViewPrefs(next);
3971
+ };
3972
+ const [query, setQuery] = (0, react.useState)("");
3973
+ const [searchExpanded, setSearchExpanded] = (0, react.useState)(false);
3974
+ const normalizedQuery = sanitizeSearchQuery(query).trim();
3975
+ const [remoteSearch, setRemoteSearch] = (0, react.useState)({
3976
+ query: "",
3977
+ status: "idle",
3978
+ items: [],
3979
+ hasMore: false
3980
+ });
3981
+ const searchRoot = (0, react.useRef)(null);
3982
+ const searchInput = (0, react.useRef)(null);
3983
+ const [wsPickerOpen, setWsPickerOpen] = (0, react.useState)(false);
3984
+ const composingRef = (0, react.useRef)(false);
3985
+ const [searchOnExpand, setSearchOnExpand] = (0, react.useState)(false);
3986
+ (0, react.useEffect)(() => {
3987
+ if (props.wide && searchOnExpand) {
3988
+ const timer = window.setTimeout(() => {
3989
+ searchInput.current?.focus({ preventScroll: true });
3990
+ setSearchOnExpand(false);
3991
+ }, 300);
3992
+ return () => {
3993
+ window.clearTimeout(timer);
3994
+ };
3995
+ }
3996
+ }, [props.wide, searchOnExpand]);
3997
+ (0, react.useEffect)(() => {
3998
+ if (!props.wide || !searchExpanded || searchOnExpand) return;
3999
+ searchInput.current?.focus({ preventScroll: true });
4000
+ }, [
4001
+ props.wide,
4002
+ searchExpanded,
4003
+ searchOnExpand
4004
+ ]);
4005
+ (0, react.useEffect)(() => {
4006
+ if (!props.wide || !searchExpanded || searchOnExpand) return;
4007
+ const onClick = (event) => {
4008
+ if (!(event.target instanceof Node) || searchRoot.current?.contains(event.target) === true) return;
4009
+ searchInput.current?.blur();
4010
+ if (normalizedQuery !== "") return;
4011
+ setSearchExpanded(false);
4012
+ };
4013
+ document.addEventListener("click", onClick);
4014
+ return () => {
4015
+ document.removeEventListener("click", onClick);
4016
+ };
4017
+ }, [
4018
+ normalizedQuery,
4019
+ props.wide,
4020
+ searchExpanded,
4021
+ searchOnExpand
4022
+ ]);
4023
+ (0, react.useEffect)(() => {
4024
+ if (normalizedQuery === "") {
4025
+ setRemoteSearch({
4026
+ query: "",
4027
+ status: "idle",
4028
+ items: [],
4029
+ hasMore: false
4030
+ });
4031
+ return;
4032
+ }
4033
+ const controller = new AbortController();
4034
+ setRemoteSearch({
4035
+ query: normalizedQuery,
4036
+ status: "loading",
4037
+ items: [],
4038
+ hasMore: false
4039
+ });
4040
+ const timer = window.setTimeout(() => {
4041
+ props.searchSessions(normalizedQuery, controller.signal).then((result) => {
4042
+ if (controller.signal.aborted) return;
4043
+ setRemoteSearch({
4044
+ query: normalizedQuery,
4045
+ status: "ready",
4046
+ items: result.items,
4047
+ hasMore: result.hasMore
4048
+ });
4049
+ }).catch(() => {
4050
+ if (controller.signal.aborted) return;
4051
+ setRemoteSearch({
4052
+ query: normalizedQuery,
4053
+ status: "error",
4054
+ items: [],
4055
+ hasMore: false
4056
+ });
4057
+ });
4058
+ }, 250);
4059
+ return () => {
4060
+ window.clearTimeout(timer);
4061
+ controller.abort();
4062
+ };
4063
+ }, [normalizedQuery, props.searchSessions]);
4064
+ const [renameTarget, setRenameTarget] = (0, react.useState)(null);
4065
+ const [renameDraft, setRenameDraft] = (0, react.useState)("");
4066
+ const [renaming, setRenaming] = (0, react.useState)(false);
4067
+ const [renameError, setRenameError] = (0, react.useState)(null);
4068
+ const renameTrimmed = renameDraft.trim();
4069
+ const renameDuplicate = renameTarget !== null && renameTrimmed !== "" && renameTrimmed !== renameTarget.currentTitle && items.some((w) => w.title === renameTrimmed);
4070
+ const renameBlocked = renaming || renameTrimmed === "" || renameTarget === null || renameTrimmed === renameTarget.currentTitle || renameDuplicate;
4071
+ const closeRename = () => {
4072
+ if (renaming) return;
4073
+ setRenameTarget(null);
4074
+ setRenameError(null);
4075
+ };
4076
+ const confirmRename = () => {
4077
+ if (renameBlocked || renameTarget === null) return;
4078
+ setRenaming(true);
4079
+ setRenameError(null);
4080
+ props.renameWorkspace(renameTarget.workspaceId, renameTrimmed).then(() => {
4081
+ setRenaming(false);
4082
+ setRenameTarget(null);
4083
+ }).catch((reason) => {
4084
+ setRenaming(false);
4085
+ setRenameError(reason instanceof Error ? reason.message : String(reason));
4086
+ });
4087
+ };
4088
+ const [sessionRenameTarget, setSessionRenameTarget] = (0, react.useState)(null);
4089
+ const [sessionRenameDraft, setSessionRenameDraft] = (0, react.useState)("");
4090
+ const [sessionRenaming, setSessionRenaming] = (0, react.useState)(false);
4091
+ const [sessionRenameError, setSessionRenameError] = (0, react.useState)(null);
4092
+ const sessionRenameTrimmed = sessionRenameDraft.trim();
4093
+ const sessionRenameBlocked = sessionRenaming || sessionRenameTrimmed === "" || sessionRenameTarget === null;
4094
+ const closeSessionRename = () => {
4095
+ if (sessionRenaming) return;
4096
+ setSessionRenameTarget(null);
4097
+ setSessionRenameError(null);
4098
+ };
4099
+ const confirmSessionRename = () => {
4100
+ if (sessionRenameBlocked || sessionRenameTarget === null) return;
4101
+ setSessionRenaming(true);
4102
+ setSessionRenameError(null);
4103
+ props.renameSession(sessionRenameTarget.sessionId, sessionRenameTrimmed).then(() => {
4104
+ setSessionRenaming(false);
4105
+ setSessionRenameTarget(null);
4106
+ }).catch((reason) => {
4107
+ setSessionRenaming(false);
4108
+ setSessionRenameError(reason instanceof Error ? reason.message : String(reason));
4109
+ });
4110
+ };
4111
+ const onSessionRename = (sessionId, currentTitle) => {
4112
+ setSessionRenameTarget({
4113
+ sessionId,
4114
+ currentTitle
4115
+ });
4116
+ setSessionRenameDraft(currentTitle);
4117
+ setSessionRenameError(null);
4118
+ };
4119
+ const onSessionArchive = (sessionId) => {
4120
+ props.archiveSession(sessionId).catch((reason) => {
4121
+ console.warn("session archive rejected:", reason);
4122
+ });
4123
+ };
4124
+ const [deleteTarget, setDeleteTarget] = (0, react.useState)(null);
4125
+ const [deleting, setDeleting] = (0, react.useState)(false);
4126
+ const [deleteCommittedId, setDeleteCommittedId] = (0, react.useState)(null);
4127
+ const [deleteError, setDeleteError] = (0, react.useState)(null);
4128
+ (0, react.useEffect)(() => {
4129
+ if (deleteCommittedId === null || items.some((workspace) => workspace.workspaceId === deleteCommittedId)) return;
4130
+ setDeleting(false);
4131
+ setDeleteCommittedId(null);
4132
+ setDeleteTarget(null);
4133
+ }, [deleteCommittedId, items]);
4134
+ const closeDelete = () => {
4135
+ if (deleting) return;
4136
+ setDeleteTarget(null);
4137
+ setDeleteError(null);
4138
+ };
4139
+ const confirmDelete = () => {
4140
+ if (deleting || deleteTarget === null) return;
4141
+ setDeleting(true);
4142
+ setDeleteCommittedId(null);
4143
+ setDeleteError(null);
4144
+ props.deleteWorkspace(deleteTarget.workspaceId).then(() => {
4145
+ setDeleteCommittedId(deleteTarget.workspaceId);
4146
+ }).catch((reason) => {
4147
+ setDeleting(false);
4148
+ setDeleteError(reason instanceof Error ? reason.message : String(reason));
4149
+ });
4150
+ };
4151
+ const now = Date.now();
4152
+ const wide = props.wide;
4153
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
4154
+ className: cx(GroupedSidebar_module_default.root, !wide && GroupedSidebar_module_default.rail),
4155
+ children: [
4156
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
4157
+ className: GroupedSidebar_module_default.sectionHeader,
4158
+ children: [
4159
+ wide && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
4160
+ className: cx(GroupedSidebar_module_default.sectionLabel, GroupedSidebar_module_default.wide, searchExpanded && GroupedSidebar_module_default.sectionLabelHidden),
4161
+ children: viewPrefs.groupBy === "flat" ? t("section.sessions") : t("section.workspaces")
4162
+ }),
4163
+ wide && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
4164
+ className: cx(GroupedSidebar_module_default.searchSlot, searchExpanded && GroupedSidebar_module_default.searchSlotExpanded),
4165
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
4166
+ ref: searchRoot,
4167
+ className: cx(GroupedSidebar_module_default.search, searchExpanded && GroupedSidebar_module_default.searchExpanded),
4168
+ onClick: () => {
4169
+ setWsPickerOpen(false);
4170
+ setSearchExpanded(true);
4171
+ searchInput.current?.focus();
4172
+ },
4173
+ children: [
4174
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tooltip, {
4175
+ label: t("search"),
4176
+ side: "bottom",
4177
+ delayMs: 500,
4178
+ disabled: searchExpanded,
4179
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
4180
+ type: "button",
4181
+ className: GroupedSidebar_module_default.searchButton,
4182
+ "aria-label": t("search.sessions.aria"),
4183
+ "aria-expanded": searchExpanded,
4184
+ onClick: () => {
4185
+ setWsPickerOpen(false);
4186
+ setSearchExpanded(true);
4187
+ },
4188
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconSearchOutline16, { size: searchExpanded ? 11 : 14 })
4189
+ })
4190
+ }),
4191
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
4192
+ ref: searchInput,
4193
+ className: GroupedSidebar_module_default.searchInput,
4194
+ type: "text",
4195
+ placeholder: t("search.placeholder"),
4196
+ maxLength: 500,
4197
+ value: query,
4198
+ tabIndex: searchExpanded ? 0 : -1,
4199
+ onChange: (e) => {
4200
+ setQuery(sanitizeSearchQuery(e.target.value));
4201
+ },
4202
+ onKeyDown: (e) => {
4203
+ if (e.key !== "Escape") return;
4204
+ setQuery("");
4205
+ setSearchExpanded(false);
4206
+ }
4207
+ }),
4208
+ searchExpanded && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
4209
+ type: "button",
4210
+ className: GroupedSidebar_module_default.clearButton,
4211
+ "aria-label": t("search.clear"),
4212
+ onClick: (e) => {
4213
+ e.stopPropagation();
4214
+ setQuery("");
4215
+ setSearchExpanded(false);
4216
+ },
4217
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconCloseFill14, {})
4218
+ })
4219
+ ]
4220
+ })
4221
+ }),
4222
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
4223
+ className: cx(GroupedSidebar_module_default.headerActions, wide && searchExpanded && GroupedSidebar_module_default.headerActionsHidden),
4224
+ children: [wide && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ViewOptionsMenu, {
4225
+ groupBy: viewPrefs.groupBy,
4226
+ orderBy: viewPrefs.orderBy,
4227
+ onGroupPick: setGroupBy,
4228
+ onOrderPick: setOrderBy,
4229
+ t
4230
+ }), directoryFlowAvailable && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tooltip, {
4231
+ label: t("workspace.add"),
4232
+ side: "bottom",
4233
+ delayMs: 500,
4234
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
4235
+ type: "button",
4236
+ className: GroupedSidebar_module_default.iconButton,
4237
+ "aria-label": t("workspace.add"),
4238
+ onClick: () => {
4239
+ setWsPickerOpen((v) => !v);
4240
+ },
4241
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconProjectAddOutline16, { size: wide ? 16 : 18 })
4242
+ })
4243
+ })]
4244
+ }),
4245
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WorkspacePickFlow, {
4246
+ t,
4247
+ open: wsPickerOpen,
4248
+ pickDirectory: props.pickDirectory,
4249
+ createWorkspace: props.createWorkspace,
4250
+ onPick: (workspaceId) => {
4251
+ setWsPickerOpen(false);
4252
+ props.startSession(workspaceId);
4253
+ },
4254
+ onClose: () => {
4255
+ setWsPickerOpen(false);
4256
+ },
4257
+ onRetry: () => {
4258
+ setWsPickerOpen(true);
4259
+ }
4260
+ })
4261
+ ]
4262
+ }),
4263
+ !wide && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
4264
+ className: GroupedSidebar_module_default.search,
4265
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tooltip, {
4266
+ label: t("search"),
4267
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
4268
+ type: "button",
4269
+ className: GroupedSidebar_module_default.searchButton,
4270
+ "aria-label": t("search.sessions.aria"),
4271
+ onClick: () => {
4272
+ setSearchExpanded(true);
4273
+ setSearchOnExpand(true);
4274
+ props.expandSidebar();
4275
+ },
4276
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconSearchOutline16, { size: 18 })
4277
+ })
4278
+ })
4279
+ }),
4280
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
4281
+ className: GroupedSidebar_module_default.listArea,
4282
+ children: wide && (normalizedQuery !== "" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SearchResults, {
4283
+ list: sessionList,
4284
+ workspaces: items,
4285
+ archivedSessionIds: archived,
4286
+ query: normalizedQuery,
4287
+ remote: remoteSearch,
4288
+ resultLimit: props.searchResultLimit,
4289
+ currentId: sessions.current,
4290
+ onOpen: props.openSession,
4291
+ t
4292
+ }) : viewPrefs.groupBy === "flat" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FlatListBody, {
4293
+ list: sessionList,
4294
+ archivedSessionIds: archived,
4295
+ orderBy: viewPrefs.orderBy,
4296
+ currentId: sessions.current,
4297
+ now,
4298
+ onOpen: props.openSession,
4299
+ onRename: onSessionRename,
4300
+ onFork: props.forkSession,
4301
+ onArchive: onSessionArchive,
4302
+ t
4303
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GroupedTree, {
4304
+ groups,
4305
+ sessions: sessionList,
4306
+ archived,
4307
+ currentSessionId: sessions.current,
4308
+ expandMap,
4309
+ onToggle: toggle,
4310
+ expandTo,
4311
+ orderBy: viewPrefs.orderBy,
4312
+ now,
4313
+ home,
4314
+ onOpen: props.openSession,
4315
+ onRename: onSessionRename,
4316
+ onFork: props.forkSession,
4317
+ onArchive: onSessionArchive,
4318
+ onWorkspaceRename: (workspaceId, currentTitle) => {
4319
+ setRenameTarget({
4320
+ workspaceId,
4321
+ currentTitle
4322
+ });
4323
+ setRenameDraft(currentTitle);
4324
+ setRenameError(null);
4325
+ },
4326
+ onWorkspaceDelete: (workspaceId, title) => {
4327
+ setDeleteTarget({
4328
+ workspaceId,
4329
+ title
4330
+ });
4331
+ setDeleteError(null);
4332
+ },
4333
+ startSession: props.startSession,
4334
+ t
4335
+ }))
4336
+ }),
4337
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_deepseek_ai_dsh_client_ui_primitives.Modal, {
4338
+ open: renameTarget !== null,
4339
+ onClose: closeRename,
4340
+ closeLabel: t("close"),
4341
+ title: t("rename.workspace.title"),
4342
+ footer: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
4343
+ variant: "outline",
4344
+ disabled: renaming,
4345
+ onClick: closeRename,
4346
+ children: t("cancel")
4347
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
4348
+ variant: "primary",
4349
+ disabled: renameBlocked,
4350
+ onClick: confirmRename,
4351
+ children: t("rename")
4352
+ })] }),
4353
+ children: [
4354
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
4355
+ className: GroupedSidebar_module_default.renameInput,
4356
+ value: renameDraft,
4357
+ "aria-label": t("field.workspaceName"),
4358
+ autoFocus: true,
4359
+ disabled: renaming,
4360
+ onFocus: (e) => {
4361
+ e.target.select();
4362
+ },
4363
+ onChange: (e) => {
4364
+ setRenameDraft(e.target.value);
4365
+ setRenameError(null);
4366
+ },
4367
+ onCompositionStart: () => {
4368
+ composingRef.current = true;
4369
+ },
4370
+ onCompositionEnd: () => {
4371
+ composingRef.current = false;
4372
+ },
4373
+ onKeyDown: (e) => {
4374
+ if (e.key === "Enter" && !composingRef.current) {
4375
+ e.preventDefault();
4376
+ confirmRename();
4377
+ }
4378
+ }
4379
+ }),
4380
+ renameDuplicate && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
4381
+ className: GroupedSidebar_module_default.renameError,
4382
+ role: "alert",
4383
+ children: t("conflict.named", { name: renameTrimmed })
4384
+ }),
4385
+ renameError !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
4386
+ className: GroupedSidebar_module_default.renameError,
4387
+ role: "alert",
4388
+ children: renameError
4389
+ })
4390
+ ]
4391
+ }),
4392
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_deepseek_ai_dsh_client_ui_primitives.Modal, {
4393
+ open: sessionRenameTarget !== null,
4394
+ onClose: closeSessionRename,
4395
+ closeLabel: t("close"),
4396
+ title: t("rename.session.title"),
4397
+ footer: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
4398
+ variant: "outline",
4399
+ disabled: sessionRenaming,
4400
+ onClick: closeSessionRename,
4401
+ children: t("cancel")
4402
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
4403
+ variant: "primary",
4404
+ disabled: sessionRenameBlocked,
4405
+ onClick: confirmSessionRename,
4406
+ children: t("rename")
4407
+ })] }),
4408
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
4409
+ className: GroupedSidebar_module_default.renameInput,
4410
+ value: sessionRenameDraft,
4411
+ "aria-label": t("field.sessionName"),
4412
+ autoFocus: true,
4413
+ disabled: sessionRenaming,
4414
+ onFocus: (e) => {
4415
+ e.target.select();
4416
+ },
4417
+ onChange: (e) => {
4418
+ setSessionRenameDraft(e.target.value);
4419
+ setSessionRenameError(null);
4420
+ },
4421
+ onCompositionStart: () => {
4422
+ composingRef.current = true;
4423
+ },
4424
+ onCompositionEnd: () => {
4425
+ composingRef.current = false;
4426
+ },
4427
+ onKeyDown: (e) => {
4428
+ if (e.key === "Enter" && !composingRef.current) {
4429
+ e.preventDefault();
4430
+ confirmSessionRename();
4431
+ }
4432
+ }
4433
+ }), sessionRenameError !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
4434
+ className: GroupedSidebar_module_default.renameError,
4435
+ role: "alert",
4436
+ children: sessionRenameError
4437
+ })]
4438
+ }),
4439
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_deepseek_ai_dsh_client_ui_primitives.Modal, {
4440
+ open: deleteTarget !== null,
4441
+ onClose: closeDelete,
4442
+ closeLabel: t("close"),
4443
+ title: t("delete.workspace"),
4444
+ ...deleteTarget === null ? {} : { description: t("delete.desc", { name: deleteTarget.title }) },
4445
+ footer: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
4446
+ variant: "outline",
4447
+ disabled: deleting,
4448
+ onClick: closeDelete,
4449
+ children: t("cancel")
4450
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
4451
+ variant: "outline",
4452
+ className: GroupedSidebar_module_default.deleteAction,
4453
+ disabled: deleting,
4454
+ onClick: confirmDelete,
4455
+ children: t("delete.workspace")
4456
+ })] }),
4457
+ children: [deleting && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
4458
+ className: GroupedSidebar_module_default.deleteStatus,
4459
+ role: "status",
4460
+ children: t("delete.pending")
4461
+ }), deleteError !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
4462
+ className: GroupedSidebar_module_default.renameError,
4463
+ role: "alert",
4464
+ children: deleteError
4465
+ })]
4466
+ })
4467
+ ]
4468
+ });
4469
+ }
4470
+ //#endregion
1639
4471
  //#region src/client/locales.ts
1640
4472
  /** English dictionary — complete by construction. */
1641
4473
  const en = {
1642
4474
  chipWorktree: "Worktree",
1643
4475
  worktreeToggle: "Create an isolated worktree",
4476
+ menuBranches: "Branches",
1644
4477
  menuLocalBranches: "Local branches",
4478
+ menuWorktrees: "Worktrees",
4479
+ menuRemoteBranches: "Remote branches",
4480
+ mainRepoOnly: "Branch operations start from the main checkout",
1645
4481
  menuSearchPlaceholder: "Search branches",
1646
4482
  menuNoMatches: "No matching branches",
4483
+ menuNoBranches: "No branches yet",
1647
4484
  menuLocate: "Locate current branch",
1648
4485
  menuExpandAll: "Expand all",
1649
4486
  menuCollapseAll: "Collapse all",
4487
+ menuNewBranch: "Create branch from current",
4488
+ menuNewBranchPlaceholder: "New branch name",
4489
+ menuNewBranchBad: "Git will not accept this name",
4490
+ menuNewBranchExists: "A branch with this name already exists",
4491
+ menuFetch: "Fetch",
4492
+ menuUpdate: "Update current branch from upstream",
4493
+ fetchDone: "Remote branches synced",
4494
+ updateDone: "{branch} fast-forwarded to its upstream",
4495
+ updateUpToDate: "Already up to date",
4496
+ aheadTitle: "{n} commits ahead of upstream",
4497
+ behindTitle: "{n} commits behind upstream",
1650
4498
  switchAsk: "Switch to {branch}?",
4499
+ switchAskRemote: "Check out this remote branch?",
1651
4500
  switchBusy: "Switching…",
1652
4501
  worktreeAskNew: "Create a worktree from {branch}?",
4502
+ worktreeAskRemote: "Create a worktree from this remote branch?",
1653
4503
  worktreeAskReuse: "Switch to the {branch} worktree?",
1654
- worktreeAskCutOut: "Cut a worktree out of the current branch {branch}?",
4504
+ worktreeAskCutOut: "Cut a new branch out of {branch} into an isolated worktree",
1655
4505
  worktreeBusy: "Creating…",
4506
+ createBranchTitle: "New branch from {branch}",
4507
+ createBranchBusy: "Creating…",
1656
4508
  actionCancel: "Cancel",
1657
4509
  actionConfirm: "Confirm",
1658
4510
  errorGeneric: "Git worktree: {message}",
@@ -1670,24 +4522,121 @@ window.__ModuleLoader__.load({
1670
4522
  cardSaveFailed: "The change did not save. Check the path is absolute and try again.",
1671
4523
  cardDiscard: "Discard",
1672
4524
  cardSave: "Save",
1673
- cardSaving: "Saving…"
4525
+ cardSaving: "Saving…",
4526
+ sidebarSectionTitle: "Workspaces",
4527
+ sidebarAddSession: "Start a new session",
4528
+ sidebarNewSession: "New Session",
4529
+ sidebarMainBranch: "Main ({branch})",
4530
+ sidebarMain: "Main",
4531
+ sidebarRailExpand: "Expand sidebar",
4532
+ cardGroupSidebarLabel: "Group workspaces",
4533
+ cardGroupSidebarHint: "DSH does not yet expose a multi-workspace grouping API, so this replaces the native sidebar 1:1 and adds same-repo worktree grouping.",
4534
+ cardGroupSidebarMark: "(experimental)",
4535
+ cardGroupSidebarNote: "Turn it off to restore the native list if anything breaks; we will switch to the official API as soon as it ships.",
4536
+ cardGroupSidebarBusy: "Switching sidebar…",
4537
+ "group.ungrouped": "Ungrouped",
4538
+ "session.new": "New Session",
4539
+ "section.workspaces": "Workspaces",
4540
+ "section.sessions": "Sessions",
4541
+ "viewOptions.label": "View options",
4542
+ "groupBy.label": "Group by",
4543
+ "groupBy.workspace": "WorkSpace",
4544
+ "groupBy.flat": "In one list",
4545
+ "orderBy.label": "Order by",
4546
+ "orderBy.manual": "Manual",
4547
+ "orderBy.updated": "Last updated",
4548
+ "sessions.expand": "Show {n} more sessions",
4549
+ "sessions.collapse": "Show less",
4550
+ "empty.none": "No sessions yet",
4551
+ "empty.noMatches": "No matches",
4552
+ "workspace.add": "Add workspace",
4553
+ search: "Search",
4554
+ "search.sessions.aria": "Search sessions",
4555
+ "search.placeholder": "Search sessions...",
4556
+ "search.clear": "Clear search",
4557
+ "search.results.aria": "Search results",
4558
+ "search.pending": "Searching session history…",
4559
+ "search.unavailable": "Content search is temporarily unavailable. Showing name matches.",
4560
+ "search.noMatches": "No matching sessions",
4561
+ "search.hasMore": "Showing the first {n} results. Narrow your search.",
4562
+ "menu.addWorkspace": "Add workspace…",
4563
+ "picker.loading": "Loading workspaces…",
4564
+ "conflict.named": "A workspace named “{name}” already exists.",
4565
+ "folderError.title": "Couldn’t open folder",
4566
+ "folderError.retry": "Choose again",
4567
+ rename: "Rename",
4568
+ "rename.workspace.title": "Rename workspace",
4569
+ "rename.session.title": "Rename session",
4570
+ "field.workspaceName": "Workspace name",
4571
+ "field.sessionName": "Session name",
4572
+ "delete.workspace": "Delete workspace",
4573
+ "delete.desc": "This removes “{name}” from the workspace list. The folder and session logs will be kept. Its sessions will appear under Ungrouped.",
4574
+ "delete.pending": "Deleting workspace…",
4575
+ "menu.fork": "Fork session",
4576
+ "menu.archiveSession": "Archive session",
4577
+ "sessions.count.one": "{n} session",
4578
+ "sessions.count.other": "{n} sessions",
4579
+ "actions.workspace.aria": "Workspace actions for {name}",
4580
+ "actions.session.aria": "Session actions for {name}",
4581
+ "actions.newSession.aria": "New session in {name}",
4582
+ "status.running": "Running",
4583
+ "status.subagentsRunning.one": "{n} subagent running",
4584
+ "status.subagentsRunning.other": "{n} subagents running",
4585
+ "status.idle": "Idle",
4586
+ "status.waitingApproval": "Waiting for approval",
4587
+ "status.planReview": "Plan awaiting review",
4588
+ "status.waitingAnswer": "Waiting for answer",
4589
+ "status.completed": "Completed",
4590
+ "hover.created": "Created {time}",
4591
+ "hover.copied": "Copied",
4592
+ "date.ymd": "{y}-{m}-{d}",
4593
+ "time.now": "now",
4594
+ "time.minutes": "{n}min",
4595
+ "time.hours": "{n}h",
4596
+ "time.days": "{n}d",
4597
+ "time.months": "{n}mo",
4598
+ "time.years": "{n}y",
4599
+ "time.ago": "{t} ago",
4600
+ copy: "Copy",
4601
+ close: "Close",
4602
+ cancel: "Cancel"
1674
4603
  };
1675
4604
  /** 中文词典。 */
1676
4605
  const zh = {
1677
4606
  chipWorktree: "工作树",
1678
4607
  worktreeToggle: "创建隔离工作树",
4608
+ menuBranches: "分支",
1679
4609
  menuLocalBranches: "本地分支",
4610
+ menuWorktrees: "工作树",
4611
+ menuRemoteBranches: "远程分支",
4612
+ mainRepoOnly: "分支操作请在主仓库发起",
1680
4613
  menuSearchPlaceholder: "搜索分支",
1681
4614
  menuNoMatches: "没有匹配的分支",
4615
+ menuNoBranches: "暂无分支",
1682
4616
  menuLocate: "定位当前分支",
1683
4617
  menuExpandAll: "全部展开",
1684
4618
  menuCollapseAll: "全部折叠",
4619
+ menuNewBranch: "从当前分支新建分支",
4620
+ menuNewBranchPlaceholder: "新分支名称",
4621
+ menuNewBranchBad: "Git 不接受该名称",
4622
+ menuNewBranchExists: "同名分支已存在",
4623
+ menuFetch: "提取",
4624
+ menuUpdate: "更新当前分支",
4625
+ fetchDone: "远程分支已同步",
4626
+ updateDone: "{branch} 已快进到远程最新",
4627
+ updateUpToDate: "已是最新",
4628
+ aheadTitle: "领先上游 {n} 个提交",
4629
+ behindTitle: "落后上游 {n} 个提交",
1685
4630
  switchAsk: "是否切到 {branch}?",
4631
+ switchAskRemote: "是否检出该远程分支?",
1686
4632
  switchBusy: "切换中…",
1687
4633
  worktreeAskNew: "是否从 {branch} 新建工作树?",
4634
+ worktreeAskRemote: "从该远程分支新建工作树?",
1688
4635
  worktreeAskReuse: "是否切到 {branch} 工作树?",
1689
- worktreeAskCutOut: "是否从当前分支 {branch} 切出工作树?",
4636
+ worktreeAskCutOut: "从当前分支 {branch} 切出新分支到隔离工作树",
1690
4637
  worktreeBusy: "创建中…",
4638
+ createBranchTitle: "从 {branch} 新建分支",
4639
+ createBranchBusy: "创建中…",
1691
4640
  actionCancel: "取消",
1692
4641
  actionConfirm: "确认",
1693
4642
  errorGeneric: "Git 工作树:{message}",
@@ -1705,7 +4654,84 @@ window.__ModuleLoader__.load({
1705
4654
  cardSaveFailed: "保存未生效,请检查路径是否为绝对路径后重试。",
1706
4655
  cardDiscard: "放弃",
1707
4656
  cardSave: "保存",
1708
- cardSaving: "保存中…"
4657
+ cardSaving: "保存中…",
4658
+ sidebarSectionTitle: "工作区",
4659
+ sidebarAddSession: "发起新会话",
4660
+ sidebarNewSession: "新会话",
4661
+ sidebarMainBranch: "主仓库({branch})",
4662
+ sidebarMain: "主仓库",
4663
+ sidebarRailExpand: "展开侧栏",
4664
+ cardGroupSidebarLabel: "聚合工作区",
4665
+ cardGroupSidebarHint: "DSH 尚未开放多工作区聚合接口,因此按原生侧边栏 1:1 替换左侧列表,并加上同仓库工作树分组。",
4666
+ cardGroupSidebarMark: "(测试功能)",
4667
+ cardGroupSidebarNote: "使用中若遇问题,关掉即可回到原生;官方接口一旦开放,会第一时间改用原生实现。",
4668
+ cardGroupSidebarBusy: "正在切换侧栏…",
4669
+ "group.ungrouped": "未分组",
4670
+ "session.new": "新会话",
4671
+ "section.workspaces": "工作区",
4672
+ "section.sessions": "会话",
4673
+ "viewOptions.label": "视图选项",
4674
+ "groupBy.label": "分组方式",
4675
+ "groupBy.workspace": "按工作区",
4676
+ "groupBy.flat": "单列表",
4677
+ "orderBy.label": "排序方式",
4678
+ "orderBy.manual": "手动排序",
4679
+ "orderBy.updated": "最近更新",
4680
+ "sessions.expand": "展开其余 {n} 个会话",
4681
+ "sessions.collapse": "收起",
4682
+ "empty.none": "暂无会话",
4683
+ "empty.noMatches": "无匹配结果",
4684
+ "workspace.add": "添加工作区",
4685
+ search: "搜索",
4686
+ "search.sessions.aria": "搜索会话",
4687
+ "search.placeholder": "搜索会话…",
4688
+ "search.clear": "清除搜索",
4689
+ "search.results.aria": "搜索结果",
4690
+ "search.pending": "正在搜索会话历史…",
4691
+ "search.unavailable": "内容搜索暂不可用,仅显示名称匹配。",
4692
+ "search.noMatches": "无匹配会话",
4693
+ "search.hasMore": "仅显示前 {n} 条结果,请缩小搜索范围。",
4694
+ "menu.addWorkspace": "添加工作区…",
4695
+ "picker.loading": "正在加载工作区…",
4696
+ "conflict.named": "已存在名为“{name}”的工作区。",
4697
+ "folderError.title": "无法打开文件夹",
4698
+ "folderError.retry": "重新选择",
4699
+ rename: "重命名",
4700
+ "rename.workspace.title": "重命名工作区",
4701
+ "rename.session.title": "重命名会话",
4702
+ "field.workspaceName": "工作区名称",
4703
+ "field.sessionName": "会话名称",
4704
+ "delete.workspace": "删除工作区",
4705
+ "delete.desc": "将把“{name}”从工作区列表中移除。文件夹与会话记录会保留,其会话将显示在“未分组”下。",
4706
+ "delete.pending": "正在删除工作区…",
4707
+ "menu.fork": "分叉会话",
4708
+ "menu.archiveSession": "归档会话",
4709
+ "sessions.count.one": "{n} 个会话",
4710
+ "sessions.count.other": "{n} 个会话",
4711
+ "actions.workspace.aria": "工作区“{name}”的操作",
4712
+ "actions.session.aria": "会话“{name}”的操作",
4713
+ "actions.newSession.aria": "在“{name}”中新建会话",
4714
+ "status.running": "进行中",
4715
+ "status.subagentsRunning.one": "{n} 个子代理运行中",
4716
+ "status.subagentsRunning.other": "{n} 个子代理运行中",
4717
+ "status.idle": "空闲",
4718
+ "status.waitingApproval": "等待审批",
4719
+ "status.planReview": "计划待审",
4720
+ "status.waitingAnswer": "等待回答",
4721
+ "status.completed": "已完成",
4722
+ "hover.created": "创建于 {time}",
4723
+ "hover.copied": "已复制",
4724
+ "date.ymd": "{y}年{m}月{d}日",
4725
+ "time.now": "刚刚",
4726
+ "time.minutes": "{n}分钟",
4727
+ "time.hours": "{n}小时",
4728
+ "time.days": "{n}天",
4729
+ "time.months": "{n}个月",
4730
+ "time.years": "{n}年",
4731
+ "time.ago": "{t}前",
4732
+ copy: "复制",
4733
+ close: "关闭",
4734
+ cancel: "取消"
1709
4735
  };
1710
4736
  //#endregion
1711
4737
  //#region src/client/index.ts
@@ -1716,12 +4742,14 @@ window.__ModuleLoader__.load({
1716
4742
  * imported: a client package must not depend on a Host package.
1717
4743
  */
1718
4744
  const GIT_WORKTREE_NS = "git-worktree";
1719
- /** Required services: the slot ledger, session/workspace runtime, copy, and
1720
- * the settings scope backing the plugin configuration card. */
4745
+ /** Required services: the slot ledger, session/workspace runtimes, the
4746
+ * workspace navigation/directory face, copy, and the settings scope backing
4747
+ * the plugin configuration card. */
1721
4748
  const inject = [
1722
4749
  "slots",
1723
4750
  "sessions",
1724
4751
  "workspaces",
4752
+ "uiWorkspace",
1725
4753
  "locale",
1726
4754
  "connection",
1727
4755
  "remote",
@@ -1732,10 +4760,13 @@ window.__ModuleLoader__.load({
1732
4760
  zh,
1733
4761
  en
1734
4762
  }), "git-worktree: dictionaries");
1735
- const chipInjected = () => ({ adoptWorktree: async (path) => {
1736
- const workspace = await ctx.workspaces.create({ path });
1737
- ctx.workspaces.startSession(workspace.workspaceId);
1738
- } });
4763
+ const chipInjected = () => ({
4764
+ adoptWorktree: async (path) => {
4765
+ const workspace = await ctx.workspaces.create({ path });
4766
+ ctx.uiWorkspace.startSession(workspace.workspaceId);
4767
+ },
4768
+ sessionsList: ctx.sessions.list
4769
+ });
1739
4770
  ctx.slots.inject("conversation.input.left", () => ctx.slots.register({
1740
4771
  name: "conversation.input.left",
1741
4772
  id: "git-worktree",
@@ -1743,18 +4774,174 @@ window.__ModuleLoader__.load({
1743
4774
  locale: NS,
1744
4775
  inject: chipInjected
1745
4776
  }, BranchChipDock));
1746
- const form = new CardForm(ctx.settingsScope.bind({ namespace: GIT_WORKTREE_NS }));
4777
+ const groupingScope = ctx.settingsScope.bind({ namespace: GIT_WORKTREE_NS });
4778
+ const SEAT_READY_TIMEOUT_MS = 2e4;
4779
+ const SNAPSHOT_WAIT_MS = 8e3;
4780
+ let groupingDisposer;
4781
+ let groupingEnabled;
4782
+ let seatEpoch = 0;
4783
+ let seatReady = Promise.resolve();
4784
+ let seatReadyResolve;
4785
+ let seatTimer;
4786
+ const finishSeat = () => {
4787
+ if (seatTimer !== void 0) {
4788
+ window.clearTimeout(seatTimer);
4789
+ seatTimer = void 0;
4790
+ }
4791
+ const resolve = seatReadyResolve;
4792
+ seatReadyResolve = void 0;
4793
+ resolve?.();
4794
+ };
4795
+ const afterPaint = () => new Promise((resolve) => {
4796
+ if (typeof requestAnimationFrame === "function") {
4797
+ requestAnimationFrame(() => {
4798
+ requestAnimationFrame(() => {
4799
+ resolve();
4800
+ });
4801
+ });
4802
+ return;
4803
+ }
4804
+ setTimeout(resolve, 0);
4805
+ });
4806
+ const groupingMatches = (enabled) => {
4807
+ const snapshot = groupingScope.getSnapshot();
4808
+ return snapshot.status === "ready" && (snapshot.value?.groupSidebar ?? true) === enabled;
4809
+ };
4810
+ const waitSnapshotMatches = async (enabled) => {
4811
+ if (groupingMatches(enabled)) return;
4812
+ await new Promise((resolve) => {
4813
+ const stop = groupingScope.subscribe(() => {
4814
+ if (!groupingMatches(enabled)) return;
4815
+ stop();
4816
+ window.clearTimeout(timer);
4817
+ resolve();
4818
+ });
4819
+ const timer = window.setTimeout(() => {
4820
+ stop();
4821
+ resolve();
4822
+ }, SNAPSHOT_WAIT_MS);
4823
+ if (groupingMatches(enabled)) {
4824
+ window.clearTimeout(timer);
4825
+ stop();
4826
+ resolve();
4827
+ }
4828
+ });
4829
+ };
4830
+ const syncGroupingSeat = () => {
4831
+ const snapshot = groupingScope.getSnapshot();
4832
+ if (snapshot.status !== "ready") return seatReady;
4833
+ const enabled = snapshot.value?.groupSidebar ?? true;
4834
+ if (enabled === groupingEnabled) return seatReady;
4835
+ groupingEnabled = enabled;
4836
+ if (groupingDisposer !== void 0) {
4837
+ groupingDisposer();
4838
+ groupingDisposer = void 0;
4839
+ }
4840
+ const epoch = ++seatEpoch;
4841
+ seatReady = new Promise((resolve) => {
4842
+ seatReadyResolve = resolve;
4843
+ });
4844
+ if (!enabled) {
4845
+ afterPaint().then(() => {
4846
+ if (epoch === seatEpoch) finishSeat();
4847
+ });
4848
+ return seatReady;
4849
+ }
4850
+ const injectFace = () => ({
4851
+ workspacesList: ctx.workspaces.list,
4852
+ sessionsList: ctx.sessions.list,
4853
+ openSession: (sessionId) => {
4854
+ ctx.sessions.open(sessionId);
4855
+ },
4856
+ startSession: (workspaceId) => {
4857
+ ctx.uiWorkspace.startSession(workspaceId);
4858
+ },
4859
+ loadFacts: async (paths) => {
4860
+ const result = await requestGroupWorktrees(paths);
4861
+ return result.ok ? result.facts : void 0;
4862
+ },
4863
+ searchSessions: async (query, signal) => {
4864
+ const result = await ctx.sessions.search(query, signal);
4865
+ if (!result.ok) throw new Error(result.error.message);
4866
+ return result.value;
4867
+ },
4868
+ searchResultLimit: ctx.sessions.searchResultLimit,
4869
+ renameSession: async (sessionId, title) => {
4870
+ const session = ctx.sessions.binding(sessionId)?.session;
4871
+ if (session === void 0) throw new Error(`unknown session "${sessionId}"`);
4872
+ const result = await session.rename(title);
4873
+ if (!result.ok) throw new Error(result.error.message);
4874
+ },
4875
+ forkSession: (sessionId) => {
4876
+ ctx.sessions.fork({
4877
+ sessionId,
4878
+ increaseTitle: true
4879
+ }).then((childId) => {
4880
+ ctx.sessions.open(childId);
4881
+ }).catch(() => {});
4882
+ },
4883
+ renameWorkspace: async (workspaceId, title) => {
4884
+ await ctx.workspaces.rename(workspaceId, title);
4885
+ },
4886
+ deleteWorkspace: async (workspaceId) => {
4887
+ await ctx.workspaces.delete(workspaceId);
4888
+ },
4889
+ archiveSession: async (sessionId) => {
4890
+ await ctx.workspaces.archiveSession(sessionId);
4891
+ },
4892
+ createWorkspace: (input) => ctx.workspaces.create(input),
4893
+ pickDirectory: () => ctx.uiWorkspace.pickDirectory(),
4894
+ hostInfo: (() => {
4895
+ const generation = ctx.get("connection").generation;
4896
+ return {
4897
+ getSnapshot: () => ctx.remote.$host,
4898
+ subscribe: (listener) => generation.subscribe(listener)
4899
+ };
4900
+ })(),
4901
+ directoryFlow: {
4902
+ getSnapshot: () => ctx.slots.entries("sidebar.workspaces.directoryFlow").length > 0,
4903
+ subscribe: (listener) => ctx.slots.subscribe("sidebar.workspaces.directoryFlow", listener)
4904
+ },
4905
+ onReady: () => {
4906
+ if (epoch === seatEpoch) finishSeat();
4907
+ }
4908
+ });
4909
+ groupingDisposer = ctx.slots.inject("sidebar.workspaces", () => ctx.slots.register({
4910
+ name: "sidebar.workspaces",
4911
+ priority: -1,
4912
+ locale: NS,
4913
+ inject: injectFace
4914
+ }, GroupedSidebar));
4915
+ seatTimer = window.setTimeout(() => {
4916
+ if (epoch === seatEpoch) finishSeat();
4917
+ }, SEAT_READY_TIMEOUT_MS);
4918
+ return seatReady;
4919
+ };
4920
+ const waitForGroupingSeat = async (enabled) => {
4921
+ await waitSnapshotMatches(enabled);
4922
+ await syncGroupingSeat();
4923
+ };
4924
+ const form = new CardForm(groupingScope, waitForGroupingSeat);
1747
4925
  const store = form.bind();
1748
4926
  ctx.slots.inject("settings.plugin.item", () => ctx.slots.register({
1749
4927
  name: "settings.plugin.item",
1750
4928
  key: GIT_WORKTREE_NS,
4929
+ priority: -1,
1751
4930
  locale: NS,
1752
4931
  inject: () => ({
1753
4932
  hooks: { gitWorktreeCard: store },
1754
4933
  ...form.actions(),
1755
- pickDirectory: () => ctx.workspaces.pickDirectory()
4934
+ pickDirectory: () => ctx.uiWorkspace.pickDirectory()
1756
4935
  })
1757
4936
  }, GitWorktreeCard));
4937
+ syncGroupingSeat();
4938
+ const unsubscribeGrouping = groupingScope.subscribe(() => {
4939
+ syncGroupingSeat();
4940
+ });
4941
+ ctx.effect(() => () => {
4942
+ unsubscribeGrouping();
4943
+ if (groupingDisposer !== void 0) groupingDisposer();
4944
+ }, "git-worktree: sidebar grouping lifecycle");
1758
4945
  }
1759
4946
  //#endregion
1760
4947
  exports.apply = apply;