@laoyuehanni/dsh-git-worktree 0.4.0

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 ADDED
@@ -0,0 +1,1766 @@
1
+ window.__ModuleLoader__.load({
2
+ id: "@laoyuehanni/dsh-git-worktree",
3
+ factory: (require) => {
4
+ var module = { exports: {} };
5
+ var exports = module.exports;
6
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
+ let react = require("react");
8
+ let react_dom = require("react-dom");
9
+ let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
10
+ let react_jsx_runtime = require("react/jsx-runtime");
11
+ //#region src/normalize.ts
12
+ /**
13
+ * Local branch name for a display name: strip the leading `<remote>/` segment
14
+ * when one is present (`origin/feat/x` → `feat/x`). A local branch whose own
15
+ * name contains `/` (like `feat/x`) passes through unchanged — callers that
16
+ * need certainty compare against the authoritative branch list instead.
17
+ * @param branch - branch display name.
18
+ * @returns the candidate local branch name.
19
+ */
20
+ function localBranchName(branch) {
21
+ const at = branch.indexOf("/");
22
+ return at <= 0 ? branch : branch.slice(at + 1);
23
+ }
24
+ //#endregion
25
+ //#region src/wire.ts
26
+ /**
27
+ * Shared wire contract between the host half (HTTP routes under
28
+ * `/plugin/git-worktree`) and the browser half (chip + plugin settings card).
29
+ * Zero runtime dependencies: constants and types only, imported by both
30
+ * builds.
31
+ */
32
+ /** Absolute pathname prefix every route of this plugin lives under. */
33
+ const ROUTE_PREFIX = "/plugin/git-worktree";
34
+ /** GET ROUTE_PREFIX/status?path=<absolute dir> */
35
+ const ROUTE_STATUS = `${ROUTE_PREFIX}/status`;
36
+ /** POST ROUTE_PREFIX/worktree — create-or-reuse a worktree for a branch. */
37
+ const ROUTE_WORKTREE = `${ROUTE_PREFIX}/worktree`;
38
+ /** POST ROUTE_PREFIX/switch — in-place branch switch of the main checkout. */
39
+ const ROUTE_SWITCH = `${ROUTE_PREFIX}/switch`;
40
+ //#endregion
41
+ //#region src/client/api.ts
42
+ /** POST one JSON body and parse the uniform envelope. */
43
+ async function post(url, body) {
44
+ return send("POST", url, body);
45
+ }
46
+ /** Send one JSON body with any method and parse the uniform envelope. */
47
+ async function send(method, url, body) {
48
+ try {
49
+ const response = await fetch(url, {
50
+ method,
51
+ headers: { "content-type": "application/json" },
52
+ body: JSON.stringify(body)
53
+ });
54
+ const payload = await response.json();
55
+ if (!response.ok) return {
56
+ ok: false,
57
+ error: payload.error ?? `HTTP ${String(response.status)}`
58
+ };
59
+ return {
60
+ ...payload,
61
+ ok: true
62
+ };
63
+ } catch (cause) {
64
+ return {
65
+ ok: false,
66
+ error: cause instanceof Error ? cause.message : String(cause)
67
+ };
68
+ }
69
+ }
70
+ /**
71
+ * Repository status for one directory.
72
+ * @param path - absolute workspace directory.
73
+ */
74
+ async function fetchStatus(path) {
75
+ try {
76
+ const response = await fetch(`${ROUTE_STATUS}?path=${encodeURIComponent(path)}`, { cache: "no-store" });
77
+ if (!response.ok) return {
78
+ ok: false,
79
+ error: `HTTP ${String(response.status)}`
80
+ };
81
+ return {
82
+ ...await response.json(),
83
+ ok: true
84
+ };
85
+ } catch (cause) {
86
+ return {
87
+ ok: false,
88
+ error: cause instanceof Error ? cause.message : String(cause)
89
+ };
90
+ }
91
+ }
92
+ /**
93
+ * Create or reuse the worktree for a branch.
94
+ * @param repoPath - absolute directory inside the repository.
95
+ * @param branch - branch display name.
96
+ */
97
+ function requestWorktree(repoPath, branch) {
98
+ return post(ROUTE_WORKTREE, {
99
+ repoPath,
100
+ branch
101
+ });
102
+ }
103
+ /**
104
+ * Cut a NEW branch out of the current checkout and isolate it in a fresh
105
+ * worktree (the current branch itself is occupied by the main worktree).
106
+ * @param repoPath - absolute directory inside the repository.
107
+ * @param branch - the current checkout's branch (or `HEAD` when detached).
108
+ */
109
+ function requestWorktreeCutout(repoPath, branch) {
110
+ return post(ROUTE_WORKTREE, {
111
+ repoPath,
112
+ branch,
113
+ cutout: true
114
+ });
115
+ }
116
+ /**
117
+ * Switch the main checkout in place.
118
+ * @param repoPath - absolute directory inside the main worktree.
119
+ * @param branch - branch display name.
120
+ */
121
+ function requestSwitch(repoPath, branch) {
122
+ return post(ROUTE_SWITCH, {
123
+ repoPath,
124
+ branch
125
+ });
126
+ }
127
+ //#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) {
132
+ const tag = document.createElement("style");
133
+ tag.dataset.plugin = "@laoyuehanni/dsh-git-worktree";
134
+ tag.dataset.pluginCss = tagId$1;
135
+ tag.textContent = css$1;
136
+ document.head.appendChild(tag);
137
+ }
138
+ 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"
173
+ };
174
+ //#endregion
175
+ //#region src/client/BranchMenu.tsx
176
+ /**
177
+ * BranchMenu: the branch picker popup anchored to the composer branch chip.
178
+ * The base Menu primitive exposes neither a height cap nor a search field,
179
+ * so with many branches its portal list fills the viewport — this popup
180
+ * replaces it with an owner-styled card: Menu's card chrome (r12, inverted
181
+ * hairline, shadow-lv3, --dsw-specific-menu, see .menuCard) on a
182
+ * portal-fixed posture, with owner requirements baked in:
183
+ *
184
+ * 1. the card is capped at min(420px, 60vh) and only the branch rows
185
+ * scroll (heading, search, and the toolbar stay pinned);
186
+ * 2. a search field is pinned at the card's bottom edge — the row list
187
+ * scrolls above it — filtering rows by case-insensitive substring
188
+ * while KEEPING the matching branches' ancestor folders (IDEA-style
189
+ * prune) and highlighting the hit substring;
190
+ * 3. the card opens entirely above the chip: the CSS `bottom` pins its
191
+ * bottom edge ~6px above the chip's top, so it grows upward and can
192
+ * never cover the composer, whatever the branch count.
193
+ *
194
+ * 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
198
+ * right-side confirm flyout for that row — the switch itself always goes
199
+ * through the confirmation step, never straight away. While the confirm
200
+ * flyout is open, clicking another row re-anchors it (the old one-click
201
+ * pick flow).
202
+ *
203
+ * The confirm step is a second-level flyout opening to the RIGHT of the
204
+ * branch card (the base Menu's submenu posture): the chip sits in the
205
+ * bottom composer, so the old below-the-chip bubble landed off-viewport.
206
+ * The flyout is a separate portal (not clipped by the card's
207
+ * overflow:hidden), horizontally anchored to the card's right edge — it
208
+ * can never overlap the branch list — and vertically centered on the
209
+ * picked row. Its width is content-driven, capped in CSS, wrapping.
210
+ *
211
+ * Close semantics: outside pointerdown (card, flyout, and chip excluded)
212
+ * 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.
215
+ *
216
+ * 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).
224
+ */
225
+ /** Viewport edge clearance, mirroring the base Menu portal margin. */
226
+ const MARGIN = 12;
227
+ /** Gap kept between the chip's top edge and the card's bottom edge. */
228
+ const GAP = 6;
229
+ /** Design card width — the CSS width's px arm; used for horizontal clamping. */
230
+ const CARD_WIDTH = 360;
231
+ /** Design flyout width cap — matches .popCard's max-width arm. */
232
+ const FLY_MAX_WIDTH = 400;
233
+ /** After a folder toggle, clicks arriving within this window are swallowed
234
+ * (double-click misfire guard — see shiftGuardUntil in the component). */
235
+ const CLICK_GUARD_MS = 250;
236
+ /** Unplaced flyout: hidden but laid out at a fixed origin so offsetWidth/
237
+ * offsetHeight are real for the measure-then-place pass (base Menu trick). */
238
+ const FLY_MEASURE = {
239
+ left: "-9999px",
240
+ top: "0px",
241
+ visibility: "hidden"
242
+ };
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. */
245
+ const TREE_MIN_ROWS = 8;
246
+ const segCmp = (a, b) => a.localeCompare(b, void 0, {
247
+ numeric: true,
248
+ sensitivity: "base"
249
+ });
250
+ /** Build the prefix tree of the rows (see TreeNode). */
251
+ function buildTree(rows) {
252
+ const root = [];
253
+ const find = (level, segment) => level.find((n) => n.segment === segment);
254
+ for (const row of rows) {
255
+ const segs = row.name.split("/").filter((s) => s !== "");
256
+ let level = root;
257
+ let path = "";
258
+ for (let i = 0; i < segs.length; i += 1) {
259
+ path = path === "" ? segs[i] : `${path}/${segs[i]}`;
260
+ let node = find(level, segs[i]);
261
+ if (node === void 0) {
262
+ node = {
263
+ segment: segs[i],
264
+ path,
265
+ depth: i,
266
+ leaf: null,
267
+ children: [],
268
+ total: 0
269
+ };
270
+ level.push(node);
271
+ }
272
+ if (i === segs.length - 1) node.leaf = row;
273
+ level = node.children;
274
+ }
275
+ }
276
+ const finish = (nodes) => {
277
+ for (const node of nodes) finish(node.children);
278
+ nodes.sort((a, b) => {
279
+ const af = a.children.length > 0 ? 0 : 1;
280
+ const bf = b.children.length > 0 ? 0 : 1;
281
+ return af !== bf ? af - bf : segCmp(a.segment, b.segment);
282
+ });
283
+ };
284
+ finish(root);
285
+ const count = (nodes) => {
286
+ for (const node of nodes) {
287
+ count(node.children);
288
+ node.total = (node.leaf === null ? 0 : 1) + node.children.reduce((sum, c) => sum + c.total, 0);
289
+ }
290
+ };
291
+ count(root);
292
+ return root;
293
+ }
294
+ /** The folders that must start expanded so the checked-out branch is
295
+ * immediately visible in the tree: every proper ancestor of its path. */
296
+ function chainExpanded(branch) {
297
+ const segs = branch.split("/").filter((s) => s !== "");
298
+ const set = /* @__PURE__ */ new Set();
299
+ let path = "";
300
+ for (let i = 0; i < segs.length - 1; i += 1) {
301
+ path = path === "" ? segs[i] : `${path}/${segs[i]}`;
302
+ set.add(path);
303
+ }
304
+ return set;
305
+ }
306
+ /** Hover tooltip: set the native `title` ONLY when the label is actually
307
+ * clipped (scrollWidth > clientWidth) — fitted names show no tooltip, and
308
+ * long ones expose their full path without a custom bubble. The target is
309
+ * the label span (first span child), the clipped element. */
310
+ const gateTooltip = (button, name) => {
311
+ const label = button.querySelector(":scope > span");
312
+ if (label !== null) label.title = label.scrollWidth > label.clientWidth ? name : "";
313
+ };
314
+ /** Leaving a row drops its tooltip so a recycled DOM node (search refilter)
315
+ * can never show a stale title for another branch. */
316
+ const clearTooltip = (button) => {
317
+ const label = button.querySelector(":scope > span");
318
+ if (label !== null) label.title = "";
319
+ };
320
+ /**
321
+ * Render the upward branch picker with its right-side confirm flyout.
322
+ * @param props - anchor, rows, confirm bundle, callbacks, and the class sheet.
323
+ * @returns null while closed or unplaced; otherwise the portaled card (+flyout).
324
+ */
325
+ function BranchMenu({ open, anchorRef, rows, currentBranch, confirm, onSelect, onClose, t }) {
326
+ const cardRef = (0, react.useRef)(null);
327
+ const inputRef = (0, react.useRef)(null);
328
+ /**
329
+ * Search-field ref callback: focus the field the moment it mounts. The
330
+ * card mounts in two stages (open flips, then pos resolves a render
331
+ * later), so an [open]-keyed passive effect fires while the input is
332
+ * still unmounted — its focus() no-ops against a null ref. Focusing at
333
+ * mount time is immune to that race by construction.
334
+ */
335
+ const holdSearchFocus = (el) => {
336
+ inputRef.current = el;
337
+ if (el !== null) el.focus();
338
+ };
339
+ const flyRef = (0, react.useRef)(null);
340
+ const flyConfirmRef = (0, react.useRef)(null);
341
+ /** The row whose pick is awaiting confirmation (anchoring element). */
342
+ const pendingRef = (0, react.useRef)(null);
343
+ /** Pending row's name — the placement-effect trigger: picking another
344
+ * row while the flyout is open must re-anchor it (confirmOpen alone
345
+ * stays true, so a ref mutation re-renders nothing). */
346
+ const [pendingName, setPendingName] = (0, react.useState)(null);
347
+ const [pos, setPos] = (0, react.useState)(null);
348
+ const [flyPos, setFlyPos] = (0, react.useState)(null);
349
+ 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. */
352
+ const [expanded, setExpanded] = (0, react.useState)(/* @__PURE__ */ new Set());
353
+ /** IDEA-style selection: clicked row (blue). Zero or one at a time. */
354
+ const [selected, setSelected] = (0, react.useState)(null);
355
+ const confirmRef = (0, react.useRef)(confirm);
356
+ confirmRef.current = confirm;
357
+ const queryRef = (0, react.useRef)(query);
358
+ queryRef.current = query;
359
+ const selectedRef = (0, react.useRef)(selected);
360
+ selectedRef.current = selected;
361
+ /** Always-fresh pick for the stale-safe document keydown listener. */
362
+ const pickRef = (0, react.useRef)(() => {});
363
+ const confirmOpen = confirm !== null;
364
+ /**
365
+ * Double-click misfire guard: toggling a folder shifts the layout — the
366
+ * second click of a double-click can land on a row that slid under the
367
+ * cursor (a branch!), which would select it or pop the switch flyout.
368
+ * After a folder toggle, every click swallowed for CLICK_GUARD_MS, so a
369
+ * double-click on a folder expands it exactly once and never bleeds into
370
+ * a branch click. Branch-row clicks do not arm the guard (selecting does
371
+ * not move anything), so row double-clicks keep working instantly.
372
+ */
373
+ const shiftGuardUntil = (0, react.useRef)(0);
374
+ const guardActive = () => Date.now() < shiftGuardUntil.current;
375
+ const armShiftGuard = () => {
376
+ shiftGuardUntil.current = Date.now() + CLICK_GUARD_MS;
377
+ };
378
+ /** Stage a pick: remember the row element (the flyout anchors beside
379
+ * it), then hand the branch to the owner. All pick paths — search Enter,
380
+ * keyboard Enter on a selected row — funnel through here. */
381
+ const pick = (el, name) => {
382
+ if (el !== null) pendingRef.current = {
383
+ name,
384
+ el
385
+ };
386
+ setPendingName(name);
387
+ onSelect(name);
388
+ };
389
+ 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));
407
+ const toggleAll = () => {
408
+ setExpanded(allExpanded ? /* @__PURE__ */ new Set() : new Set(folderPaths));
409
+ };
410
+ const locateCurrent = () => {
411
+ setExpanded((prev) => {
412
+ const next = new Set(prev);
413
+ for (const p of chainExpanded(currentBranch)) next.add(p);
414
+ return next;
415
+ });
416
+ requestAnimationFrame(() => {
417
+ if (rowsRef.current !== null) centerCurrentRow(rowsRef.current);
418
+ });
419
+ };
420
+ (0, react.useEffect)(() => {
421
+ if (!open) return;
422
+ setQuery("");
423
+ setSelected(null);
424
+ setExpanded(chainExpanded(currentBranch));
425
+ }, [open, currentBranch]);
426
+ (0, react.useEffect)(() => {
427
+ if (selected !== null && !rows.some((r) => r.name === selected)) setSelected(null);
428
+ }, [rows, selected]);
429
+ /** Toggle one folder header. */
430
+ const toggle = (path) => {
431
+ setExpanded((prev) => {
432
+ const next = new Set(prev);
433
+ if (next.has(path)) next.delete(path);
434
+ else next.add(path);
435
+ return next;
436
+ });
437
+ };
438
+ (0, react.useLayoutEffect)(() => {
439
+ if (!open) {
440
+ setPos(null);
441
+ return;
442
+ }
443
+ const place = () => {
444
+ const anchor = anchorRef.current;
445
+ if (anchor === null) return;
446
+ const rect = anchor.getBoundingClientRect();
447
+ const vw = window.innerWidth;
448
+ const vh = window.innerHeight;
449
+ const left = Math.min(Math.max(rect.left, MARGIN), Math.max(MARGIN, vw - CARD_WIDTH - MARGIN));
450
+ setPos({
451
+ left,
452
+ bottom: vh - rect.top + GAP
453
+ });
454
+ };
455
+ place();
456
+ window.addEventListener("resize", place);
457
+ window.addEventListener("scroll", place, true);
458
+ return () => {
459
+ window.removeEventListener("resize", place);
460
+ window.removeEventListener("scroll", place, true);
461
+ };
462
+ }, [open, anchorRef]);
463
+ const rowsRef = (0, react.useRef)(null);
464
+ const centerCurrentRow = (0, react.useCallback)((viewport) => {
465
+ const row = [...viewport.querySelectorAll("button[role=\"menuitem\"][data-branch]")].find((b) => (b.dataset.branch ?? "") === currentBranch);
466
+ if (row === void 0) return;
467
+ const rowRect = row.getBoundingClientRect();
468
+ const vpRect = viewport.getBoundingClientRect();
469
+ const target = viewport.scrollTop + (rowRect.top - vpRect.top) - (viewport.clientHeight - rowRect.height) / 2;
470
+ viewport.scrollTo({ top: Math.max(0, target) });
471
+ }, [currentBranch]);
472
+ const holdRowsCenter = (0, react.useCallback)((el) => {
473
+ rowsRef.current = el;
474
+ if (el !== null) centerCurrentRow(el);
475
+ }, [centerCurrentRow]);
476
+ (0, react.useEffect)(() => {
477
+ if (!open || query.trim() !== "") return;
478
+ if (rowsRef.current !== null) centerCurrentRow(rowsRef.current);
479
+ }, [
480
+ open,
481
+ query,
482
+ centerCurrentRow
483
+ ]);
484
+ (0, react.useEffect)(() => {
485
+ if (!open) return;
486
+ const raf = requestAnimationFrame(() => {
487
+ if (rowsRef.current !== null) centerCurrentRow(rowsRef.current);
488
+ });
489
+ return () => {
490
+ cancelAnimationFrame(raf);
491
+ };
492
+ }, [open, centerCurrentRow]);
493
+ (0, react.useLayoutEffect)(() => {
494
+ if (!confirmOpen || pendingName === null) {
495
+ setFlyPos(null);
496
+ return;
497
+ }
498
+ const place = () => {
499
+ const pending = pendingRef.current;
500
+ const fly = flyRef.current;
501
+ const card = cardRef.current;
502
+ if (pending === null || fly === null || card === null) return;
503
+ const row = pending.el.getBoundingClientRect();
504
+ const cr = card.getBoundingClientRect();
505
+ const vw = window.innerWidth;
506
+ const vh = window.innerHeight;
507
+ const left = cr.right + GAP;
508
+ const room = Math.min(FLY_MAX_WIDTH, Math.max(200, vw - MARGIN - left));
509
+ fly.style.maxWidth = `${room}px`;
510
+ const fw = fly.offsetWidth;
511
+ const fh = fly.offsetHeight;
512
+ const top = Math.min(Math.max(row.top + row.height / 2 - fh / 2, MARGIN), Math.max(MARGIN, vh - fh - MARGIN));
513
+ setFlyPos({
514
+ left: Math.min(left, vw - MARGIN - fw),
515
+ top
516
+ });
517
+ };
518
+ place();
519
+ window.addEventListener("resize", place);
520
+ window.addEventListener("scroll", place, true);
521
+ return () => {
522
+ window.removeEventListener("resize", place);
523
+ window.removeEventListener("scroll", place, true);
524
+ };
525
+ }, [confirmOpen, pendingName]);
526
+ (0, react.useEffect)(() => {
527
+ if (confirmOpen && pendingName !== null) {
528
+ const raf = requestAnimationFrame(() => {
529
+ flyConfirmRef.current?.focus();
530
+ });
531
+ return () => {
532
+ cancelAnimationFrame(raf);
533
+ };
534
+ }
535
+ if (!confirmOpen) {
536
+ pendingRef.current = null;
537
+ setPendingName(null);
538
+ }
539
+ }, [confirmOpen, pendingName]);
540
+ (0, react.useEffect)(() => {
541
+ if (!open) return;
542
+ const onPointerDown = (event) => {
543
+ if (cardRef.current?.contains(event.target) === true) return;
544
+ if (flyRef.current?.contains(event.target) === true) return;
545
+ if (anchorRef.current?.contains(event.target) === true) return;
546
+ confirmRef.current?.onCancel();
547
+ onClose();
548
+ };
549
+ const onKeyDown = (event) => {
550
+ const key = event.key;
551
+ if (key === "Escape") {
552
+ if (confirmRef.current !== null) {
553
+ confirmRef.current.onCancel();
554
+ return;
555
+ }
556
+ if (queryRef.current.trim() !== "") {
557
+ setQuery("");
558
+ return;
559
+ }
560
+ if (selectedRef.current !== null) {
561
+ setSelected(null);
562
+ return;
563
+ }
564
+ onClose();
565
+ return;
566
+ }
567
+ const card = cardRef.current;
568
+ const active = document.activeElement;
569
+ if (card === null || active === null || !card.contains(active)) return;
570
+ if (active === card.querySelector("input")) return;
571
+ const leaves = [...card.querySelectorAll("button[role=\"menuitem\"][data-branch]")];
572
+ if (key === "ArrowDown" || key === "ArrowUp") {
573
+ event.preventDefault();
574
+ if (leaves.length === 0) return;
575
+ const idx = leaves.findIndex((b) => (b.dataset.branch ?? "") === selectedRef.current);
576
+ let next = idx;
577
+ if (key === "ArrowDown") next = idx < 0 ? 0 : Math.min(leaves.length - 1, idx + 1);
578
+ else next = idx <= 0 ? leaves.length - 1 : idx - 1;
579
+ const target = leaves[next];
580
+ const name = target.dataset.branch ?? null;
581
+ if (name !== null) setSelected(name);
582
+ target.focus();
583
+ target.scrollIntoView({ block: "nearest" });
584
+ } else if (key === "Enter" && selectedRef.current !== null) {
585
+ event.preventDefault();
586
+ const el = leaves.find((b) => (b.dataset.branch ?? "") === selectedRef.current) ?? null;
587
+ pickRef.current(el, selectedRef.current);
588
+ }
589
+ };
590
+ document.addEventListener("pointerdown", onPointerDown, true);
591
+ document.addEventListener("keydown", onKeyDown);
592
+ return () => {
593
+ document.removeEventListener("pointerdown", onPointerDown, true);
594
+ document.removeEventListener("keydown", onKeyDown);
595
+ };
596
+ }, [
597
+ open,
598
+ onClose,
599
+ anchorRef
600
+ ]);
601
+ if (!open || pos === null) return null;
602
+ 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). */
607
+ const commitFirst = () => {
608
+ const first = visible.find((row) => !row.disabled);
609
+ if (first === void 0) return;
610
+ const card = cardRef.current;
611
+ if (card === null) return;
612
+ const el = card.querySelector(`button[data-branch="${CSS.escape(first.name)}"]`);
613
+ pick(el, first.name);
614
+ };
615
+ /** Row class composition: base + HEAD tint + selection (selection wins). */
616
+ const rowClass = (name) => {
617
+ let cls = BranchChip_module_default.menuRow;
618
+ if (name === currentBranch) cls += ` ${BranchChip_module_default.menuRowSelected}`;
619
+ if (name === selected) cls += ` ${BranchChip_module_default.menuRowPicked}`;
620
+ return cls;
621
+ };
622
+ /** A row's click behavior: with the confirm flyout open, clicking a row
623
+ * re-picks it (the old one-click flow — the flyout re-anchors); without
624
+ * one it just selects (IDEA model — double-click or Enter opens the
625
+ * confirm flyout for the selected row). */
626
+ const rowClick = (el, name) => {
627
+ if (confirmOpen) pick(el, name);
628
+ else setSelected(name);
629
+ };
630
+ /** Wrap every case-insensitive occurrence of `needle` in `text` with the
631
+ * search-mark span (IDEA-style hit highlight). */
632
+ const renderLabel = (text) => {
633
+ if (needle === "") return text;
634
+ const out = [];
635
+ let rest = text;
636
+ let key = 0;
637
+ for (;;) {
638
+ const idx = rest.toLowerCase().indexOf(needle);
639
+ if (idx === -1) {
640
+ out.push(rest);
641
+ break;
642
+ }
643
+ if (idx > 0) out.push(rest.slice(0, idx));
644
+ out.push(/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
645
+ className: BranchChip_module_default.menuSearchMark,
646
+ children: rest.slice(idx, idx + needle.length)
647
+ }, key));
648
+ key += 1;
649
+ rest = rest.slice(idx + needle.length);
650
+ }
651
+ return out;
652
+ };
653
+ /** Does any leaf under these nodes match the needle? */
654
+ const subtreeMatches = (nodes) => {
655
+ for (const node of nodes) {
656
+ if (node.leaf !== null && node.leaf.name.toLowerCase().includes(needle)) return true;
657
+ if (subtreeMatches(node.children)) return true;
658
+ }
659
+ return false;
660
+ };
661
+ /** One tree group-header row: its own segment (a compressed chain's
662
+ * walked segments join the label), a count badge, and a chevron that
663
+ * 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);
667
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
668
+ type: "button",
669
+ className: BranchChip_module_default.menuGroup,
670
+ "data-group": node.path,
671
+ style: { paddingLeft: 8 + depth * 12 },
672
+ "aria-expanded": isOpen,
673
+ onClick: () => {
674
+ if (guardActive()) return;
675
+ toggle(node.path);
676
+ armShiftGuard();
677
+ },
678
+ children: [
679
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronRightOutline14, {
680
+ size: 12,
681
+ className: isOpen ? `${BranchChip_module_default.menuGroupChevron} ${BranchChip_module_default.menuGroupChevronOpen}` : BranchChip_module_default.menuGroupChevron
682
+ }),
683
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
684
+ className: BranchChip_module_default.menuGroupLabel,
685
+ children: label
686
+ }),
687
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
688
+ className: BranchChip_module_default.menuGroupCount,
689
+ children: [
690
+ "(",
691
+ node.total,
692
+ ")"
693
+ ]
694
+ })
695
+ ]
696
+ }, `group:${node.path}`);
697
+ };
698
+ /** One tree leaf row: under an expanded folder it shows only its own
699
+ * segment (indentation carries the hierarchy — no repeated full path);
700
+ * 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", {
703
+ type: "button",
704
+ role: "menuitem",
705
+ "data-branch": node.path,
706
+ className: rowClass(node.path),
707
+ disabled: node.leaf?.disabled ?? false,
708
+ style: { paddingLeft: 8 + depth * 12 },
709
+ onClick: () => {
710
+ if (guardActive()) return;
711
+ rowClick(buttonOf(node.path), node.path);
712
+ },
713
+ onDoubleClick: (event) => {
714
+ if (guardActive()) return;
715
+ pick(event.currentTarget, node.path);
716
+ },
717
+ onMouseEnter: (event) => {
718
+ gateTooltip(event.currentTarget, node.path);
719
+ },
720
+ onMouseLeave: (event) => {
721
+ clearTooltip(event.currentTarget);
722
+ },
723
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
724
+ 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);
728
+ /** Recursive tree renderer. Linear chains — nodes that are neither a
729
+ * branch nor a real fork — compress into the next row's label, so
730
+ * `feature/优化` stays a single flat row instead of a pointless one-entry
731
+ * folder, while a real fork (`a/deep/tree` holding leaf1+leaf2) gets a
732
+ * header whose children show only their own segments. */
733
+ const renderTree = (nodes, depth) => {
734
+ const out = [];
735
+ for (const node of nodes) {
736
+ let cur = node;
737
+ const parts = [];
738
+ while (cur.leaf === null && cur.children.length === 1) {
739
+ parts.push(cur.segment);
740
+ cur = cur.children[0];
741
+ }
742
+ const label = parts.length === 0 ? cur.segment : `${parts.join("/")}/${cur.segment}`;
743
+ if (cur.leaf !== null) {
744
+ out.push(renderLeaf(cur, label, depth));
745
+ 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));
748
+ }
749
+ } else {
750
+ out.push(renderHeader(cur, label, depth));
751
+ if (expanded.has(cur.path)) out.push(...renderTree(cur.children, depth + 1));
752
+ }
753
+ }
754
+ return out;
755
+ };
756
+ /** Search view: keep matching leaves AND their ancestor folders (IDEA's
757
+ * filter keeps the path), hide non-matching siblings, force every kept
758
+ * folder open, and highlight the hit substring. No chain compression —
759
+ * the full ancestor path is exactly the context the search is for. */
760
+ const renderSearch = (nodes, depth) => {
761
+ const out = [];
762
+ for (const node of nodes) {
763
+ const leafHit = node.leaf !== null && node.leaf.name.toLowerCase().includes(needle);
764
+ const childHit = subtreeMatches(node.children);
765
+ if (leafHit) out.push(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
766
+ type: "button",
767
+ role: "menuitem",
768
+ "data-branch": node.path,
769
+ className: rowClass(node.path),
770
+ disabled: node.leaf?.disabled ?? false,
771
+ style: { paddingLeft: 8 + depth * 12 },
772
+ onClick: () => {
773
+ if (guardActive()) return;
774
+ rowClick(buttonOf(node.path), node.path);
775
+ },
776
+ onDoubleClick: (event) => {
777
+ if (guardActive()) return;
778
+ pick(event.currentTarget, node.path);
779
+ },
780
+ onMouseEnter: (event) => {
781
+ gateTooltip(event.currentTarget, node.path);
782
+ },
783
+ onMouseLeave: (event) => {
784
+ clearTooltip(event.currentTarget);
785
+ },
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));
791
+ if (childHit) {
792
+ out.push(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
793
+ role: "presentation",
794
+ className: BranchChip_module_default.menuGroup,
795
+ "data-group": node.path,
796
+ style: { paddingLeft: 8 + depth * 12 },
797
+ children: [
798
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronDownOutline14, {
799
+ size: 12,
800
+ className: BranchChip_module_default.menuGroupChevron
801
+ }),
802
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
803
+ className: BranchChip_module_default.menuGroupLabel,
804
+ children: renderLabel(node.segment)
805
+ }),
806
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
807
+ className: BranchChip_module_default.menuGroupCount,
808
+ children: [
809
+ "(",
810
+ node.total,
811
+ ")"
812
+ ]
813
+ })
814
+ ]
815
+ }, `search:${node.path}`));
816
+ out.push(...renderSearch(node.children, depth + 1));
817
+ }
818
+ }
819
+ return out;
820
+ };
821
+ /** The rendered button for a branch name (flyout anchor on click-select
822
+ * paths, where the handler only has the name at hand). */
823
+ 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 })
878
+ })]
879
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
880
+ className: BranchChip_module_default.menuMain,
881
+ children: [
882
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
883
+ className: BranchChip_module_default.menuHeading,
884
+ children: t("menuLocalBranches")
885
+ }),
886
+ /* @__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")
893
+ })]
894
+ }),
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
+ }
913
+ }
914
+ })
915
+ })
916
+ ]
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)] });
943
+ }
944
+ //#endregion
945
+ //#region src/client/BranchChip.tsx
946
+ /**
947
+ * BranchChipDock: the composer tool-row entry (conversation.input.left, right
948
+ * 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.
958
+ *
959
+ * Checking the worktree toggle pops the cutout confirm dialog right away:
960
+ * confirming it cuts a NEW branch (`<current>-wt`, suffixes past taken
961
+ * names) out of the current checkout into a fresh isolated worktree — the
962
+ * current branch itself is occupied by the main worktree, so git refuses a
963
+ * second worktree on it. The dialog stands alone above the chip (the
964
+ * branch menu stays closed); the chip still opens the menu, where picking
965
+ * another branch keeps the plain create-or-reuse flow and re-picking the
966
+ * current branch stages the same cutout confirm. Dismissing the dialog and
967
+ * sending the message anyway means the user knowingly stays in the current
968
+ * directory — no separate notice fires on send.
969
+ */
970
+ /**
971
+ * Heavier check glyph for the worktree toggle. The base's IconCheckOutline16
972
+ * is a fill path (fixed visual weight); we need a visibly bolder stroke to
973
+ * read inside the 14×14 bluish fill — local to this module so the heavier
974
+ * weight doesn't leak into the rest of the composer chrome.
975
+ */
976
+ function WorktreeCheck({ size = 12 }) {
977
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
978
+ width: size,
979
+ height: size,
980
+ viewBox: "0 0 16 16",
981
+ fill: "none",
982
+ "aria-hidden": "true",
983
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
984
+ d: "M3.2 8.4 L6.6 11.8 L12.8 4.4",
985
+ stroke: "currentColor",
986
+ strokeWidth: "3.2",
987
+ strokeLinecap: "round",
988
+ strokeLinejoin: "round"
989
+ })
990
+ });
991
+ }
992
+ /**
993
+ * Read the repository status for a directory; refetch on demand.
994
+ * @param cwd - absolute session directory.
995
+ * @returns the state holder and a refetch verb.
996
+ */
997
+ function useRepoStatus(cwd) {
998
+ const [state, setState] = (0, react.useState)({ facts: null });
999
+ const load = (0, react.useCallback)(async () => {
1000
+ if (cwd === void 0) {
1001
+ setState({ facts: null });
1002
+ return;
1003
+ }
1004
+ const result = await fetchStatus(cwd);
1005
+ setState({ facts: result.ok && result.repo ? result : null });
1006
+ }, [cwd]);
1007
+ (0, react.useEffect)(() => {
1008
+ let live = true;
1009
+ setState({ facts: null });
1010
+ if (cwd !== void 0) fetchStatus(cwd).then((result) => {
1011
+ if (live) setState({ facts: result.ok && result.repo ? result : null });
1012
+ });
1013
+ return () => {
1014
+ live = false;
1015
+ };
1016
+ }, [cwd]);
1017
+ return [state, load];
1018
+ }
1019
+ /** Longest branch name shown on the chip before ellipsizing (chars, … included). */
1020
+ const BRANCH_DISPLAY_MAX = 25;
1021
+ /** Viewport edge clearance and chip gap, mirroring BranchMenu's posture. */
1022
+ const POP_MARGIN = 12;
1023
+ const POP_GAP = 6;
1024
+ /** Unplaced dialog: hidden but laid out at a fixed origin so offsetWidth is
1025
+ * real for the measure-then-place pass (BranchMenu's flyout trick). */
1026
+ const POP_MEASURE = {
1027
+ left: "-9999px",
1028
+ bottom: "0px",
1029
+ visibility: "hidden"
1030
+ };
1031
+ /**
1032
+ * Clamp a branch name for chip display: names up to 25 chars pass through;
1033
+ * longer ones show the first 24 chars plus an ellipsis.
1034
+ * @param branch - full branch name.
1035
+ */
1036
+ function displayBranch(branch) {
1037
+ return branch.length <= BRANCH_DISPLAY_MAX ? branch : `${branch.slice(0, 24)}…`;
1038
+ }
1039
+ /**
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.
1046
+ */
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
+ }));
1053
+ }
1054
+ /**
1055
+ * The check-time confirm dialog, rendered while the branch menu is closed:
1056
+ * the same popCard chrome as BranchMenu's flyout, but bottom-pinned above
1057
+ * the chip in the menu card's posture — the flyout's right-of-card anchor
1058
+ * has no card to sit beside here. Outside pointerdown and Escape cancel;
1059
+ * the confirm button takes focus so Enter commits.
1060
+ */
1061
+ function ChipConfirm({ anchorRef, ask, confirmLabel, cancelLabel, busy, onConfirm, onCancel }) {
1062
+ const popRef = (0, react.useRef)(null);
1063
+ const confirmRef = (0, react.useRef)(null);
1064
+ const [pos, setPos] = (0, react.useState)(null);
1065
+ (0, react.useLayoutEffect)(() => {
1066
+ const place = () => {
1067
+ const anchor = anchorRef.current;
1068
+ const pop = popRef.current;
1069
+ if (anchor === null || pop === null) return;
1070
+ const rect = anchor.getBoundingClientRect();
1071
+ const vw = window.innerWidth;
1072
+ const vh = window.innerHeight;
1073
+ const left = Math.min(Math.max(rect.left, POP_MARGIN), Math.max(POP_MARGIN, vw - POP_MARGIN - pop.offsetWidth));
1074
+ setPos({
1075
+ left,
1076
+ bottom: vh - rect.top + POP_GAP
1077
+ });
1078
+ };
1079
+ place();
1080
+ window.addEventListener("resize", place);
1081
+ window.addEventListener("scroll", place, true);
1082
+ return () => {
1083
+ window.removeEventListener("resize", place);
1084
+ window.removeEventListener("scroll", place, true);
1085
+ };
1086
+ }, [anchorRef]);
1087
+ (0, react.useEffect)(() => {
1088
+ const raf = requestAnimationFrame(() => {
1089
+ confirmRef.current?.focus();
1090
+ });
1091
+ return () => {
1092
+ cancelAnimationFrame(raf);
1093
+ };
1094
+ }, []);
1095
+ (0, react.useEffect)(() => {
1096
+ const onPointerDown = (event) => {
1097
+ if (popRef.current?.contains(event.target) === true) return;
1098
+ if (anchorRef.current?.contains(event.target) === true) return;
1099
+ onCancel();
1100
+ };
1101
+ const onKeyDown = (event) => {
1102
+ if (event.key === "Escape") onCancel();
1103
+ };
1104
+ document.addEventListener("pointerdown", onPointerDown, true);
1105
+ document.addEventListener("keydown", onKeyDown);
1106
+ return () => {
1107
+ document.removeEventListener("pointerdown", onPointerDown, true);
1108
+ document.removeEventListener("keydown", onKeyDown);
1109
+ };
1110
+ }, [onCancel, anchorRef]);
1111
+ return (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1112
+ ref: popRef,
1113
+ className: BranchChip_module_default.popCard,
1114
+ style: pos ?? POP_MEASURE,
1115
+ role: "dialog",
1116
+ "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",
1124
+ 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
+ })]
1135
+ }), document.body);
1136
+ }
1137
+ /** 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;
1140
+ const [repo, refresh] = useRepoStatus(cwd);
1141
+ const [menuOpen, setMenuOpen] = (0, react.useState)(false);
1142
+ const [worktreeMode, setWorktreeMode] = (0, react.useState)(false);
1143
+ const [confirm, setConfirm] = (0, react.useState)(null);
1144
+ const [busy, setBusy] = (0, react.useState)(false);
1145
+ const [toast, setToast] = (0, react.useState)(null);
1146
+ const chipRef = (0, react.useRef)(null);
1147
+ const busyRef = (0, react.useRef)(false);
1148
+ (0, react.useEffect)(() => {
1149
+ setWorktreeMode(false);
1150
+ setConfirm(null);
1151
+ setMenuOpen(false);
1152
+ }, [cwd]);
1153
+ (0, react.useEffect)(() => {
1154
+ if (!session.blank) {
1155
+ setWorktreeMode(false);
1156
+ setConfirm((current) => current !== null && current.kind !== "switch" ? null : current);
1157
+ }
1158
+ }, [session.blank]);
1159
+ (0, react.useEffect)(() => {
1160
+ const refreshIfIdle = () => {
1161
+ if (busyRef.current) return;
1162
+ refresh();
1163
+ };
1164
+ const onVisibility = () => {
1165
+ if (document.visibilityState === "visible") refreshIfIdle();
1166
+ };
1167
+ window.addEventListener("focus", refreshIfIdle);
1168
+ document.addEventListener("visibilitychange", onVisibility);
1169
+ return () => {
1170
+ window.removeEventListener("focus", refreshIfIdle);
1171
+ document.removeEventListener("visibilitychange", onVisibility);
1172
+ };
1173
+ }, [refresh]);
1174
+ const showError = (0, react.useCallback)((message) => {
1175
+ setToast({
1176
+ seq: Date.now(),
1177
+ text: t("errorGeneric", { message })
1178
+ });
1179
+ }, [t]);
1180
+ /** Run one guarded confirm action: single-flight, toast on failure, close on success. */
1181
+ const runGuarded = (0, react.useCallback)(async (action) => {
1182
+ if (busyRef.current) return;
1183
+ busyRef.current = true;
1184
+ setBusy(true);
1185
+ const failure = await action();
1186
+ busyRef.current = false;
1187
+ setBusy(false);
1188
+ if (failure !== void 0) {
1189
+ showError(failure);
1190
+ return;
1191
+ }
1192
+ setConfirm(null);
1193
+ setMenuOpen(false);
1194
+ }, [showError]);
1195
+ /** In-place switch flow: POST /switch, then refetch the status. */
1196
+ const doSwitch = (0, react.useCallback)((branch) => runGuarded(async () => {
1197
+ if (cwd === void 0) return "no session directory";
1198
+ const result = await requestSwitch(cwd, branch);
1199
+ if (!result.ok) return result.error;
1200
+ await refresh();
1201
+ }), [
1202
+ cwd,
1203
+ refresh,
1204
+ runGuarded
1205
+ ]);
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 () => {
1209
+ if (cwd === void 0) return "no session directory";
1210
+ const result = cutout ? await requestWorktreeCutout(cwd, branch) : await requestWorktree(cwd, branch);
1211
+ 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
+ }
1217
+ }), [
1218
+ adoptWorktree,
1219
+ cwd,
1220
+ runGuarded
1221
+ ]);
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);
1240
+ }
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",
1248
+ className: BranchChip_module_default.chip,
1249
+ title: facts.currentBranch,
1250
+ onClick: () => {
1251
+ setConfirm(null);
1252
+ const opening = !menuOpen;
1253
+ setMenuOpen(opening);
1254
+ if (opening && !busyRef.current) refresh();
1255
+ },
1256
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconBranchOutline16, { size: 12 }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1257
+ className: BranchChip_module_default.branch,
1258
+ children: displayBranch(facts.currentBranch)
1259
+ })]
1260
+ }), session.blank && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1261
+ className: BranchChip_module_default.divider,
1262
+ "aria-hidden": "true"
1263
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1264
+ type: "button",
1265
+ className: worktreeMode ? BranchChip_module_default.checkOn : BranchChip_module_default.check,
1266
+ onClick: () => {
1267
+ const next = !worktreeMode;
1268
+ setWorktreeMode(next);
1269
+ setMenuOpen(false);
1270
+ if (next) {
1271
+ setConfirm({
1272
+ kind: "worktree-cutout",
1273
+ branch: facts.currentBranch
1274
+ });
1275
+ if (!busyRef.current) refresh();
1276
+ } else setConfirm(null);
1277
+ },
1278
+ title: t("worktreeToggle"),
1279
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1280
+ className: BranchChip_module_default.box,
1281
+ children: worktreeMode ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WorktreeCheck, { size: 10 }) : null
1282
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1283
+ className: BranchChip_module_default.checkLabel,
1284
+ children: t("chipWorktree")
1285
+ })]
1286
+ })] })]
1287
+ }),
1288
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BranchMenu, {
1289
+ open: menuOpen,
1290
+ anchorRef: chipRef,
1291
+ rows,
1292
+ currentBranch: facts.currentBranch,
1293
+ confirm: confirmBundle,
1294
+ onSelect: (branch) => {
1295
+ if (branch === facts.currentBranch) {
1296
+ if (worktreeMode) setConfirm({
1297
+ kind: "worktree-cutout",
1298
+ branch
1299
+ });
1300
+ else setMenuOpen(false);
1301
+ return;
1302
+ }
1303
+ setConfirm({
1304
+ kind: worktreeMode ? "worktree" : "switch",
1305
+ branch
1306
+ });
1307
+ },
1308
+ onClose: () => {
1309
+ setMenuOpen(false);
1310
+ },
1311
+ t
1312
+ }),
1313
+ confirmBundle !== null && !menuOpen && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChipConfirm, {
1314
+ anchorRef: chipRef,
1315
+ ...confirmBundle
1316
+ }),
1317
+ toast !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Toast, {
1318
+ text: toast.text,
1319
+ onDone: () => {
1320
+ setToast(null);
1321
+ }
1322
+ }, toast.seq)
1323
+ ] });
1324
+ }
1325
+ //#endregion
1326
+ //#region src/client/card-form.ts
1327
+ /** The field this card edits. */
1328
+ const ROOT_FIELD = "rootDir";
1329
+ /**
1330
+ * Stages the settings edit over the `git-worktree` scope.
1331
+ *
1332
+ * The form publishes through a snapshot store because the slot component
1333
+ * reads through a snapshot selector while both the scope and the local draft
1334
+ * 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.
1337
+ */
1338
+ var CardForm = class {
1339
+ scope;
1340
+ snapshotValue;
1341
+ listeners = /* @__PURE__ */ new Set();
1342
+ draft;
1343
+ saving = false;
1344
+ failed = false;
1345
+ /**
1346
+ * @param scope - the bound settings scope for the `git-worktree` namespace.
1347
+ */
1348
+ constructor(scope) {
1349
+ this.scope = scope;
1350
+ this.snapshotValue = this.project();
1351
+ scope.subscribe(() => {
1352
+ this.publish();
1353
+ });
1354
+ }
1355
+ /** @returns the store the card's component reads through its bound selector. */
1356
+ bind() {
1357
+ return {
1358
+ getSnapshot: () => this.snapshotValue,
1359
+ subscribe: (listener) => {
1360
+ this.listeners.add(listener);
1361
+ return () => {
1362
+ this.listeners.delete(listener);
1363
+ };
1364
+ },
1365
+ set: (next) => {
1366
+ this.store(next);
1367
+ }
1368
+ };
1369
+ }
1370
+ /** @returns the edit, clear, save, and discard actions bound to this form. */
1371
+ actions() {
1372
+ return {
1373
+ editRoot: (text) => {
1374
+ this.draft = text;
1375
+ this.failed = false;
1376
+ this.publish();
1377
+ },
1378
+ clearRoot: () => {
1379
+ this.draft = "";
1380
+ this.failed = false;
1381
+ this.publish();
1382
+ },
1383
+ save: () => this.save(),
1384
+ discard: () => {
1385
+ if (this.draft === void 0 && !this.failed) return;
1386
+ this.draft = void 0;
1387
+ this.failed = false;
1388
+ this.publish();
1389
+ }
1390
+ };
1391
+ }
1392
+ /**
1393
+ * Write the staged edit, then re-seed from what the Host accepted.
1394
+ *
1395
+ * The Host is the only authority on acceptance — an empty draft clears the
1396
+ * field, anything else stores the trimmed text (so blanking the control and
1397
+ * saving is the same gesture as clearing it). A save that did not land
1398
+ * keeps its draft so the user can correct it instead of retyping.
1399
+ */
1400
+ async save() {
1401
+ if (this.draft === void 0 || this.saving) return;
1402
+ const intended = this.draft.trim();
1403
+ this.saving = true;
1404
+ this.failed = false;
1405
+ this.publish();
1406
+ let landed = true;
1407
+ try {
1408
+ if (intended === "") await this.scope.unset(ROOT_FIELD);
1409
+ else await this.scope.set(ROOT_FIELD, intended);
1410
+ if (intended === "" ? this.storedRoot() : this.storedRootValue() !== intended) landed = false;
1411
+ } catch (_settingsWriteFailure) {
1412
+ landed = false;
1413
+ }
1414
+ if (landed) this.draft = void 0;
1415
+ this.saving = false;
1416
+ this.failed = !landed;
1417
+ this.publish();
1418
+ }
1419
+ /** The raw user layer narrowed to a record; the wire answer is `unknown`. */
1420
+ userLayer() {
1421
+ const user = this.scope.getSnapshot().user;
1422
+ return typeof user === "object" && user !== null ? user : void 0;
1423
+ }
1424
+ /** Whether the user layer carries the root field. */
1425
+ storedRoot() {
1426
+ const user = this.userLayer();
1427
+ return user !== void 0 && Object.hasOwn(user, "rootDir");
1428
+ }
1429
+ /** The raw user-layer value of the root field. */
1430
+ storedRootValue() {
1431
+ return this.userLayer()?.[ROOT_FIELD];
1432
+ }
1433
+ /** The resolved (draft-free) text of the field; '' means inherited. */
1434
+ effectiveRoot() {
1435
+ const value = this.scope.getSnapshot().value?.[ROOT_FIELD];
1436
+ return typeof value === "string" ? value : "";
1437
+ }
1438
+ project() {
1439
+ const snapshot = this.scope.getSnapshot();
1440
+ const draft = this.draft ?? this.effectiveRoot();
1441
+ return {
1442
+ available: snapshot.status === "ready",
1443
+ writable: snapshot.writable,
1444
+ rootDir: draft,
1445
+ overridden: this.draft !== void 0 ? this.draft.trim() !== "" : this.storedRoot(),
1446
+ dirty: this.draft !== void 0 && this.draft !== this.effectiveRoot(),
1447
+ saving: this.saving,
1448
+ failed: this.failed
1449
+ };
1450
+ }
1451
+ /** Replace the snapshot reference and notify, only when the fact moved. */
1452
+ store(next) {
1453
+ if (next === this.snapshotValue) return;
1454
+ this.snapshotValue = next;
1455
+ for (const listener of this.listeners) listener();
1456
+ }
1457
+ publish() {
1458
+ this.store(this.project());
1459
+ }
1460
+ };
1461
+ //#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) {
1466
+ const tag = document.createElement("style");
1467
+ tag.dataset.plugin = "@laoyuehanni/dsh-git-worktree";
1468
+ tag.dataset.pluginCss = tagId;
1469
+ tag.textContent = css;
1470
+ document.head.appendChild(tag);
1471
+ }
1472
+ 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"
1494
+ };
1495
+ //#endregion
1496
+ //#region src/client/GitWorktreeCard.tsx
1497
+ /**
1498
+ * The git-worktree card on the Plugins configuration tab: a collapsible row
1499
+ * whose header names the plugin over a one-line description of what its
1500
+ * settings govern, disclosing the storage-root control when open. The card
1501
+ * owns everything inside it — chrome, controls, and copy — per the keyed-slot
1502
+ * contract; the tab only dispatches it under the `git-worktree` namespace
1503
+ * key.
1504
+ *
1505
+ * Renders nothing while the namespace is unavailable: a deployment that did
1506
+ * not compose the host half shows no trace of the card. A stored root edit
1507
+ * takes effect live (the Host routes read the section source per request);
1508
+ * no data moves — worktrees already created stay where they are, and git
1509
+ * itself still lists and reuses them.
1510
+ *
1511
+ * @module git-worktree/client/GitWorktreeCard
1512
+ */
1513
+ /**
1514
+ * Render the git-worktree settings card.
1515
+ * @param props - locale copy, the card snapshot, and its form actions.
1516
+ * @returns the card, or nothing when the namespace is unavailable.
1517
+ */
1518
+ function GitWorktreeCard(props) {
1519
+ const [open, setOpen] = (0, react.useState)(false);
1520
+ const [picking, setPicking] = (0, react.useState)(false);
1521
+ const { t } = props;
1522
+ const state = props.useGitWorktreeCard((snapshot) => snapshot);
1523
+ if (!state.available) return null;
1524
+ const lockInput = !state.writable;
1525
+ const lockActions = !state.dirty || state.saving;
1526
+ /**
1527
+ * Open the shell's native folder dialog and stage the chosen path — the
1528
+ * same picker the workspace flows use, driven through the injected
1529
+ * workspace service. A dismissal leaves the staged draft exactly as it
1530
+ * was; the text input stays the fallback either way.
1531
+ */
1532
+ const browse = async () => {
1533
+ if (picking || lockInput) return;
1534
+ setPicking(true);
1535
+ try {
1536
+ const picked = await props.pickDirectory();
1537
+ if (picked !== null && picked !== "") props.editRoot(picked);
1538
+ } catch (_pickFailure) {} finally {
1539
+ setPicking(false);
1540
+ }
1541
+ };
1542
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
1543
+ className: open ? `${GitWorktreeCard_module_default.card} ${GitWorktreeCard_module_default.cardOpen}` : GitWorktreeCard_module_default.card,
1544
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1545
+ type: "button",
1546
+ className: GitWorktreeCard_module_default.header,
1547
+ "aria-expanded": open,
1548
+ "aria-label": `${t(open ? "cardCollapse" : "cardExpand")}: ${t("cardTitle")}`,
1549
+ onClick: () => {
1550
+ setOpen(!open);
1551
+ },
1552
+ children: [
1553
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1554
+ className: GitWorktreeCard_module_default.headText,
1555
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1556
+ className: GitWorktreeCard_module_default.name,
1557
+ children: t("cardTitle")
1558
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1559
+ className: GitWorktreeCard_module_default.description,
1560
+ children: t("cardDescription")
1561
+ })]
1562
+ }),
1563
+ state.dirty ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1564
+ className: GitWorktreeCard_module_default.pending,
1565
+ children: t("cardUnsaved")
1566
+ }) : null,
1567
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronDownOutline14, { className: open ? `${GitWorktreeCard_module_default.chevron} ${GitWorktreeCard_module_default.chevronOpen}` : GitWorktreeCard_module_default.chevron })
1568
+ ]
1569
+ }), open ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1570
+ className: GitWorktreeCard_module_default.body,
1571
+ children: [
1572
+ !state.writable ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1573
+ className: GitWorktreeCard_module_default.note,
1574
+ role: "status",
1575
+ children: t("cardReadOnly")
1576
+ }) : null,
1577
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
1578
+ className: GitWorktreeCard_module_default.field,
1579
+ htmlFor: "git-worktree-card-root-dir",
1580
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1581
+ className: GitWorktreeCard_module_default.fieldLabel,
1582
+ children: t("cardRootDirLabel")
1583
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1584
+ className: GitWorktreeCard_module_default.inputRow,
1585
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1586
+ id: "git-worktree-card-root-dir",
1587
+ className: GitWorktreeCard_module_default.input,
1588
+ type: "text",
1589
+ spellCheck: false,
1590
+ value: state.rootDir,
1591
+ disabled: lockInput,
1592
+ onChange: (event) => {
1593
+ props.editRoot(event.target.value);
1594
+ }
1595
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1596
+ type: "button",
1597
+ className: GitWorktreeCard_module_default.browse,
1598
+ disabled: lockInput || picking,
1599
+ onClick: () => {
1600
+ browse();
1601
+ },
1602
+ children: t(picking ? "cardPicking" : "cardBrowse")
1603
+ })]
1604
+ })]
1605
+ }),
1606
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
1607
+ className: GitWorktreeCard_module_default.hint,
1608
+ children: [t("cardRootDirHint"), state.overridden ? ` ${t("cardOverridden")}` : ""]
1609
+ }),
1610
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1611
+ className: GitWorktreeCard_module_default.footer,
1612
+ children: [
1613
+ state.failed ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1614
+ className: GitWorktreeCard_module_default.failed,
1615
+ role: "status",
1616
+ children: t("cardSaveFailed")
1617
+ }) : null,
1618
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1619
+ type: "button",
1620
+ className: GitWorktreeCard_module_default.discard,
1621
+ disabled: lockActions,
1622
+ onClick: props.discard,
1623
+ children: t("cardDiscard")
1624
+ }),
1625
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1626
+ type: "button",
1627
+ className: GitWorktreeCard_module_default.save,
1628
+ disabled: lockActions,
1629
+ onClick: props.save,
1630
+ children: t(state.saving ? "cardSaving" : "cardSave")
1631
+ })
1632
+ ]
1633
+ })
1634
+ ]
1635
+ }) : null]
1636
+ });
1637
+ }
1638
+ //#endregion
1639
+ //#region src/client/locales.ts
1640
+ /** English dictionary — complete by construction. */
1641
+ const en = {
1642
+ chipWorktree: "Worktree",
1643
+ worktreeToggle: "Create an isolated worktree",
1644
+ menuLocalBranches: "Local branches",
1645
+ menuSearchPlaceholder: "Search branches",
1646
+ menuNoMatches: "No matching branches",
1647
+ menuLocate: "Locate current branch",
1648
+ menuExpandAll: "Expand all",
1649
+ menuCollapseAll: "Collapse all",
1650
+ switchAsk: "Switch to {branch}?",
1651
+ switchBusy: "Switching…",
1652
+ worktreeAskNew: "Create a worktree from {branch}?",
1653
+ worktreeAskReuse: "Switch to the {branch} worktree?",
1654
+ worktreeAskCutOut: "Cut a worktree out of the current branch {branch}?",
1655
+ worktreeBusy: "Creating…",
1656
+ actionCancel: "Cancel",
1657
+ actionConfirm: "Confirm",
1658
+ errorGeneric: "Git worktree: {message}",
1659
+ cardTitle: "Git Worktree",
1660
+ cardDescription: "Where isolated worktree folders for new sessions are stored.",
1661
+ cardUnsaved: "Unsaved",
1662
+ cardExpand: "Expand",
1663
+ cardCollapse: "Collapse",
1664
+ cardReadOnly: "The settings document is read-only; edits cannot be saved.",
1665
+ cardRootDirLabel: "Worktree storage folder",
1666
+ cardBrowse: "Browse…",
1667
+ cardPicking: "Choosing…",
1668
+ cardRootDirHint: "Absolute path. Empty uses the default $DSH_HOME/gitworktree (~/.dsh/gitworktree).",
1669
+ cardOverridden: "(custom location)",
1670
+ cardSaveFailed: "The change did not save. Check the path is absolute and try again.",
1671
+ cardDiscard: "Discard",
1672
+ cardSave: "Save",
1673
+ cardSaving: "Saving…"
1674
+ };
1675
+ /** 中文词典。 */
1676
+ const zh = {
1677
+ chipWorktree: "工作树",
1678
+ worktreeToggle: "创建隔离工作树",
1679
+ menuLocalBranches: "本地分支",
1680
+ menuSearchPlaceholder: "搜索分支",
1681
+ menuNoMatches: "没有匹配的分支",
1682
+ menuLocate: "定位当前分支",
1683
+ menuExpandAll: "全部展开",
1684
+ menuCollapseAll: "全部折叠",
1685
+ switchAsk: "是否切到 {branch}?",
1686
+ switchBusy: "切换中…",
1687
+ worktreeAskNew: "是否从 {branch} 新建工作树?",
1688
+ worktreeAskReuse: "是否切到 {branch} 工作树?",
1689
+ worktreeAskCutOut: "是否从当前分支 {branch} 切出工作树?",
1690
+ worktreeBusy: "创建中…",
1691
+ actionCancel: "取消",
1692
+ actionConfirm: "确认",
1693
+ errorGeneric: "Git 工作树:{message}",
1694
+ cardTitle: "Git 工作树",
1695
+ cardDescription: "新会话的隔离工作树文件夹存放位置。",
1696
+ cardUnsaved: "未保存",
1697
+ cardExpand: "展开",
1698
+ cardCollapse: "折叠",
1699
+ cardReadOnly: "设置文档为只读,修改无法保存。",
1700
+ cardRootDirLabel: "工作树存放目录",
1701
+ cardBrowse: "浏览…",
1702
+ cardPicking: "选择中…",
1703
+ cardRootDirHint: "绝对路径。留空使用默认 $DSH_HOME/gitworktree(~/.dsh/gitworktree)。",
1704
+ cardOverridden: "(已自定义位置)",
1705
+ cardSaveFailed: "保存未生效,请检查路径是否为绝对路径后重试。",
1706
+ cardDiscard: "放弃",
1707
+ cardSave: "保存",
1708
+ cardSaving: "保存中…"
1709
+ };
1710
+ //#endregion
1711
+ //#region src/client/index.ts
1712
+ /** Dictionary namespace owned by this plugin. */
1713
+ const NS = "git-worktree";
1714
+ /**
1715
+ * Namespace of the git-worktree settings section. Spelled here rather than
1716
+ * imported: a client package must not depend on a Host package.
1717
+ */
1718
+ 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. */
1721
+ const inject = [
1722
+ "slots",
1723
+ "sessions",
1724
+ "workspaces",
1725
+ "locale",
1726
+ "connection",
1727
+ "remote",
1728
+ "settingsScope"
1729
+ ];
1730
+ function apply(ctx) {
1731
+ ctx.effect(() => ctx.locale.register(NS, {
1732
+ zh,
1733
+ en
1734
+ }), "git-worktree: dictionaries");
1735
+ const chipInjected = () => ({ adoptWorktree: async (path) => {
1736
+ const workspace = await ctx.workspaces.create({ path });
1737
+ ctx.workspaces.startSession(workspace.workspaceId);
1738
+ } });
1739
+ ctx.slots.inject("conversation.input.left", () => ctx.slots.register({
1740
+ name: "conversation.input.left",
1741
+ id: "git-worktree",
1742
+ order: 5,
1743
+ locale: NS,
1744
+ inject: chipInjected
1745
+ }, BranchChipDock));
1746
+ const form = new CardForm(ctx.settingsScope.bind({ namespace: GIT_WORKTREE_NS }));
1747
+ const store = form.bind();
1748
+ ctx.slots.inject("settings.plugin.item", () => ctx.slots.register({
1749
+ name: "settings.plugin.item",
1750
+ key: GIT_WORKTREE_NS,
1751
+ locale: NS,
1752
+ inject: () => ({
1753
+ hooks: { gitWorktreeCard: store },
1754
+ ...form.actions(),
1755
+ pickDirectory: () => ctx.workspaces.pickDirectory()
1756
+ })
1757
+ }, GitWorktreeCard));
1758
+ }
1759
+ //#endregion
1760
+ exports.apply = apply;
1761
+ exports.inject = inject;
1762
+ return module.exports;
1763
+ }
1764
+ });
1765
+
1766
+ //# sourceMappingURL=client.js.map