dsh-worktree-groups 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +168 -2
- package/cordis.patch.yml +17 -0
- package/icon.svg +20 -0
- package/lib/activity.d.ts +78 -0
- package/lib/activity.d.ts.map +1 -0
- package/lib/activity.js +241 -0
- package/lib/activity.js.map +1 -0
- package/lib/client.d.ts +78 -0
- package/lib/client.d.ts.map +1 -0
- package/lib/client.js +4280 -0
- package/lib/git.d.ts +109 -0
- package/lib/git.d.ts.map +1 -0
- package/lib/git.js +317 -0
- package/lib/git.js.map +1 -0
- package/lib/icons.d.ts +148 -0
- package/lib/icons.d.ts.map +1 -0
- package/lib/icons.js +144 -0
- package/lib/icons.js.map +1 -0
- package/lib/index.d.ts +32 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +47 -0
- package/lib/index.js.map +1 -0
- package/lib/ledger.d.ts +97 -0
- package/lib/ledger.d.ts.map +1 -0
- package/lib/ledger.js +276 -0
- package/lib/ledger.js.map +1 -0
- package/lib/live-merge.d.ts +44 -0
- package/lib/live-merge.d.ts.map +1 -0
- package/lib/live-merge.js +227 -0
- package/lib/live-merge.js.map +1 -0
- package/lib/live-state.d.ts +158 -0
- package/lib/live-state.d.ts.map +1 -0
- package/lib/live-state.js +281 -0
- package/lib/live-state.js.map +1 -0
- package/lib/locales.d.ts +71 -0
- package/lib/locales.d.ts.map +1 -0
- package/lib/locales.js +199 -0
- package/lib/locales.js.map +1 -0
- package/lib/projects.d.ts +88 -0
- package/lib/projects.d.ts.map +1 -0
- package/lib/projects.js +418 -0
- package/lib/projects.js.map +1 -0
- package/lib/routes.d.ts +376 -0
- package/lib/routes.d.ts.map +1 -0
- package/lib/routes.js +1875 -0
- package/lib/routes.js.map +1 -0
- package/lib/row-memo.d.ts +34 -0
- package/lib/row-memo.d.ts.map +1 -0
- package/lib/row-memo.js +46 -0
- package/lib/row-memo.js.map +1 -0
- package/lib/sidebar.d.ts +126 -0
- package/lib/sidebar.d.ts.map +1 -0
- package/lib/tree-model.d.ts +1226 -0
- package/lib/tree-model.d.ts.map +1 -0
- package/lib/tree-model.js +2143 -0
- package/lib/tree-model.js.map +1 -0
- package/lib/types.d.ts +98 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +8 -0
- package/lib/types.js.map +1 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +88 -4
package/lib/client.js
ADDED
|
@@ -0,0 +1,4280 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({id:"dsh-worktree-groups",factory:(require)=>{var module={exports:{}};var exports=module.exports;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name2 in all)
|
|
11
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/client.tsx
|
|
32
|
+
var client_exports = {};
|
|
33
|
+
__export(client_exports, {
|
|
34
|
+
apply: () => apply,
|
|
35
|
+
inject: () => inject,
|
|
36
|
+
name: () => name
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(client_exports);
|
|
39
|
+
|
|
40
|
+
// src/sidebar.tsx
|
|
41
|
+
var Primitives = __toESM(require("@deepseek-ai/dsh-client-ui-primitives"), 1);
|
|
42
|
+
var import_react = require("react");
|
|
43
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
44
|
+
|
|
45
|
+
// src/locales.ts
|
|
46
|
+
var zh = {
|
|
47
|
+
"section.workspaces": "\u5DE5\u4F5C\u533A",
|
|
48
|
+
"section.ungrouped": "\u672A\u5206\u7EC4",
|
|
49
|
+
"search.placeholder": "\u641C\u7D22\u4F1A\u8BDD\u2026",
|
|
50
|
+
"search.empty": "\u65E0\u5339\u914D\u7ED3\u679C",
|
|
51
|
+
"session.new": "\u65B0\u4F1A\u8BDD",
|
|
52
|
+
"session.blank": "\u65B0\u4F1A\u8BDD",
|
|
53
|
+
"sessions.expand": "\u5C55\u5F00\u5176\u4F59 {n} \u4E2A\u4F1A\u8BDD",
|
|
54
|
+
/** 2026-11-14 PX1:渐进展开按钮(n = 本次多展开的条数)。 */
|
|
55
|
+
"sessions.expandMore": "\u5C55\u5F00\u66F4\u591A {n} \u4E2A",
|
|
56
|
+
"sessions.collapse": "\u6536\u8D77",
|
|
57
|
+
"history.label": "history-worktree-session",
|
|
58
|
+
"worktree.main": "\u4E3B",
|
|
59
|
+
"worktree.create": "\u65B0\u5EFA worktree\u2026",
|
|
60
|
+
"worktree.remove": "\u79FB\u9664 worktree",
|
|
61
|
+
"worktree.creating": "\u6B63\u5728\u521B\u5EFA\u2026",
|
|
62
|
+
"worktree.removing": "\u6B63\u5728\u79FB\u9664\u2026",
|
|
63
|
+
"worktree.newBranch": "\u65B0\u5EFA\u5206\u652F",
|
|
64
|
+
"worktree.useExisting": "\u590D\u7528\u5DF2\u6709\u5206\u652F",
|
|
65
|
+
"worktree.branchName": "\u5206\u652F\u540D",
|
|
66
|
+
"worktree.baseBranch": "\u8D77\u59CB\u5206\u652F",
|
|
67
|
+
"worktree.path": "\u8DEF\u5F84",
|
|
68
|
+
"worktree.pathHint": "\u9ED8\u8BA4\uFF1A<\u4E3B\u4ED3\u7236\u76EE\u5F55>/<\u4E3B\u4ED3\u540D>-<\u5206\u652F\u540D>",
|
|
69
|
+
"worktree.confirm": "\u521B\u5EFA",
|
|
70
|
+
"worktree.cancel": "\u53D6\u6D88",
|
|
71
|
+
"worktree.removeConfirm": "\u786E\u5B9A\u79FB\u9664 worktree \u201C{name}\u201D\uFF1F",
|
|
72
|
+
"worktree.removeKeepBranch": "\u5206\u652F\u4F1A\u4FDD\u7559\uFF0C\u53EF\u7528 git branch -d \u5220\u9664\u3002",
|
|
73
|
+
"worktree.forceRemove": "\u5F3A\u5236\u5220\u9664\uFF08\u4E22\u5931\u672A\u63D0\u4EA4\u6539\u52A8\uFF09",
|
|
74
|
+
"worktree.dirty": "\u8BE5 worktree \u6709\u672A\u63D0\u4EA4\u6539\u52A8\u3002",
|
|
75
|
+
// D10:`worktree-create` 返回 `ok:true` 但注册工作区失败时的**非阻塞**提示
|
|
76
|
+
// (worktree 确实建成了,只是没有 workspaceId ⇒ 不会自动开新会话)。
|
|
77
|
+
"worktree.workspaceWarning": "worktree \u5DF2\u521B\u5EFA\uFF0C\u4F46\u6CE8\u518C\u4E3A\u5DE5\u4F5C\u533A\u5931\u8D25\uFF0C\u672A\u81EA\u52A8\u65B0\u5EFA\u4F1A\u8BDD\uFF1A{message}",
|
|
78
|
+
"project.add": "\u6DFB\u52A0\u5DE5\u4F5C\u533A\u2026",
|
|
79
|
+
"menu.newSession": "\u65B0\u5EFA\u4F1A\u8BDD",
|
|
80
|
+
"menu.reveal": "\u5728\u6587\u4EF6\u7BA1\u7406\u5668\u4E2D\u6253\u5F00",
|
|
81
|
+
"menu.copyPath": "\u590D\u5236\u8DEF\u5F84",
|
|
82
|
+
"menu.rename": "\u91CD\u547D\u540D",
|
|
83
|
+
"menu.archive": "\u5F52\u6863",
|
|
84
|
+
"menu.fork": "\u6D3E\u751F\u4F1A\u8BDD",
|
|
85
|
+
"menu.removeHistory": "\u79FB\u51FA history",
|
|
86
|
+
"menu.deleteWorkspace": "\u5220\u9664\u5DE5\u4F5C\u533A",
|
|
87
|
+
// D10(2026-09-21 用户决策变更):拖拽排序落地后,必须有一个**切回默认排序**的入口
|
|
88
|
+
// (「拖拽即切手动排序」的承诺是「直到你手动切回最近更新」)。菜单项即可,不做模式切换 UI。
|
|
89
|
+
"menu.resetOrder": "\u6062\u590D\u9ED8\u8BA4\u6392\u5E8F",
|
|
90
|
+
"dialog.rename": "\u91CD\u547D\u540D",
|
|
91
|
+
"dialog.renameWorkspace": "\u91CD\u547D\u540D\u5DE5\u4F5C\u533A",
|
|
92
|
+
"dialog.renameSession": "\u91CD\u547D\u540D\u4F1A\u8BDD",
|
|
93
|
+
"dialog.confirm": "\u786E\u5B9A",
|
|
94
|
+
"dialog.cancel": "\u53D6\u6D88",
|
|
95
|
+
"error.title": "\u4FA7\u680F\u6E32\u67D3\u51FA\u9519",
|
|
96
|
+
"error.retry": "\u91CD\u8BD5",
|
|
97
|
+
"error.load": "\u52A0\u8F7D\u5931\u8D25",
|
|
98
|
+
"state.loading": "\u52A0\u8F7D\u4E2D\u2026",
|
|
99
|
+
// 渲染层(T5)实际使用、原最小集遗漏的 4 条。原由 `sidebar.tsx` 的临时
|
|
100
|
+
// 兜底常量补齐,该常量已随清理彻底删除,这 4 条现为冻结集的正式成员
|
|
101
|
+
// (与 `state.loading` 并存,语义不同:本条专指树数据首拉)。
|
|
102
|
+
"worktree.menu": "\u66F4\u591A\u64CD\u4F5C",
|
|
103
|
+
"a11y.subagents": "{n} \u4E2A\u5B50\u4EE3\u7406\u8FD0\u884C\u4E2D",
|
|
104
|
+
// 2026-10-20 运行中任务高亮:容器行 lead 图标的 `title`(key 唯一,见 INTERFACES §2.1)。
|
|
105
|
+
"a11y.runningTask": "\u6709\u4EFB\u52A1\u6B63\u5728\u8FD0\u884C",
|
|
106
|
+
"state.loadingTree": "\u6B63\u5728\u52A0\u8F7D\u5DE5\u4F5C\u533A\u2026",
|
|
107
|
+
"worktree.createTitle": "\u5728 {name} \u4E0B\u65B0\u5EFA worktree",
|
|
108
|
+
// 2026-10-21 新增:底部「最近」分区、归档工作空间与设置页恢复管理词条(WSR1/WSR2/WSR6)。
|
|
109
|
+
"section.recent": "\u6700\u8FD1",
|
|
110
|
+
"menu.archiveWorkspace": "\u5F52\u6863\u5DE5\u4F5C\u7A7A\u95F4",
|
|
111
|
+
"settings.archivedWorkspaces.title": "\u5DF2\u5F52\u6863\u7684\u5DE5\u4F5C\u7A7A\u95F4",
|
|
112
|
+
"settings.archivedWorkspaces.description": "\u5F52\u6863\u540E\u7684\u5DE5\u4F5C\u7A7A\u95F4\u53CA\u5176\u4F1A\u8BDD\u4E0D\u5728\u4FA7\u680F\u663E\u793A\uFF0C\u53EF\u5728\u6B64\u653E\u51FA\u6062\u590D\uFF0C\u6216\u91CD\u65B0\u6DFB\u52A0\u76F8\u540C\u76EE\u5F55\u81EA\u52A8\u653E\u51FA",
|
|
113
|
+
"settings.archivedWorkspaces.empty": "\u6682\u65E0\u5DF2\u5F52\u6863\u7684\u5DE5\u4F5C\u7A7A\u95F4",
|
|
114
|
+
"settings.archivedWorkspaces.restore": "\u653E\u51FA"
|
|
115
|
+
};
|
|
116
|
+
function format(template, vars) {
|
|
117
|
+
if (vars === void 0) return template;
|
|
118
|
+
return template.replace(
|
|
119
|
+
/\{([A-Za-z0-9_]+)\}/g,
|
|
120
|
+
(match, name2) => Object.prototype.hasOwnProperty.call(vars, name2) ? String(vars[name2]) : match
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
function createT(dict = zh) {
|
|
124
|
+
return (key, vars) => {
|
|
125
|
+
const template = Object.prototype.hasOwnProperty.call(dict, key) ? dict[key] : key;
|
|
126
|
+
if (template === void 0) return key;
|
|
127
|
+
return format(template, vars);
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
var seatCache = /* @__PURE__ */ new WeakMap();
|
|
131
|
+
function createSeatT(seat, dict = zh) {
|
|
132
|
+
let perDict = seatCache.get(seat);
|
|
133
|
+
if (perDict === void 0) {
|
|
134
|
+
perDict = /* @__PURE__ */ new WeakMap();
|
|
135
|
+
seatCache.set(seat, perDict);
|
|
136
|
+
}
|
|
137
|
+
const cached = perDict.get(dict);
|
|
138
|
+
if (cached !== void 0) return cached;
|
|
139
|
+
const t = (key, vars) => {
|
|
140
|
+
let resolved;
|
|
141
|
+
try {
|
|
142
|
+
resolved = seat(key, vars);
|
|
143
|
+
} catch {
|
|
144
|
+
resolved = void 0;
|
|
145
|
+
}
|
|
146
|
+
if (typeof resolved === "string" && resolved !== key) return resolved;
|
|
147
|
+
const template = Object.prototype.hasOwnProperty.call(dict, key) ? dict[key] : void 0;
|
|
148
|
+
if (template === void 0) return key;
|
|
149
|
+
return format(template, vars);
|
|
150
|
+
};
|
|
151
|
+
perDict.set(dict, t);
|
|
152
|
+
return t;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// src/icons.ts
|
|
156
|
+
var ICON_SPECS = {
|
|
157
|
+
chevronDown: { candidates: ["IconChevronDownOutlineRegular", "IconChevronDownOutline14"], size: 14 },
|
|
158
|
+
chevronRight: { candidates: ["IconChevronRightOutlineRegular", "IconChevronRightOutline14"], size: 14 },
|
|
159
|
+
clock: { candidates: ["IconClockOutlineRegular", "IconClockOutline16"], size: 16 },
|
|
160
|
+
folderOpen: { candidates: ["IconFolderOpenOutlineRegular", "IconFolderOpenOutline16"], size: 16 },
|
|
161
|
+
folderClose: { candidates: ["IconFolderCloseRegular", "IconFolderClose16"], size: 16 },
|
|
162
|
+
branch: { candidates: ["IconBranchOutlineRegular", "IconBranchOutline16"], size: 16 },
|
|
163
|
+
panelLeft: { candidates: ["IconPanelLeftOutlineRegular", "IconPanelLeftOutline16"], size: 16 },
|
|
164
|
+
plus: { candidates: ["IconPlusOutlineRegular", "IconPlusOutline16"], size: 16 },
|
|
165
|
+
ellipsis: { candidates: ["IconEllipsisOutlineRegular", "IconEllipsisOutline16"], size: 16 },
|
|
166
|
+
projectAdd: { candidates: ["IconProjectAddOutlineRegular", "IconProjectAddOutline16"], size: 16 },
|
|
167
|
+
refresh: { candidates: ["IconRefreshOutlineRegular", "IconRefreshOutline16"], size: 14 },
|
|
168
|
+
copy: { candidates: ["IconCopyOutlineRegular", "IconCopyOutline16"], size: 16 },
|
|
169
|
+
edit: { candidates: ["IconEditOutlineRegular", "IconEditOutline16"], size: 16 },
|
|
170
|
+
trash: { candidates: ["IconTrashOutlineRegular", "IconTrashOutline16"], size: 16 },
|
|
171
|
+
archive: { candidates: ["IconArchiveOutlineRegular", "IconArchiveOutline20"], size: 20 },
|
|
172
|
+
newChat: { candidates: ["IconNewChatOutlineRegular", "IconNewChatOutline16"], size: 16 }
|
|
173
|
+
};
|
|
174
|
+
var ICON_NAMES = Object.keys(ICON_SPECS);
|
|
175
|
+
function NullIcon() {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
function iconAt(face, name2) {
|
|
179
|
+
if (face === null || face === void 0) return void 0;
|
|
180
|
+
const value = face[name2];
|
|
181
|
+
return typeof value === "function" ? value : void 0;
|
|
182
|
+
}
|
|
183
|
+
var resolvedCache = /* @__PURE__ */ new WeakMap();
|
|
184
|
+
var fallbackCache = /* @__PURE__ */ new Map();
|
|
185
|
+
function resolveIcon(face, name2) {
|
|
186
|
+
const spec = ICON_SPECS[name2];
|
|
187
|
+
const hit = spec.candidates.find((candidate) => iconAt(face, candidate) !== void 0);
|
|
188
|
+
if (hit === void 0) {
|
|
189
|
+
const cached2 = fallbackCache.get(name2);
|
|
190
|
+
if (cached2 !== void 0) return cached2;
|
|
191
|
+
const fallback = { Component: NullIcon, candidate: void 0 };
|
|
192
|
+
fallbackCache.set(name2, fallback);
|
|
193
|
+
return fallback;
|
|
194
|
+
}
|
|
195
|
+
const key = face;
|
|
196
|
+
let perFace = resolvedCache.get(key);
|
|
197
|
+
if (perFace === void 0) {
|
|
198
|
+
perFace = /* @__PURE__ */ new Map();
|
|
199
|
+
resolvedCache.set(key, perFace);
|
|
200
|
+
}
|
|
201
|
+
const cached = perFace.get(name2);
|
|
202
|
+
if (cached !== void 0 && cached.candidate === hit) return cached;
|
|
203
|
+
const resolved = {
|
|
204
|
+
Component: iconAt(face, hit),
|
|
205
|
+
candidate: hit
|
|
206
|
+
};
|
|
207
|
+
perFace.set(name2, resolved);
|
|
208
|
+
return resolved;
|
|
209
|
+
}
|
|
210
|
+
function iconSize(name2) {
|
|
211
|
+
return ICON_SPECS[name2].size;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// src/live-state.ts
|
|
215
|
+
var VISIBLE_PENDING_KINDS = ["approval", "plan-review", "question"];
|
|
216
|
+
function visiblePendingKind(kind) {
|
|
217
|
+
return typeof kind === "string" && VISIBLE_PENDING_KINDS.includes(kind) ? kind : void 0;
|
|
218
|
+
}
|
|
219
|
+
function normalizeSessionKey(id) {
|
|
220
|
+
return id.startsWith("session-") ? id.slice("session-".length) : id;
|
|
221
|
+
}
|
|
222
|
+
function entryOf(face, sessionId) {
|
|
223
|
+
if (face === null || face === void 0) return void 0;
|
|
224
|
+
const map = face;
|
|
225
|
+
if (typeof map.get !== "function") return void 0;
|
|
226
|
+
try {
|
|
227
|
+
return map.get(sessionId);
|
|
228
|
+
} catch {
|
|
229
|
+
return void 0;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
function sessionStatusOf(status, sessionId) {
|
|
233
|
+
if (typeof sessionId !== "string" || sessionId === "") return void 0;
|
|
234
|
+
const direct = entryOf(status, sessionId);
|
|
235
|
+
if (direct !== void 0) return direct;
|
|
236
|
+
const iterable = status;
|
|
237
|
+
if (iterable === null || iterable === void 0 || typeof iterable.entries !== "function") return void 0;
|
|
238
|
+
const key = normalizeSessionKey(sessionId);
|
|
239
|
+
if (key === "") return void 0;
|
|
240
|
+
try {
|
|
241
|
+
for (const [id, value] of iterable.entries()) {
|
|
242
|
+
if (typeof id === "string" && normalizeSessionKey(id) === key) return value;
|
|
243
|
+
}
|
|
244
|
+
} catch {
|
|
245
|
+
return void 0;
|
|
246
|
+
}
|
|
247
|
+
return void 0;
|
|
248
|
+
}
|
|
249
|
+
function pendingKindFromLegacy(pending, sessionId) {
|
|
250
|
+
const direct = visiblePendingKind(entryOf(pending, sessionId)?.kind);
|
|
251
|
+
if (direct !== void 0) return direct;
|
|
252
|
+
const iterable = pending;
|
|
253
|
+
if (iterable === null || iterable === void 0 || typeof iterable.entries !== "function") return void 0;
|
|
254
|
+
const key = normalizeSessionKey(sessionId);
|
|
255
|
+
if (key === "") return void 0;
|
|
256
|
+
try {
|
|
257
|
+
for (const [id, interaction] of iterable.entries()) {
|
|
258
|
+
if (typeof id !== "string" || normalizeSessionKey(id) !== key) continue;
|
|
259
|
+
const kind = visiblePendingKind(interaction?.kind);
|
|
260
|
+
if (kind !== void 0) return kind;
|
|
261
|
+
}
|
|
262
|
+
} catch {
|
|
263
|
+
return void 0;
|
|
264
|
+
}
|
|
265
|
+
return void 0;
|
|
266
|
+
}
|
|
267
|
+
function completedFromLegacy(sessions, sessionId) {
|
|
268
|
+
const byId = sessions?.byId;
|
|
269
|
+
if (byId === null || byId === void 0 || typeof byId !== "object") return false;
|
|
270
|
+
if (byId[sessionId]?.completed === true) return true;
|
|
271
|
+
const key = normalizeSessionKey(sessionId);
|
|
272
|
+
if (key === "") return false;
|
|
273
|
+
for (const [id, entry] of Object.entries(byId)) {
|
|
274
|
+
if (entry?.completed === true && normalizeSessionKey(id) === key) return true;
|
|
275
|
+
}
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
function runningSignature(status) {
|
|
279
|
+
const iterable = status;
|
|
280
|
+
if (iterable === null || iterable === void 0 || typeof iterable.entries !== "function") return "";
|
|
281
|
+
try {
|
|
282
|
+
const keys = /* @__PURE__ */ new Set();
|
|
283
|
+
for (const [id, entry] of iterable.entries()) {
|
|
284
|
+
if (typeof id !== "string" || id === "") continue;
|
|
285
|
+
if (entry === null || typeof entry !== "object") continue;
|
|
286
|
+
if (entry.running !== true) continue;
|
|
287
|
+
const key = normalizeSessionKey(id);
|
|
288
|
+
if (key === "") continue;
|
|
289
|
+
keys.add(key);
|
|
290
|
+
}
|
|
291
|
+
return [...keys].sort().join(",");
|
|
292
|
+
} catch {
|
|
293
|
+
return "";
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
function liveStateOf(input, sessionId) {
|
|
297
|
+
const status = sessionStatusOf(input.status, sessionId);
|
|
298
|
+
const pendingKind = status === void 0 ? pendingKindFromLegacy(input.pending, sessionId) : visiblePendingKind(status.pendingInteraction?.kind);
|
|
299
|
+
const completionUnread = typeof status?.completionUnread === "boolean" ? status.completionUnread === true : completedFromLegacy(input.sessions, sessionId);
|
|
300
|
+
return { pendingKind, completionUnread };
|
|
301
|
+
}
|
|
302
|
+
function currentSessionIdOf(input) {
|
|
303
|
+
if (input === null || input === void 0 || typeof input !== "object") return void 0;
|
|
304
|
+
try {
|
|
305
|
+
const panelInfo = input.panelInfo;
|
|
306
|
+
if (panelInfo !== null && panelInfo !== void 0 && typeof panelInfo === "object") {
|
|
307
|
+
const activePanelId = panelInfo.activePanelId;
|
|
308
|
+
if (activePanelId !== null && activePanelId !== void 0) return void 0;
|
|
309
|
+
}
|
|
310
|
+
const sessions = input.sessions;
|
|
311
|
+
if (sessions !== null && sessions !== void 0 && typeof sessions === "object") {
|
|
312
|
+
const byId = sessions.byId;
|
|
313
|
+
if (byId !== null && byId !== void 0 && typeof byId === "object" && !Array.isArray(byId)) {
|
|
314
|
+
for (const [key, rawEntry] of Object.entries(byId)) {
|
|
315
|
+
if (rawEntry === null || rawEntry === void 0 || typeof rawEntry !== "object") continue;
|
|
316
|
+
const entry = rawEntry;
|
|
317
|
+
const mainView = entry.retainedBy?.mainView;
|
|
318
|
+
if (typeof mainView === "number" && Number.isFinite(mainView) && mainView > 0) {
|
|
319
|
+
if (typeof entry.id === "string" && entry.id !== "") return entry.id;
|
|
320
|
+
if (typeof entry.sessionId === "string" && entry.sessionId !== "") return entry.sessionId;
|
|
321
|
+
if (key !== "") return key;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
const legacyCurrent = sessions.current;
|
|
326
|
+
if (typeof legacyCurrent === "string" && legacyCurrent !== "") return legacyCurrent;
|
|
327
|
+
}
|
|
328
|
+
if (typeof input.optimisticSessionId === "string" && input.optimisticSessionId !== "") {
|
|
329
|
+
return input.optimisticSessionId;
|
|
330
|
+
}
|
|
331
|
+
return void 0;
|
|
332
|
+
} catch {
|
|
333
|
+
return void 0;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// src/tree-model.ts
|
|
338
|
+
var COLLAPSED_SESSION_LIMIT = 5;
|
|
339
|
+
function visibleSessionLimit(level) {
|
|
340
|
+
const l = Number.isFinite(level) && level > 0 ? Math.floor(level) : 0;
|
|
341
|
+
return COLLAPSED_SESSION_LIMIT + COLLAPSED_SESSION_LIMIT * l * (l + 1) / 2;
|
|
342
|
+
}
|
|
343
|
+
function nextExpandCount(level, remaining) {
|
|
344
|
+
const l = Number.isFinite(level) && level > 0 ? Math.floor(level) : 0;
|
|
345
|
+
const left = Number.isFinite(remaining) && remaining > 0 ? Math.floor(remaining) : 0;
|
|
346
|
+
return Math.min(COLLAPSED_SESSION_LIMIT * (l + 1), left);
|
|
347
|
+
}
|
|
348
|
+
function expandLevelOf(levels, key) {
|
|
349
|
+
const value = levels?.[key];
|
|
350
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.floor(value) : 0;
|
|
351
|
+
}
|
|
352
|
+
function containerKeysUnder(projects, rowKey) {
|
|
353
|
+
if (!rowKey.startsWith("p:")) return [rowKey];
|
|
354
|
+
const projectKey = rowKey.slice("p:".length);
|
|
355
|
+
const keys = /* @__PURE__ */ new Set([rowKey, `h:${projectKey}`]);
|
|
356
|
+
const project = projects.find((candidate) => candidate.key === projectKey);
|
|
357
|
+
for (const node of project?.worktrees ?? []) keys.add(`w:${node.path}`);
|
|
358
|
+
return [...keys];
|
|
359
|
+
}
|
|
360
|
+
var RECENT_KEY = "__recent__";
|
|
361
|
+
var UNGROUPED_KEY = "__ungrouped__";
|
|
362
|
+
var SESSION_ID_PREFIX = "session-";
|
|
363
|
+
function applyManualOrder(items, order, keyOf, pinnedKeys) {
|
|
364
|
+
const copy = [...items];
|
|
365
|
+
const pinned = pinnedKeys === void 0 ? [] : pinnedKeys;
|
|
366
|
+
if (pinned.length === 0 && (order === void 0 || order.length === 0)) return copy;
|
|
367
|
+
const indexOf = /* @__PURE__ */ new Map();
|
|
368
|
+
for (let i = 0; i < copy.length; i += 1) {
|
|
369
|
+
const key = keyOf(copy[i]);
|
|
370
|
+
if (!indexOf.has(key)) indexOf.set(key, i);
|
|
371
|
+
}
|
|
372
|
+
const ordered = [];
|
|
373
|
+
const taken = /* @__PURE__ */ new Set();
|
|
374
|
+
for (const key of pinned) {
|
|
375
|
+
const index = indexOf.get(key);
|
|
376
|
+
if (index === void 0 || taken.has(index)) continue;
|
|
377
|
+
taken.add(index);
|
|
378
|
+
ordered.push(copy[index]);
|
|
379
|
+
}
|
|
380
|
+
for (const key of order ?? []) {
|
|
381
|
+
const index = indexOf.get(key);
|
|
382
|
+
if (index === void 0 || taken.has(index)) continue;
|
|
383
|
+
taken.add(index);
|
|
384
|
+
ordered.push(copy[index]);
|
|
385
|
+
}
|
|
386
|
+
for (let i = 0; i < copy.length; i += 1) {
|
|
387
|
+
if (!taken.has(i)) ordered.push(copy[i]);
|
|
388
|
+
}
|
|
389
|
+
return ordered;
|
|
390
|
+
}
|
|
391
|
+
function worktreeOrderOf(order, projectKey) {
|
|
392
|
+
if (order === void 0 || order.manual !== true) return void 0;
|
|
393
|
+
return order.worktrees?.[projectKey];
|
|
394
|
+
}
|
|
395
|
+
function sessionOrderOf(order, containerKey) {
|
|
396
|
+
if (order === void 0 || order.manual !== true) return void 0;
|
|
397
|
+
return order.sessions?.[containerKey];
|
|
398
|
+
}
|
|
399
|
+
function sortTopZone(sessions) {
|
|
400
|
+
return sortedByRecency(sessions);
|
|
401
|
+
}
|
|
402
|
+
function isTopZoneRunningSession(session, topZone) {
|
|
403
|
+
if (session.running === true) return true;
|
|
404
|
+
if (topZone === void 0 || topZone === null || typeof topZone !== "object") return false;
|
|
405
|
+
if (typeof session.sessionId !== "string" || session.sessionId === "") return false;
|
|
406
|
+
const ids = topZone.runningSessionIds;
|
|
407
|
+
if (!Array.isArray(ids)) return false;
|
|
408
|
+
const key = normalizeSessionId(session.sessionId);
|
|
409
|
+
for (const id of ids) {
|
|
410
|
+
if (typeof id === "string" && normalizeSessionId(id) === key) return true;
|
|
411
|
+
}
|
|
412
|
+
return false;
|
|
413
|
+
}
|
|
414
|
+
function isCurrentBlankSession(session, currentSessionId) {
|
|
415
|
+
if (session.blank !== true) return false;
|
|
416
|
+
if (session.isCurrent === true) return true;
|
|
417
|
+
if (typeof currentSessionId !== "string" || currentSessionId === "") return false;
|
|
418
|
+
return isCurrentSession(session.sessionId, currentSessionId);
|
|
419
|
+
}
|
|
420
|
+
function isSessionDragLocked(session, topZone) {
|
|
421
|
+
if (isCurrentBlankSession(session)) return true;
|
|
422
|
+
return isTopZoneRunningSession(session, topZone);
|
|
423
|
+
}
|
|
424
|
+
function topZoneSessionKeys(sessions, currentSessionId, containerKey, topZone) {
|
|
425
|
+
void currentSessionId;
|
|
426
|
+
void containerKey;
|
|
427
|
+
const keys = [];
|
|
428
|
+
const seen = /* @__PURE__ */ new Set();
|
|
429
|
+
const push = (key) => {
|
|
430
|
+
if (key === void 0 || seen.has(key)) return;
|
|
431
|
+
seen.add(key);
|
|
432
|
+
keys.push(key);
|
|
433
|
+
};
|
|
434
|
+
if (topZone === void 0) return keys.length === 0 ? void 0 : keys;
|
|
435
|
+
const zone = topZone;
|
|
436
|
+
if (zone === null || typeof zone !== "object") return keys.length === 0 ? void 0 : keys;
|
|
437
|
+
const done = /* @__PURE__ */ new Set();
|
|
438
|
+
for (const id of Array.isArray(zone.writtenNewSessionIds) ? zone.writtenNewSessionIds : []) {
|
|
439
|
+
if (typeof id === "string") done.add(normalizeSessionId(id));
|
|
440
|
+
}
|
|
441
|
+
const fresh = /* @__PURE__ */ new Set();
|
|
442
|
+
for (const id of Array.isArray(zone.newSessionIds) ? zone.newSessionIds : []) {
|
|
443
|
+
if (typeof id === "string") fresh.add(normalizeSessionId(id));
|
|
444
|
+
}
|
|
445
|
+
const rest = [];
|
|
446
|
+
for (const session of sessions) {
|
|
447
|
+
const key = normalizeSessionId(session.sessionId);
|
|
448
|
+
const isRunning = isTopZoneRunningSession(session, zone);
|
|
449
|
+
const isFresh = fresh.has(key) && !done.has(key);
|
|
450
|
+
if (!isRunning && !isFresh) continue;
|
|
451
|
+
rest.push(session);
|
|
452
|
+
}
|
|
453
|
+
for (const session of sortTopZone(rest)) push(session.sessionId);
|
|
454
|
+
return keys.length === 0 ? void 0 : keys;
|
|
455
|
+
}
|
|
456
|
+
function initialTopZoneState() {
|
|
457
|
+
return {
|
|
458
|
+
baselined: false,
|
|
459
|
+
startedAtMs: 0,
|
|
460
|
+
knownSessionIds: [],
|
|
461
|
+
blankOf: {},
|
|
462
|
+
runningOf: {},
|
|
463
|
+
newSessionIds: [],
|
|
464
|
+
writtenNewSessionIds: []
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
function observeTopZone(state, observations, nowMs) {
|
|
468
|
+
const eligible = [];
|
|
469
|
+
const seen = /* @__PURE__ */ new Set();
|
|
470
|
+
for (const observation of observations) {
|
|
471
|
+
if (typeof observation.sessionId !== "string" || observation.sessionId === "") continue;
|
|
472
|
+
const id = normalizeSessionId(observation.sessionId);
|
|
473
|
+
seen.add(id);
|
|
474
|
+
if (observation.subagent || observation.archived) continue;
|
|
475
|
+
eligible.push(observation);
|
|
476
|
+
}
|
|
477
|
+
if (!state.baselined) {
|
|
478
|
+
const known2 = new Set(seen);
|
|
479
|
+
const blankOf2 = {};
|
|
480
|
+
const runningOf2 = {};
|
|
481
|
+
for (const observation of eligible) {
|
|
482
|
+
const id = normalizeSessionId(observation.sessionId);
|
|
483
|
+
blankOf2[id] = observation.blank === true;
|
|
484
|
+
runningOf2[id] = observation.running === true;
|
|
485
|
+
}
|
|
486
|
+
return {
|
|
487
|
+
baselined: true,
|
|
488
|
+
startedAtMs: nowMs,
|
|
489
|
+
knownSessionIds: [...known2],
|
|
490
|
+
blankOf: blankOf2,
|
|
491
|
+
runningOf: runningOf2,
|
|
492
|
+
newSessionIds: [],
|
|
493
|
+
writtenNewSessionIds: state.writtenNewSessionIds
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
const known = new Set(state.knownSessionIds);
|
|
497
|
+
const blankOf = { ...state.blankOf };
|
|
498
|
+
const runningOf = { ...state.runningOf };
|
|
499
|
+
const fresh = new Set(state.newSessionIds);
|
|
500
|
+
const detectedNew = [];
|
|
501
|
+
for (const observation of eligible) {
|
|
502
|
+
const id = normalizeSessionId(observation.sessionId);
|
|
503
|
+
const previousBlank = blankOf[id];
|
|
504
|
+
const blankedToVisible = previousBlank === true && observation.blank !== true;
|
|
505
|
+
const firstSeenAfterStart = !known.has(id) && Number.isFinite(observation.updatedAt) && observation.updatedAt >= state.startedAtMs;
|
|
506
|
+
if (!blankedToVisible && !firstSeenAfterStart) continue;
|
|
507
|
+
if (!fresh.has(id)) detectedNew.push(id);
|
|
508
|
+
}
|
|
509
|
+
for (const observation of eligible) {
|
|
510
|
+
const id = normalizeSessionId(observation.sessionId);
|
|
511
|
+
blankOf[id] = observation.blank === true;
|
|
512
|
+
runningOf[id] = observation.running === true;
|
|
513
|
+
known.add(id);
|
|
514
|
+
}
|
|
515
|
+
for (const id of detectedNew) fresh.add(id);
|
|
516
|
+
for (const id of seen) known.add(id);
|
|
517
|
+
const nextFresh = [...fresh];
|
|
518
|
+
const sameIds = (a, b) => a.length === b.length && a.every((id, index) => id === b[index]);
|
|
519
|
+
const sameRecord = (a, b) => {
|
|
520
|
+
const aKeys = Object.keys(a);
|
|
521
|
+
if (aKeys.length !== Object.keys(b).length) return false;
|
|
522
|
+
return aKeys.every((key) => b[key] === a[key]);
|
|
523
|
+
};
|
|
524
|
+
const unchanged = detectedNew.length === 0 && sameIds(nextFresh, state.newSessionIds) && sameIds([...known], state.knownSessionIds) && sameRecord(blankOf, state.blankOf) && sameRecord(runningOf, state.runningOf);
|
|
525
|
+
if (unchanged) return state;
|
|
526
|
+
return {
|
|
527
|
+
baselined: true,
|
|
528
|
+
startedAtMs: state.startedAtMs,
|
|
529
|
+
knownSessionIds: [...known],
|
|
530
|
+
blankOf,
|
|
531
|
+
runningOf,
|
|
532
|
+
newSessionIds: nextFresh,
|
|
533
|
+
writtenNewSessionIds: state.writtenNewSessionIds
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
function placementOfSession(sessions, sessionId) {
|
|
537
|
+
if (typeof sessionId !== "string" || sessionId === "") return void 0;
|
|
538
|
+
const target = normalizeSessionId(sessionId);
|
|
539
|
+
for (const [containerKey, list] of sessions) {
|
|
540
|
+
for (const id of list) {
|
|
541
|
+
if (normalizeSessionId(id) === target) return { containerKey, sessionId: id };
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
return void 0;
|
|
545
|
+
}
|
|
546
|
+
function insertSessionAtFront(order, containerKey, sessionId, fullOrder) {
|
|
547
|
+
if (order.manual !== true) return void 0;
|
|
548
|
+
if (typeof containerKey !== "string" || containerKey === "") return void 0;
|
|
549
|
+
if (typeof sessionId !== "string" || sessionId === "") return void 0;
|
|
550
|
+
const stored = order.sessions?.[containerKey];
|
|
551
|
+
const base = stored !== void 0 && stored.length > 0 ? stored : fullOrder ?? stored ?? [];
|
|
552
|
+
const target = normalizeSessionId(sessionId);
|
|
553
|
+
const writtenId = base.find((id) => typeof id === "string" && normalizeSessionId(id) === target) ?? fullOrder?.find((id) => typeof id === "string" && normalizeSessionId(id) === target) ?? sessionId;
|
|
554
|
+
const rest = base.filter((id) => typeof id === "string" && normalizeSessionId(id) !== target);
|
|
555
|
+
const next = [writtenId, ...rest];
|
|
556
|
+
const current = order.sessions?.[containerKey];
|
|
557
|
+
if (current !== void 0 && current.length === next.length && current.every((id, index) => id === next[index])) {
|
|
558
|
+
return void 0;
|
|
559
|
+
}
|
|
560
|
+
return { ...order, manual: true, sessions: { ...order.sessions ?? {}, [containerKey]: next } };
|
|
561
|
+
}
|
|
562
|
+
function planNewSessionInserts(order, sessions, newSessionIds, alreadyWritten) {
|
|
563
|
+
if (order.manual !== true) return { order, consumed: [], changed: false };
|
|
564
|
+
const done = /* @__PURE__ */ new Set();
|
|
565
|
+
for (const id of alreadyWritten) {
|
|
566
|
+
if (typeof id === "string" && id !== "") done.add(normalizeSessionId(id));
|
|
567
|
+
}
|
|
568
|
+
const consumed = [];
|
|
569
|
+
let next = order;
|
|
570
|
+
let changed = false;
|
|
571
|
+
for (const raw of newSessionIds) {
|
|
572
|
+
if (typeof raw !== "string" || raw === "") continue;
|
|
573
|
+
const id = normalizeSessionId(raw);
|
|
574
|
+
if (done.has(id)) continue;
|
|
575
|
+
const placement = placementOfSession(sessions, id);
|
|
576
|
+
if (placement === void 0) continue;
|
|
577
|
+
const inserted = insertSessionAtFront(
|
|
578
|
+
next,
|
|
579
|
+
placement.containerKey,
|
|
580
|
+
placement.sessionId,
|
|
581
|
+
sessions.get(placement.containerKey)
|
|
582
|
+
);
|
|
583
|
+
consumed.push(id);
|
|
584
|
+
if (inserted === void 0) continue;
|
|
585
|
+
next = inserted;
|
|
586
|
+
changed = true;
|
|
587
|
+
}
|
|
588
|
+
return { order: next, consumed, changed };
|
|
589
|
+
}
|
|
590
|
+
function markNewSessionsWritten(state, sessionIds) {
|
|
591
|
+
const seen = new Set(state.writtenNewSessionIds);
|
|
592
|
+
const next = [...state.writtenNewSessionIds];
|
|
593
|
+
let changed = false;
|
|
594
|
+
for (const id of sessionIds) {
|
|
595
|
+
if (typeof id !== "string" || id === "") continue;
|
|
596
|
+
const key = normalizeSessionId(id);
|
|
597
|
+
if (seen.has(key)) continue;
|
|
598
|
+
seen.add(key);
|
|
599
|
+
next.push(key);
|
|
600
|
+
changed = true;
|
|
601
|
+
}
|
|
602
|
+
return changed ? { ...state, writtenNewSessionIds: next } : state;
|
|
603
|
+
}
|
|
604
|
+
function pendingNewSessionIdsOf(state) {
|
|
605
|
+
const done = new Set(state.writtenNewSessionIds);
|
|
606
|
+
return state.newSessionIds.filter((id) => typeof id === "string" && id !== "" && !done.has(normalizeSessionId(id)));
|
|
607
|
+
}
|
|
608
|
+
function normalizeSessionId(id) {
|
|
609
|
+
return id.startsWith(SESSION_ID_PREFIX) ? id.slice(SESSION_ID_PREFIX.length) : id;
|
|
610
|
+
}
|
|
611
|
+
function isBlank(row) {
|
|
612
|
+
return typeof row === "object" && row !== null && row.blank === true;
|
|
613
|
+
}
|
|
614
|
+
function isSubagentSession(session) {
|
|
615
|
+
return session.origin === "subagent";
|
|
616
|
+
}
|
|
617
|
+
function discoverChildEdges(sessions) {
|
|
618
|
+
const inSet = /* @__PURE__ */ new Set();
|
|
619
|
+
for (const session of sessions) inSet.add(normalizeSessionId(session.sessionId));
|
|
620
|
+
const edges = /* @__PURE__ */ new Map();
|
|
621
|
+
const edgeKeys = /* @__PURE__ */ new Set();
|
|
622
|
+
const attributed = /* @__PURE__ */ new Set();
|
|
623
|
+
let frontier = sessions;
|
|
624
|
+
while (frontier.length > 0) {
|
|
625
|
+
const nested = nestSubagents(frontier);
|
|
626
|
+
const next = [];
|
|
627
|
+
const roots = [];
|
|
628
|
+
let added = false;
|
|
629
|
+
let head;
|
|
630
|
+
for (const entry of nested) {
|
|
631
|
+
if (entry.depth === 0) {
|
|
632
|
+
head = entry.session;
|
|
633
|
+
roots.push(entry.session);
|
|
634
|
+
continue;
|
|
635
|
+
}
|
|
636
|
+
const parent = head;
|
|
637
|
+
if (parent === void 0) continue;
|
|
638
|
+
const parentKey = normalizeSessionId(parent.sessionId);
|
|
639
|
+
const childKey = normalizeSessionId(entry.session.sessionId);
|
|
640
|
+
const edgeKey = `${parentKey}\0${childKey}`;
|
|
641
|
+
if (!edgeKeys.has(edgeKey)) {
|
|
642
|
+
edgeKeys.add(edgeKey);
|
|
643
|
+
attributed.add(childKey);
|
|
644
|
+
added = true;
|
|
645
|
+
const bucket = edges.get(parentKey);
|
|
646
|
+
if (bucket === void 0) edges.set(parentKey, [entry.session]);
|
|
647
|
+
else bucket.push(entry.session);
|
|
648
|
+
}
|
|
649
|
+
next.push(entry.session);
|
|
650
|
+
}
|
|
651
|
+
for (const root of roots) {
|
|
652
|
+
const parentId = root.parentSessionId;
|
|
653
|
+
if (parentId === void 0) continue;
|
|
654
|
+
const rootKey = normalizeSessionId(root.sessionId);
|
|
655
|
+
if (attributed.has(rootKey)) continue;
|
|
656
|
+
if (!inSet.has(normalizeSessionId(parentId))) continue;
|
|
657
|
+
next.push(root);
|
|
658
|
+
}
|
|
659
|
+
if (!added) break;
|
|
660
|
+
frontier = next;
|
|
661
|
+
}
|
|
662
|
+
for (const session of sessions) {
|
|
663
|
+
const childKey = normalizeSessionId(session.sessionId);
|
|
664
|
+
const parentId = session.parentSessionId;
|
|
665
|
+
if (parentId === void 0) continue;
|
|
666
|
+
const parentKey = normalizeSessionId(parentId);
|
|
667
|
+
if (!inSet.has(parentKey)) continue;
|
|
668
|
+
const edgeKey = `${parentKey}\0${childKey}`;
|
|
669
|
+
if (edgeKeys.has(edgeKey)) continue;
|
|
670
|
+
edgeKeys.add(edgeKey);
|
|
671
|
+
const bucket = edges.get(parentKey);
|
|
672
|
+
if (bucket === void 0) edges.set(parentKey, [session]);
|
|
673
|
+
else bucket.push(session);
|
|
674
|
+
}
|
|
675
|
+
return edges;
|
|
676
|
+
}
|
|
677
|
+
function indexRunningSubagentDescendants(sessions) {
|
|
678
|
+
const edges = discoverChildEdges(sessions);
|
|
679
|
+
const parentOf = /* @__PURE__ */ new Map();
|
|
680
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
681
|
+
const counts = /* @__PURE__ */ new Map();
|
|
682
|
+
for (const session of sessions) {
|
|
683
|
+
const key = normalizeSessionId(session.sessionId);
|
|
684
|
+
if (!byKey.has(key)) byKey.set(key, session);
|
|
685
|
+
if (!counts.has(key)) counts.set(key, 0);
|
|
686
|
+
}
|
|
687
|
+
for (const [parentKey, children] of edges) {
|
|
688
|
+
for (const child of children) {
|
|
689
|
+
const childKey = normalizeSessionId(child.sessionId);
|
|
690
|
+
if (!parentOf.has(childKey)) parentOf.set(childKey, parentKey);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
for (const session of byKey.values()) {
|
|
694
|
+
if (!isSubagentSession(session)) continue;
|
|
695
|
+
const seen = /* @__PURE__ */ new Set();
|
|
696
|
+
let currentKey = normalizeSessionId(session.sessionId);
|
|
697
|
+
let current = byKey.get(currentKey);
|
|
698
|
+
while (current !== void 0 && isSubagentSession(current) && !seen.has(currentKey)) {
|
|
699
|
+
const parentKey = parentOf.get(currentKey);
|
|
700
|
+
if (parentKey === void 0) break;
|
|
701
|
+
seen.add(currentKey);
|
|
702
|
+
if (session.running === true) counts.set(parentKey, (counts.get(parentKey) ?? 0) + 1);
|
|
703
|
+
currentKey = parentKey;
|
|
704
|
+
current = byKey.get(parentKey);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
return counts;
|
|
708
|
+
}
|
|
709
|
+
function subagentCountOf(counts, sessionId) {
|
|
710
|
+
return counts.get(normalizeSessionId(sessionId)) ?? 0;
|
|
711
|
+
}
|
|
712
|
+
function allSessionsOf(source) {
|
|
713
|
+
const all = [];
|
|
714
|
+
for (const project of source.projects) {
|
|
715
|
+
for (const node of project.worktrees) all.push(...node.sessions);
|
|
716
|
+
all.push(...project.history);
|
|
717
|
+
all.push(...project.flatSessions);
|
|
718
|
+
}
|
|
719
|
+
all.push(...source.ungrouped);
|
|
720
|
+
return all;
|
|
721
|
+
}
|
|
722
|
+
function observationsOf(source) {
|
|
723
|
+
const archived = new Set(source.archivedSessionIds);
|
|
724
|
+
const counts = indexRunningSubagentDescendants(allSessionsOf(source));
|
|
725
|
+
const observations = [];
|
|
726
|
+
const seen = /* @__PURE__ */ new Set();
|
|
727
|
+
for (const session of allSessionsOf(source)) {
|
|
728
|
+
if (typeof session.sessionId !== "string" || session.sessionId === "") continue;
|
|
729
|
+
const key = normalizeSessionId(session.sessionId);
|
|
730
|
+
if (seen.has(key)) continue;
|
|
731
|
+
seen.add(key);
|
|
732
|
+
observations.push({
|
|
733
|
+
sessionId: session.sessionId,
|
|
734
|
+
updatedAt: Number.isFinite(session.updatedAt) ? session.updatedAt : 0,
|
|
735
|
+
blank: isBlank(session),
|
|
736
|
+
// 与 `toSessionRow` 的 `running` 同式 ⇒ 「只有 subagent 在跑」也算运行中(D3a)。
|
|
737
|
+
running: session.running === true || subagentCountOf(counts, session.sessionId) > 0,
|
|
738
|
+
subagent: isSubagentSession(session),
|
|
739
|
+
archived: archived.has(session.sessionId)
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
for (const raw of source.archivedSessionIds) {
|
|
743
|
+
if (typeof raw !== "string" || raw === "") continue;
|
|
744
|
+
const key = normalizeSessionId(raw);
|
|
745
|
+
if (seen.has(key)) continue;
|
|
746
|
+
seen.add(key);
|
|
747
|
+
observations.push({
|
|
748
|
+
sessionId: raw,
|
|
749
|
+
updatedAt: 0,
|
|
750
|
+
blank: false,
|
|
751
|
+
running: false,
|
|
752
|
+
subagent: false,
|
|
753
|
+
archived: true
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
return observations;
|
|
757
|
+
}
|
|
758
|
+
function topZoneInputOf(state) {
|
|
759
|
+
const runningSessionIds = [];
|
|
760
|
+
for (const [id, running] of Object.entries(state.runningOf)) {
|
|
761
|
+
if (running === true) runningSessionIds.push(id);
|
|
762
|
+
}
|
|
763
|
+
return {
|
|
764
|
+
runningSessionIds,
|
|
765
|
+
newSessionIds: state.newSessionIds,
|
|
766
|
+
// T9 缺陷 1:把落表台账一并投影进渲染期输入 —— 已落表的新会话不再被渲染期提升,
|
|
767
|
+
// 否则用户把它拖到分组内其他位置后会被搬回原位(真人 GUI 复验的「弹回」缺陷)。
|
|
768
|
+
writtenNewSessionIds: state.writtenNewSessionIds
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
function isCollapsed(keys, key) {
|
|
772
|
+
return keys !== void 0 && keys[key] === true;
|
|
773
|
+
}
|
|
774
|
+
function byRecency(a, b) {
|
|
775
|
+
if (a.updatedAt !== b.updatedAt) return b.updatedAt - a.updatedAt;
|
|
776
|
+
if (a.sessionId === b.sessionId) return 0;
|
|
777
|
+
return a.sessionId < b.sessionId ? -1 : 1;
|
|
778
|
+
}
|
|
779
|
+
function sortedByRecency(sessions) {
|
|
780
|
+
return [...sessions].sort(byRecency);
|
|
781
|
+
}
|
|
782
|
+
function recentActivityOf(session) {
|
|
783
|
+
const updatedAt = Number.isFinite(session.updatedAt) ? session.updatedAt : 0;
|
|
784
|
+
const lastActivityAt = typeof session.lastActivityAt === "number" && Number.isFinite(session.lastActivityAt) ? session.lastActivityAt : 0;
|
|
785
|
+
return Math.max(updatedAt, lastActivityAt);
|
|
786
|
+
}
|
|
787
|
+
function byRecentActivity(a, b) {
|
|
788
|
+
const delta = recentActivityOf(b) - recentActivityOf(a);
|
|
789
|
+
if (delta !== 0) return delta;
|
|
790
|
+
if (a.sessionId === b.sessionId) return 0;
|
|
791
|
+
return a.sessionId < b.sessionId ? -1 : 1;
|
|
792
|
+
}
|
|
793
|
+
function basenameOf(path) {
|
|
794
|
+
if (path === void 0) return "";
|
|
795
|
+
const trimmed = path.replace(/[/\\]+$/, "");
|
|
796
|
+
const separator = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"));
|
|
797
|
+
return trimmed.slice(separator + 1);
|
|
798
|
+
}
|
|
799
|
+
function sessionLabelOf(session, titleOf, t) {
|
|
800
|
+
if (isBlank(session)) return t("session.new");
|
|
801
|
+
const raw = titleOf(session);
|
|
802
|
+
return typeof raw === "string" && raw.trim() !== "" ? raw : t("session.new");
|
|
803
|
+
}
|
|
804
|
+
function truncateSessions(sessions, limit) {
|
|
805
|
+
const quota = Number.isFinite(limit) ? Math.max(0, Math.floor(limit)) : 0;
|
|
806
|
+
const visible = [];
|
|
807
|
+
let ordinary = 0;
|
|
808
|
+
for (let i = 0; i < sessions.length; i += 1) {
|
|
809
|
+
const session = sessions[i];
|
|
810
|
+
if (isBlank(session)) {
|
|
811
|
+
visible.push(session);
|
|
812
|
+
continue;
|
|
813
|
+
}
|
|
814
|
+
if (ordinary < quota) {
|
|
815
|
+
visible.push(session);
|
|
816
|
+
ordinary += 1;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
return { visible, hiddenCount: sessions.length - visible.length };
|
|
820
|
+
}
|
|
821
|
+
function nestSubagents(sessions) {
|
|
822
|
+
const byNormalizedId = /* @__PURE__ */ new Map();
|
|
823
|
+
for (const session of sessions) {
|
|
824
|
+
const key = normalizeSessionId(session.sessionId);
|
|
825
|
+
if (!byNormalizedId.has(key)) byNormalizedId.set(key, session);
|
|
826
|
+
}
|
|
827
|
+
const childMemo = /* @__PURE__ */ new Map();
|
|
828
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
829
|
+
const isChild = (session) => {
|
|
830
|
+
const cached = childMemo.get(session);
|
|
831
|
+
if (cached !== void 0) return cached;
|
|
832
|
+
if (visiting.has(session)) return false;
|
|
833
|
+
const parentId = session.parentSessionId;
|
|
834
|
+
if (parentId === void 0) return false;
|
|
835
|
+
const parent = byNormalizedId.get(normalizeSessionId(parentId));
|
|
836
|
+
if (parent === void 0 || parent === session) return false;
|
|
837
|
+
visiting.add(session);
|
|
838
|
+
const parentIsChild = isChild(parent);
|
|
839
|
+
visiting.delete(session);
|
|
840
|
+
const result = !parentIsChild;
|
|
841
|
+
childMemo.set(session, result);
|
|
842
|
+
return result;
|
|
843
|
+
};
|
|
844
|
+
const childrenOf = /* @__PURE__ */ new Map();
|
|
845
|
+
const roots = [];
|
|
846
|
+
for (const session of sessions) {
|
|
847
|
+
if (isChild(session)) {
|
|
848
|
+
const parent = byNormalizedId.get(normalizeSessionId(session.parentSessionId ?? ""));
|
|
849
|
+
if (parent === void 0) {
|
|
850
|
+
roots.push(session);
|
|
851
|
+
continue;
|
|
852
|
+
}
|
|
853
|
+
const siblings = childrenOf.get(parent);
|
|
854
|
+
if (siblings === void 0) childrenOf.set(parent, [session]);
|
|
855
|
+
else siblings.push(session);
|
|
856
|
+
} else {
|
|
857
|
+
roots.push(session);
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
const flattened = [];
|
|
861
|
+
for (const root of roots) {
|
|
862
|
+
flattened.push({ session: root, depth: 0 });
|
|
863
|
+
const children = childrenOf.get(root);
|
|
864
|
+
if (children === void 0) continue;
|
|
865
|
+
for (const child of children) flattened.push({ session: child, depth: 1 });
|
|
866
|
+
}
|
|
867
|
+
return flattened;
|
|
868
|
+
}
|
|
869
|
+
function containersOfProject(project, context) {
|
|
870
|
+
const projectKey = `p:${project.key}`;
|
|
871
|
+
const hasWorktreeRows = project.isGit === true;
|
|
872
|
+
const worktrees = [];
|
|
873
|
+
if (hasWorktreeRows) {
|
|
874
|
+
for (const node of project.worktrees) {
|
|
875
|
+
worktrees.push({
|
|
876
|
+
node,
|
|
877
|
+
spec: {
|
|
878
|
+
key: `w:${node.path}`,
|
|
879
|
+
kind: "worktree",
|
|
880
|
+
depth: 2,
|
|
881
|
+
sessions: node.sessions,
|
|
882
|
+
project,
|
|
883
|
+
worktree: node
|
|
884
|
+
}
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
const result = {
|
|
889
|
+
project,
|
|
890
|
+
projectKey,
|
|
891
|
+
hasWorktreeRows,
|
|
892
|
+
worktrees
|
|
893
|
+
};
|
|
894
|
+
if (!hasWorktreeRows) {
|
|
895
|
+
result.flat = {
|
|
896
|
+
key: projectKey,
|
|
897
|
+
kind: "project",
|
|
898
|
+
depth: 1,
|
|
899
|
+
sessions: project.flatSessions,
|
|
900
|
+
project
|
|
901
|
+
};
|
|
902
|
+
}
|
|
903
|
+
if (hasVisibleMembers(project.history, context)) {
|
|
904
|
+
result.history = {
|
|
905
|
+
key: `h:${project.key}`,
|
|
906
|
+
kind: "history",
|
|
907
|
+
depth: 2,
|
|
908
|
+
sessions: project.history,
|
|
909
|
+
project
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
return result;
|
|
913
|
+
}
|
|
914
|
+
function ungroupedContainer(input) {
|
|
915
|
+
return {
|
|
916
|
+
key: `p:${UNGROUPED_KEY}`,
|
|
917
|
+
kind: "project",
|
|
918
|
+
depth: 1,
|
|
919
|
+
sessions: input.ungrouped
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
function isCurrentSession(sessionId, currentSessionId) {
|
|
923
|
+
if (typeof sessionId !== "string" || sessionId === "") return false;
|
|
924
|
+
if (typeof currentSessionId !== "string" || currentSessionId === "") return false;
|
|
925
|
+
const a = normalizeSessionId(sessionId);
|
|
926
|
+
const b = normalizeSessionId(currentSessionId);
|
|
927
|
+
return a !== "" && a === b;
|
|
928
|
+
}
|
|
929
|
+
function isVisibleMember(session, context) {
|
|
930
|
+
return !isSubagentSession(session) && !context.archived.has(session.sessionId) && (!isBlank(session) || isCurrentSession(session.sessionId, context.currentSessionId));
|
|
931
|
+
}
|
|
932
|
+
function visibleMembers(spec, context) {
|
|
933
|
+
return spec.sessions.filter((session) => isVisibleMember(session, context));
|
|
934
|
+
}
|
|
935
|
+
function hasVisibleMembers(sessions, context) {
|
|
936
|
+
return sessions.some((session) => isVisibleMember(session, context));
|
|
937
|
+
}
|
|
938
|
+
function toSessionRow(session, depth, subagentCount, spec, context) {
|
|
939
|
+
const keyPrefix = spec.kind === "recent" ? "rs:" : "s:";
|
|
940
|
+
const base = {
|
|
941
|
+
kind: "session",
|
|
942
|
+
key: `${keyPrefix}${session.sessionId}`,
|
|
943
|
+
sessionId: session.sessionId,
|
|
944
|
+
label: sessionLabelOf(session, context.titleOf, context.t),
|
|
945
|
+
depth,
|
|
946
|
+
updatedAt: session.updatedAt,
|
|
947
|
+
// 需求 A(2026-09-21):主 agent 空闲、但有**运行中的子代理后代**时,父行状态点同样
|
|
948
|
+
// 是「运行中」—— 对齐原生 `sessionStatuses`(`dsh-client-ui-workspace/lib/client.js`
|
|
949
|
+
// 的 `if (subagents !== void 0) return [subagents]`:`runningSubagentCount > 0` ⇒
|
|
950
|
+
// 主状态点就是 ongoing)。原实现只读会话自己的 summary ⇒ 此场景退化成灰色 idle。
|
|
951
|
+
//
|
|
952
|
+
// `subagentCount` 就是原生 `runningSubagentCount`(所有层级的**运行中**子代理后代数,
|
|
953
|
+
// 见 {@link indexRunningSubagentDescendants}),所以这里不需要任何新数据源。
|
|
954
|
+
// 放在本函数(而不是各调用点)⇒ 树(`emitContainer`)与搜索(`buildSearchRows`)
|
|
955
|
+
// 两条路径自动同源,不可能「树里改了、搜索里忘了」。
|
|
956
|
+
running: session.running === true || subagentCount > 0,
|
|
957
|
+
completed: session.completed === true,
|
|
958
|
+
blank: isBlank(session),
|
|
959
|
+
subagentCount,
|
|
960
|
+
isCurrent: isCurrentSession(session.sessionId, context.currentSessionId),
|
|
961
|
+
parentKey: spec.key,
|
|
962
|
+
parentKind: spec.kind
|
|
963
|
+
};
|
|
964
|
+
return session.pendingInteraction === void 0 ? base : { ...base, pendingInteraction: session.pendingInteraction };
|
|
965
|
+
}
|
|
966
|
+
function truncateByLevel(heads, key, context, parentKind = "project", depth = 1) {
|
|
967
|
+
if (heads.length <= COLLAPSED_SESSION_LIMIT) return { selected: heads, hiddenCount: 0 };
|
|
968
|
+
const legacyAll = context.expandedAllKeys?.[key] === true;
|
|
969
|
+
const level = expandLevelOf(context.expandLevels, key);
|
|
970
|
+
const truncated = legacyAll ? { visible: heads, hiddenCount: 0 } : truncateSessions(heads, visibleSessionLimit(level));
|
|
971
|
+
const canCollapse = legacyAll || level > 0;
|
|
972
|
+
if (truncated.hiddenCount === 0 && !canCollapse) return { selected: truncated.visible, hiddenCount: 0 };
|
|
973
|
+
return {
|
|
974
|
+
selected: truncated.visible,
|
|
975
|
+
hiddenCount: truncated.hiddenCount,
|
|
976
|
+
more: {
|
|
977
|
+
kind: "more",
|
|
978
|
+
key: `m:${key}`,
|
|
979
|
+
parentKey: key,
|
|
980
|
+
parentKind,
|
|
981
|
+
hiddenCount: truncated.hiddenCount,
|
|
982
|
+
nextCount: nextExpandCount(level, truncated.hiddenCount),
|
|
983
|
+
canCollapse,
|
|
984
|
+
depth
|
|
985
|
+
}
|
|
986
|
+
};
|
|
987
|
+
}
|
|
988
|
+
function emitContainer(spec, context) {
|
|
989
|
+
const visible = visibleMembers(spec, context);
|
|
990
|
+
const placeholder = visible.find((session) => isCurrentBlankSession(session, context.currentSessionId));
|
|
991
|
+
const pinnedKeys = [
|
|
992
|
+
...placeholder === void 0 ? [] : [placeholder.sessionId],
|
|
993
|
+
...topZoneSessionKeys(visible, context.currentSessionId, spec.key, context.topZone) ?? []
|
|
994
|
+
];
|
|
995
|
+
const heads = applyManualOrder(
|
|
996
|
+
sortedByRecency(visible),
|
|
997
|
+
sessionOrderOf(context.manualOrder, spec.key),
|
|
998
|
+
(session) => session.sessionId,
|
|
999
|
+
pinnedKeys
|
|
1000
|
+
);
|
|
1001
|
+
const truncation = truncateByLevel(heads, spec.key, context, spec.kind, spec.depth);
|
|
1002
|
+
const selected = truncation.selected;
|
|
1003
|
+
const hiddenCount = truncation.hiddenCount;
|
|
1004
|
+
const rows = selected.map(
|
|
1005
|
+
(session) => toSessionRow(
|
|
1006
|
+
session,
|
|
1007
|
+
spec.depth,
|
|
1008
|
+
subagentCountOf(context.subagentRunningCounts, session.sessionId),
|
|
1009
|
+
spec,
|
|
1010
|
+
context
|
|
1011
|
+
)
|
|
1012
|
+
);
|
|
1013
|
+
if (truncation.more !== void 0) rows.push(truncation.more);
|
|
1014
|
+
return {
|
|
1015
|
+
rows,
|
|
1016
|
+
sessionCount: heads.length,
|
|
1017
|
+
runningCount: heads.filter((session) => session.running === true).length,
|
|
1018
|
+
pendingCount: heads.filter((session) => session.pendingInteraction !== void 0).length,
|
|
1019
|
+
// 2026-10-20 运行中任务高亮(RT1):**截断前**的 `heads`,聚合口径与
|
|
1020
|
+
// `toSessionRow` 的 `running` **逐字同源**(同一索引、同一 helper)。
|
|
1021
|
+
// 只有子代理在跑时 `runningCount` 仍为 0,但这里为 true —— 有意为之,见
|
|
1022
|
+
// `RenderRow` 的 JSDoc 与 `docs/INTERFACES.md` §2.2.1。
|
|
1023
|
+
hasRunningTasks: heads.some(
|
|
1024
|
+
(session) => session.running === true || subagentCountOf(context.subagentRunningCounts, session.sessionId) > 0
|
|
1025
|
+
),
|
|
1026
|
+
hiddenCount
|
|
1027
|
+
};
|
|
1028
|
+
}
|
|
1029
|
+
function worktreeLabels(node, t) {
|
|
1030
|
+
const base = basenameOf(node.path);
|
|
1031
|
+
const label = node.branch !== void 0 && node.branch !== "" ? node.branch : base;
|
|
1032
|
+
return label === base ? { label } : { label, sublabel: base };
|
|
1033
|
+
}
|
|
1034
|
+
function workspaceIdFromProjectKey(key) {
|
|
1035
|
+
return key.startsWith("ws:") ? key.slice("ws:".length) : void 0;
|
|
1036
|
+
}
|
|
1037
|
+
function projectIdentity(project) {
|
|
1038
|
+
const identity2 = {};
|
|
1039
|
+
const workspaceId = workspaceIdFromProjectKey(project.key);
|
|
1040
|
+
if (workspaceId !== void 0) identity2.workspaceId = workspaceId;
|
|
1041
|
+
if (project.isGit !== true) {
|
|
1042
|
+
const path = project.mainPath ?? project.flatSessions[0]?.cwd;
|
|
1043
|
+
if (path !== void 0) identity2.path = path;
|
|
1044
|
+
}
|
|
1045
|
+
return identity2;
|
|
1046
|
+
}
|
|
1047
|
+
function activeProjectsOf(input) {
|
|
1048
|
+
const keys = input.archivedProjectKeys;
|
|
1049
|
+
if (!Array.isArray(keys) || keys.length === 0) return input.projects;
|
|
1050
|
+
const archived = /* @__PURE__ */ new Set();
|
|
1051
|
+
for (const key of keys) {
|
|
1052
|
+
if (typeof key === "string" && key !== "") {
|
|
1053
|
+
archived.add(key);
|
|
1054
|
+
if (key.startsWith("p:")) archived.add(key.slice(2));
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
if (archived.size === 0) return input.projects;
|
|
1058
|
+
return input.projects.filter((project) => !archived.has(project.key));
|
|
1059
|
+
}
|
|
1060
|
+
function collectSearchCandidates(input, query, context) {
|
|
1061
|
+
const specs = [];
|
|
1062
|
+
for (const project of activeProjectsOf(input)) {
|
|
1063
|
+
const containers = containersOfProject(project, context);
|
|
1064
|
+
for (const entry of containers.worktrees) specs.push(entry.spec);
|
|
1065
|
+
if (containers.flat !== void 0) specs.push(containers.flat);
|
|
1066
|
+
if (containers.history !== void 0) specs.push(containers.history);
|
|
1067
|
+
}
|
|
1068
|
+
if (hasVisibleMembers(input.ungrouped, context)) specs.push(ungroupedContainer(input));
|
|
1069
|
+
const candidates = [];
|
|
1070
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1071
|
+
for (const spec of specs) {
|
|
1072
|
+
const members = visibleMembers(spec, context);
|
|
1073
|
+
const projectName = spec.project?.title ?? "";
|
|
1074
|
+
const worktreeHaystacks = spec.worktree === void 0 ? [] : [spec.worktree.branch ?? "", basenameOf(spec.worktree.path), spec.worktree.title ?? ""];
|
|
1075
|
+
for (const session of members) {
|
|
1076
|
+
if (seen.has(session.sessionId)) continue;
|
|
1077
|
+
const haystacks = [
|
|
1078
|
+
sessionLabelOf(session, input.titleOf, input.t),
|
|
1079
|
+
projectName,
|
|
1080
|
+
basenameOf(session.cwd),
|
|
1081
|
+
...worktreeHaystacks
|
|
1082
|
+
];
|
|
1083
|
+
const hit = haystacks.some((text) => text.toLowerCase().includes(query));
|
|
1084
|
+
if (!hit) continue;
|
|
1085
|
+
seen.add(session.sessionId);
|
|
1086
|
+
candidates.push({
|
|
1087
|
+
session,
|
|
1088
|
+
spec,
|
|
1089
|
+
subagentCount: subagentCountOf(context.subagentRunningCounts, session.sessionId)
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
return candidates;
|
|
1094
|
+
}
|
|
1095
|
+
function buildSearchRows(input, context, query) {
|
|
1096
|
+
const candidates = collectSearchCandidates(input, query, context);
|
|
1097
|
+
candidates.sort((a, b) => byRecency(a.session, b.session));
|
|
1098
|
+
return candidates.map(
|
|
1099
|
+
(candidate) => toSessionRow(candidate.session, 0, candidate.subagentCount, candidate.spec, context)
|
|
1100
|
+
);
|
|
1101
|
+
}
|
|
1102
|
+
function effectiveOrder(input) {
|
|
1103
|
+
const context = {
|
|
1104
|
+
archived: new Set(input.archivedSessionIds),
|
|
1105
|
+
collapsedKeys: input.collapsedKeys,
|
|
1106
|
+
expandedAllKeys: input.expandedAllKeys,
|
|
1107
|
+
expandLevels: input.expandLevels,
|
|
1108
|
+
currentSessionId: input.currentSessionId,
|
|
1109
|
+
titleOf: input.titleOf,
|
|
1110
|
+
t: input.t,
|
|
1111
|
+
subagentRunningCounts: /* @__PURE__ */ new Map(),
|
|
1112
|
+
manualOrder: input.manualOrder,
|
|
1113
|
+
// ⚠️ T5/T11:`effectiveOrder` **刻意不传 `topZone`** —— 与「不把运行时状态写进持久
|
|
1114
|
+
// 顺序」同一不变式,且这里连 `context.topZone` 都置 `undefined`,从结构上杜绝
|
|
1115
|
+
// 「运行时顶部区混进持久顺序」。
|
|
1116
|
+
topZone: void 0
|
|
1117
|
+
};
|
|
1118
|
+
const order = (members, containerKey) => (
|
|
1119
|
+
// ⚠️ T11:这里**刻意不传**任何置顶 key —— 本函数的产物是首次拖拽时固化进
|
|
1120
|
+
// `localStorage` 的顺序,运行时顶部区绝不能进持久化(见函数 JSDoc 的第三处差异)。
|
|
1121
|
+
applyManualOrder(
|
|
1122
|
+
sortedByRecency(visibleMembers({ key: containerKey, kind: "worktree", depth: 0, sessions: members }, context)),
|
|
1123
|
+
sessionOrderOf(input.manualOrder, containerKey),
|
|
1124
|
+
(session) => session.sessionId
|
|
1125
|
+
).map((session) => session.sessionId)
|
|
1126
|
+
);
|
|
1127
|
+
const activeProjects = activeProjectsOf(input);
|
|
1128
|
+
const manualProjects = input.manualOrder?.manual === true ? input.manualOrder.projects : void 0;
|
|
1129
|
+
const projects = applyManualOrder(activeProjects, manualProjects, (project) => project.key).map(
|
|
1130
|
+
(project) => project.key
|
|
1131
|
+
);
|
|
1132
|
+
const worktrees = /* @__PURE__ */ new Map();
|
|
1133
|
+
const sessions = /* @__PURE__ */ new Map();
|
|
1134
|
+
for (const project of activeProjects) {
|
|
1135
|
+
const containers = containersOfProject(project, context);
|
|
1136
|
+
const paths = applyManualOrder(
|
|
1137
|
+
containers.worktrees,
|
|
1138
|
+
worktreeOrderOf(input.manualOrder, project.key),
|
|
1139
|
+
(entry) => entry.node.path
|
|
1140
|
+
).map((entry) => entry.node.path);
|
|
1141
|
+
if (paths.length > 0) worktrees.set(project.key, paths);
|
|
1142
|
+
for (const entry of containers.worktrees) {
|
|
1143
|
+
sessions.set(entry.spec.key, order(entry.spec.sessions, entry.spec.key));
|
|
1144
|
+
}
|
|
1145
|
+
if (containers.flat !== void 0) {
|
|
1146
|
+
sessions.set(containers.flat.key, order(containers.flat.sessions, containers.flat.key));
|
|
1147
|
+
}
|
|
1148
|
+
if (containers.history !== void 0) {
|
|
1149
|
+
sessions.set(containers.history.key, order(containers.history.sessions, containers.history.key));
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
if (hasVisibleMembers(input.ungrouped, context)) {
|
|
1153
|
+
const spec = ungroupedContainer(input);
|
|
1154
|
+
sessions.set(spec.key, order(spec.sessions, spec.key));
|
|
1155
|
+
}
|
|
1156
|
+
return { projects, worktrees, sessions };
|
|
1157
|
+
}
|
|
1158
|
+
function reorderKeys(keys, draggedId, overId, half) {
|
|
1159
|
+
if (draggedId === overId) return null;
|
|
1160
|
+
const sourceIndex = keys.indexOf(draggedId);
|
|
1161
|
+
if (sourceIndex === -1) return null;
|
|
1162
|
+
const withoutSource = keys.filter((key) => key !== draggedId);
|
|
1163
|
+
const overIndex = withoutSource.indexOf(overId);
|
|
1164
|
+
if (overIndex === -1) return null;
|
|
1165
|
+
const insertAt = half === "before" ? overIndex : overIndex + 1;
|
|
1166
|
+
if (insertAt === sourceIndex) return null;
|
|
1167
|
+
const next = [...withoutSource];
|
|
1168
|
+
next.splice(insertAt, 0, draggedId);
|
|
1169
|
+
return next;
|
|
1170
|
+
}
|
|
1171
|
+
function reconcileManualOrder(order, defaults) {
|
|
1172
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1173
|
+
const out = [];
|
|
1174
|
+
for (const raw of order ?? []) {
|
|
1175
|
+
if (typeof raw !== "string" || raw === "" || seen.has(raw)) continue;
|
|
1176
|
+
seen.add(raw);
|
|
1177
|
+
out.push(raw);
|
|
1178
|
+
}
|
|
1179
|
+
for (const key of defaults) {
|
|
1180
|
+
if (typeof key !== "string" || key === "" || seen.has(key)) continue;
|
|
1181
|
+
seen.add(key);
|
|
1182
|
+
out.push(key);
|
|
1183
|
+
}
|
|
1184
|
+
return out;
|
|
1185
|
+
}
|
|
1186
|
+
function reorderManualScope(order, defaults, draggedId, overId, half) {
|
|
1187
|
+
return reorderKeys(reconcileManualOrder(order, defaults), draggedId, overId, half);
|
|
1188
|
+
}
|
|
1189
|
+
function buildRows(input) {
|
|
1190
|
+
const archived = new Set(input.archivedSessionIds);
|
|
1191
|
+
const context = {
|
|
1192
|
+
archived,
|
|
1193
|
+
collapsedKeys: input.collapsedKeys,
|
|
1194
|
+
expandedAllKeys: input.expandedAllKeys,
|
|
1195
|
+
expandLevels: input.expandLevels,
|
|
1196
|
+
currentSessionId: input.currentSessionId,
|
|
1197
|
+
titleOf: input.titleOf,
|
|
1198
|
+
t: input.t,
|
|
1199
|
+
// 索引建立在**全部**输入会话上(含归档与 blank),与原生的 `list.byId` 同口径 ——
|
|
1200
|
+
// 子代理被隐藏后,父行仍要如实显示「有几个子代理在跑」,不因父/子归档状态而漏计。
|
|
1201
|
+
subagentRunningCounts: indexRunningSubagentDescendants(allSessionsOf(input)),
|
|
1202
|
+
manualOrder: input.manualOrder,
|
|
1203
|
+
topZone: input.topZone
|
|
1204
|
+
};
|
|
1205
|
+
const query = (typeof input.query === "string" ? input.query : "").trim().toLowerCase();
|
|
1206
|
+
if (query !== "") return buildSearchRows(input, context, query);
|
|
1207
|
+
const activeProjects = activeProjectsOf(input);
|
|
1208
|
+
const manualProjects = input.manualOrder?.manual === true ? input.manualOrder.projects : void 0;
|
|
1209
|
+
const orderedProjects = applyManualOrder(activeProjects, manualProjects, (project) => project.key);
|
|
1210
|
+
const rows = [];
|
|
1211
|
+
for (const project of orderedProjects) {
|
|
1212
|
+
const containers = containersOfProject(project, context);
|
|
1213
|
+
const projectCollapsed = isCollapsed(context.collapsedKeys, containers.projectKey);
|
|
1214
|
+
const flatContainer = containers.flat ?? {
|
|
1215
|
+
key: containers.projectKey,
|
|
1216
|
+
kind: "project",
|
|
1217
|
+
depth: 1,
|
|
1218
|
+
sessions: project.flatSessions,
|
|
1219
|
+
project
|
|
1220
|
+
};
|
|
1221
|
+
const flatResult = emitContainer(flatContainer, context);
|
|
1222
|
+
const rendersFlat = containers.flat !== void 0;
|
|
1223
|
+
const historyResult = containers.history === void 0 ? void 0 : emitContainer(containers.history, context);
|
|
1224
|
+
const orderedWorktrees = applyManualOrder(
|
|
1225
|
+
containers.worktrees,
|
|
1226
|
+
worktreeOrderOf(context.manualOrder, project.key),
|
|
1227
|
+
(entry) => entry.node.path
|
|
1228
|
+
);
|
|
1229
|
+
const worktreeResults = orderedWorktrees.map((entry) => ({
|
|
1230
|
+
node: entry.node,
|
|
1231
|
+
spec: entry.spec,
|
|
1232
|
+
result: emitContainer(entry.spec, context)
|
|
1233
|
+
}));
|
|
1234
|
+
const allResults = [
|
|
1235
|
+
...worktreeResults.map((entry) => entry.result),
|
|
1236
|
+
// flat 只对非 git 工作区计入 sessionCount / runningCount(D11 语义不变);
|
|
1237
|
+
// git 项目的 flat 容器仅用于上面的高亮判定。
|
|
1238
|
+
...rendersFlat ? [flatResult] : [],
|
|
1239
|
+
...historyResult === void 0 ? [] : [historyResult]
|
|
1240
|
+
];
|
|
1241
|
+
const identity2 = projectIdentity(project);
|
|
1242
|
+
rows.push({
|
|
1243
|
+
kind: "project",
|
|
1244
|
+
key: containers.projectKey,
|
|
1245
|
+
label: project.title,
|
|
1246
|
+
depth: 0,
|
|
1247
|
+
expanded: !projectCollapsed,
|
|
1248
|
+
isGit: project.isGit === true,
|
|
1249
|
+
// D11(2026-09-21 修订):git 项目恒有 worktree 子行 ⇒ worktreeCount 恒等于
|
|
1250
|
+
// `worktrees.length`(含单 worktree 的 git 项目);非 git 工作区为 0。
|
|
1251
|
+
worktreeCount: containers.hasWorktreeRows ? project.worktrees.length : 0,
|
|
1252
|
+
sessionCount: allResults.reduce((sum, result) => sum + result.sessionCount, 0),
|
|
1253
|
+
runningCount: allResults.reduce((sum, result) => sum + result.runningCount, 0),
|
|
1254
|
+
pendingCount: allResults.reduce((sum, result) => sum + result.pendingCount, 0),
|
|
1255
|
+
// RT2(2026-10-20,含追加裁决):**worktree 子项 OR 本 workspace 的 flat/普通会话**。
|
|
1256
|
+
// `allResults` 同时含 history,绝不能整体用于此判定;history 桶与未分组仍显式排除。
|
|
1257
|
+
hasRunningTasks: worktreeResults.some((entry) => entry.result.hasRunningTasks === true) || flatResult.hasRunningTasks === true,
|
|
1258
|
+
...identity2
|
|
1259
|
+
});
|
|
1260
|
+
if (projectCollapsed) continue;
|
|
1261
|
+
for (const entry of worktreeResults) {
|
|
1262
|
+
const labels = worktreeLabels(entry.node, context.t);
|
|
1263
|
+
rows.push({
|
|
1264
|
+
kind: "worktree",
|
|
1265
|
+
key: entry.spec.key,
|
|
1266
|
+
label: labels.label,
|
|
1267
|
+
depth: 1,
|
|
1268
|
+
expanded: !isCollapsed(context.collapsedKeys, entry.spec.key),
|
|
1269
|
+
path: entry.node.path,
|
|
1270
|
+
isMain: entry.node.isMain === true,
|
|
1271
|
+
exists: entry.node.exists === true,
|
|
1272
|
+
sessionCount: entry.result.sessionCount,
|
|
1273
|
+
runningCount: entry.result.runningCount,
|
|
1274
|
+
pendingCount: entry.result.pendingCount,
|
|
1275
|
+
hasRunningTasks: entry.result.hasRunningTasks,
|
|
1276
|
+
...labels.sublabel === void 0 ? {} : { sublabel: labels.sublabel },
|
|
1277
|
+
...entry.node.workspaceId === void 0 ? {} : { workspaceId: entry.node.workspaceId }
|
|
1278
|
+
});
|
|
1279
|
+
if (isCollapsed(context.collapsedKeys, entry.spec.key)) continue;
|
|
1280
|
+
rows.push(...entry.result.rows);
|
|
1281
|
+
}
|
|
1282
|
+
if (rendersFlat) rows.push(...flatResult.rows);
|
|
1283
|
+
if (containers.history !== void 0 && historyResult !== void 0) {
|
|
1284
|
+
rows.push({
|
|
1285
|
+
kind: "history",
|
|
1286
|
+
key: containers.history.key,
|
|
1287
|
+
label: context.t("history.label"),
|
|
1288
|
+
depth: 1,
|
|
1289
|
+
expanded: !isCollapsed(context.collapsedKeys, containers.history.key),
|
|
1290
|
+
sessionCount: historyResult.sessionCount,
|
|
1291
|
+
runningCount: historyResult.runningCount,
|
|
1292
|
+
pendingCount: historyResult.pendingCount
|
|
1293
|
+
});
|
|
1294
|
+
if (!isCollapsed(context.collapsedKeys, containers.history.key)) {
|
|
1295
|
+
rows.push(...historyResult.rows);
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
if (hasVisibleMembers(input.ungrouped, context)) {
|
|
1300
|
+
const spec = ungroupedContainer(input);
|
|
1301
|
+
const result = emitContainer(spec, context);
|
|
1302
|
+
const collapsed = isCollapsed(context.collapsedKeys, spec.key);
|
|
1303
|
+
rows.push({
|
|
1304
|
+
kind: "project",
|
|
1305
|
+
key: spec.key,
|
|
1306
|
+
label: context.t("section.ungrouped"),
|
|
1307
|
+
depth: 0,
|
|
1308
|
+
expanded: !collapsed,
|
|
1309
|
+
isGit: false,
|
|
1310
|
+
worktreeCount: 0,
|
|
1311
|
+
sessionCount: result.sessionCount,
|
|
1312
|
+
runningCount: result.runningCount,
|
|
1313
|
+
pendingCount: result.pendingCount,
|
|
1314
|
+
// RT2(用户裁决):未分组行虽然是 `project` 形态,但**显式**为 false ——
|
|
1315
|
+
// 即使 `result.hasRunningTasks` 为 true(未分组容器内有会话在跑)也不许用:
|
|
1316
|
+
// 「project 文件夹高亮」只代表「该 workspace 的 worktree 子项或 flat 会话有任务在跑」,
|
|
1317
|
+
// 未分组不属于任何 workspace(2026-10-20 追加裁决后仍然排除)。
|
|
1318
|
+
hasRunningTasks: false
|
|
1319
|
+
});
|
|
1320
|
+
if (!collapsed) rows.push(...result.rows);
|
|
1321
|
+
}
|
|
1322
|
+
if (input.includeRecent === true) {
|
|
1323
|
+
rows.push(...emitRecentSection(input, context));
|
|
1324
|
+
}
|
|
1325
|
+
return rows;
|
|
1326
|
+
}
|
|
1327
|
+
function emitRecentSection(input, context) {
|
|
1328
|
+
const specs = [];
|
|
1329
|
+
for (const project of activeProjectsOf(input)) {
|
|
1330
|
+
const containers = containersOfProject(project, context);
|
|
1331
|
+
for (const entry of containers.worktrees) specs.push(entry.spec);
|
|
1332
|
+
if (containers.flat !== void 0) specs.push(containers.flat);
|
|
1333
|
+
if (containers.history !== void 0) specs.push(containers.history);
|
|
1334
|
+
}
|
|
1335
|
+
if (hasVisibleMembers(input.ungrouped, context)) {
|
|
1336
|
+
specs.push(ungroupedContainer(input));
|
|
1337
|
+
}
|
|
1338
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
1339
|
+
for (const spec of specs) {
|
|
1340
|
+
for (const session of visibleMembers(spec, context)) {
|
|
1341
|
+
const key = normalizeSessionId(session.sessionId);
|
|
1342
|
+
if (key === "") continue;
|
|
1343
|
+
const prior = byKey.get(key);
|
|
1344
|
+
if (prior === void 0 || byRecentActivity(session, prior) < 0) {
|
|
1345
|
+
byKey.set(key, session);
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
if (byKey.size === 0) return [];
|
|
1350
|
+
const ordered = [...byKey.values()].sort(byRecentActivity);
|
|
1351
|
+
const recentKey = `r:${RECENT_KEY}`;
|
|
1352
|
+
const collapsed = isCollapsed(context.collapsedKeys, recentKey);
|
|
1353
|
+
const recentSpec = {
|
|
1354
|
+
key: recentKey,
|
|
1355
|
+
kind: "recent",
|
|
1356
|
+
depth: 1,
|
|
1357
|
+
sessions: ordered
|
|
1358
|
+
};
|
|
1359
|
+
const rows = [
|
|
1360
|
+
{
|
|
1361
|
+
kind: "recent",
|
|
1362
|
+
key: recentKey,
|
|
1363
|
+
label: context.t("section.recent"),
|
|
1364
|
+
depth: 0,
|
|
1365
|
+
expanded: !collapsed,
|
|
1366
|
+
sessionCount: ordered.length
|
|
1367
|
+
}
|
|
1368
|
+
];
|
|
1369
|
+
if (!collapsed) {
|
|
1370
|
+
const truncation = truncateByLevel(ordered, recentKey, context, "recent", recentSpec.depth);
|
|
1371
|
+
for (const session of truncation.selected) {
|
|
1372
|
+
rows.push(
|
|
1373
|
+
toSessionRow(
|
|
1374
|
+
session,
|
|
1375
|
+
recentSpec.depth,
|
|
1376
|
+
subagentCountOf(context.subagentRunningCounts, session.sessionId),
|
|
1377
|
+
recentSpec,
|
|
1378
|
+
context
|
|
1379
|
+
)
|
|
1380
|
+
);
|
|
1381
|
+
}
|
|
1382
|
+
if (truncation.more !== void 0) rows.push(truncation.more);
|
|
1383
|
+
}
|
|
1384
|
+
return rows;
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
// src/live-merge.ts
|
|
1388
|
+
var SESSION_ID_PREFIX2 = "session-";
|
|
1389
|
+
function bareId(id) {
|
|
1390
|
+
return id.startsWith(SESSION_ID_PREFIX2) && id.length > SESSION_ID_PREFIX2.length ? id.slice(SESSION_ID_PREFIX2.length) : id;
|
|
1391
|
+
}
|
|
1392
|
+
function normalize(path) {
|
|
1393
|
+
let out = path.replace(/\\/g, "/");
|
|
1394
|
+
while (out.length > 1 && out.endsWith("/")) out = out.slice(0, -1);
|
|
1395
|
+
return out;
|
|
1396
|
+
}
|
|
1397
|
+
function isUnder(cwd, base) {
|
|
1398
|
+
if (cwd === base) return true;
|
|
1399
|
+
return cwd.startsWith(base.endsWith("/") ? base : `${base}/`);
|
|
1400
|
+
}
|
|
1401
|
+
function finite(value) {
|
|
1402
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
1403
|
+
}
|
|
1404
|
+
function nonEmpty(value) {
|
|
1405
|
+
return typeof value === "string" && value !== "" ? value : void 0;
|
|
1406
|
+
}
|
|
1407
|
+
function patchRow(row, entry) {
|
|
1408
|
+
const title = nonEmpty(entry.title);
|
|
1409
|
+
const running = typeof entry.running === "boolean" ? entry.running : row.running;
|
|
1410
|
+
const blank = typeof entry.blank === "boolean" ? entry.blank : row.blank;
|
|
1411
|
+
const liveUpdated = finite(entry.updatedAt);
|
|
1412
|
+
const updatedAt = liveUpdated !== void 0 && liveUpdated > row.updatedAt ? liveUpdated : row.updatedAt;
|
|
1413
|
+
const priorActivity = row.lastActivityAt ?? row.updatedAt;
|
|
1414
|
+
const lastActivityAt = updatedAt > priorActivity ? updatedAt : priorActivity;
|
|
1415
|
+
if ((title === void 0 || title === row.title) && running === row.running && blank === row.blank && updatedAt === row.updatedAt && lastActivityAt === (row.lastActivityAt ?? row.updatedAt)) {
|
|
1416
|
+
return row;
|
|
1417
|
+
}
|
|
1418
|
+
return {
|
|
1419
|
+
...row,
|
|
1420
|
+
...title === void 0 ? {} : { title },
|
|
1421
|
+
running,
|
|
1422
|
+
blank,
|
|
1423
|
+
updatedAt,
|
|
1424
|
+
lastActivityAt
|
|
1425
|
+
};
|
|
1426
|
+
}
|
|
1427
|
+
function patchList(list, live) {
|
|
1428
|
+
let out;
|
|
1429
|
+
for (let index = 0; index < list.length; index += 1) {
|
|
1430
|
+
const row = list[index];
|
|
1431
|
+
const entry = live.get(bareId(row.sessionId));
|
|
1432
|
+
if (entry === void 0) continue;
|
|
1433
|
+
const next = patchRow(row, entry);
|
|
1434
|
+
if (next === row) continue;
|
|
1435
|
+
out ??= list.slice();
|
|
1436
|
+
out[index] = next;
|
|
1437
|
+
}
|
|
1438
|
+
return out ?? list;
|
|
1439
|
+
}
|
|
1440
|
+
function liveEntriesOf(snapshot) {
|
|
1441
|
+
const out = /* @__PURE__ */ new Map();
|
|
1442
|
+
if (typeof snapshot !== "object" || snapshot === null) return out;
|
|
1443
|
+
const byId = snapshot.byId;
|
|
1444
|
+
const add = (key, value) => {
|
|
1445
|
+
if (typeof value !== "object" || value === null) return;
|
|
1446
|
+
const entry = value;
|
|
1447
|
+
const id = nonEmpty(entry.id) ?? key;
|
|
1448
|
+
if (id === "") return;
|
|
1449
|
+
out.set(bareId(id), { ...entry, id });
|
|
1450
|
+
};
|
|
1451
|
+
if (byId instanceof Map) {
|
|
1452
|
+
for (const [key, value] of byId) add(String(key), value);
|
|
1453
|
+
} else if (typeof byId === "object" && byId !== null) {
|
|
1454
|
+
for (const [key, value] of Object.entries(byId)) add(key, value);
|
|
1455
|
+
}
|
|
1456
|
+
return out;
|
|
1457
|
+
}
|
|
1458
|
+
function mergeLiveSessions(tree, snapshot) {
|
|
1459
|
+
const live = liveEntriesOf(snapshot);
|
|
1460
|
+
if (live.size === 0) return { tree, pendingIds: [] };
|
|
1461
|
+
const known = /* @__PURE__ */ new Set();
|
|
1462
|
+
const remember = (list) => {
|
|
1463
|
+
for (const row of list) known.add(bareId(row.sessionId));
|
|
1464
|
+
};
|
|
1465
|
+
for (const project of tree.projects) {
|
|
1466
|
+
for (const node of project.worktrees) remember(node.sessions);
|
|
1467
|
+
remember(project.history);
|
|
1468
|
+
remember(project.flatSessions);
|
|
1469
|
+
}
|
|
1470
|
+
remember(tree.ungrouped);
|
|
1471
|
+
const archived = new Set(tree.archivedSessionIds.map(bareId));
|
|
1472
|
+
const pendingIds = [];
|
|
1473
|
+
const additions = [];
|
|
1474
|
+
for (const [key, entry] of live) {
|
|
1475
|
+
if (known.has(key) || archived.has(key)) continue;
|
|
1476
|
+
if (entry.origin === "subagent" || nonEmpty(entry.parentId) !== void 0) continue;
|
|
1477
|
+
const cwd = nonEmpty(entry.cwd);
|
|
1478
|
+
if (cwd === void 0) continue;
|
|
1479
|
+
const id = nonEmpty(entry.id) ?? key;
|
|
1480
|
+
pendingIds.push(id);
|
|
1481
|
+
additions.push({ entry, cwd: normalize(cwd), id });
|
|
1482
|
+
}
|
|
1483
|
+
pendingIds.sort();
|
|
1484
|
+
let changed = false;
|
|
1485
|
+
const projects = tree.projects.map((project) => {
|
|
1486
|
+
const worktrees = project.worktrees.map((node) => {
|
|
1487
|
+
const sessions = patchList(node.sessions, live);
|
|
1488
|
+
return sessions === node.sessions ? node : { ...node, sessions };
|
|
1489
|
+
});
|
|
1490
|
+
const history = patchList(project.history, live);
|
|
1491
|
+
const flatSessions = patchList(project.flatSessions, live);
|
|
1492
|
+
const worktreesChanged = worktrees.some((node, index) => node !== project.worktrees[index]);
|
|
1493
|
+
if (!worktreesChanged && history === project.history && flatSessions === project.flatSessions) return project;
|
|
1494
|
+
changed = true;
|
|
1495
|
+
return { ...project, worktrees, history, flatSessions };
|
|
1496
|
+
});
|
|
1497
|
+
const ungrouped = patchList(tree.ungrouped, live);
|
|
1498
|
+
if (ungrouped !== tree.ungrouped) changed = true;
|
|
1499
|
+
if (additions.length > 0) {
|
|
1500
|
+
const targets = [];
|
|
1501
|
+
const projectIndexByKey = /* @__PURE__ */ new Map();
|
|
1502
|
+
projects.forEach((project, projectIndex) => {
|
|
1503
|
+
projectIndexByKey.set(project.key, projectIndex);
|
|
1504
|
+
if (!project.isGit) return;
|
|
1505
|
+
project.worktrees.forEach((node, worktreeIndex) => {
|
|
1506
|
+
if (node.exists === false) return;
|
|
1507
|
+
targets.push({ path: normalize(node.path), projectIndex, worktreeIndex });
|
|
1508
|
+
});
|
|
1509
|
+
});
|
|
1510
|
+
for (const [path, workspaceId] of Object.entries(tree.workspaceByPath ?? {})) {
|
|
1511
|
+
const projectIndex = projectIndexByKey.get(`ws:${workspaceId}`);
|
|
1512
|
+
if (projectIndex === void 0 || projects[projectIndex].isGit) continue;
|
|
1513
|
+
targets.push({ path: normalize(path), projectIndex, worktreeIndex: -1 });
|
|
1514
|
+
}
|
|
1515
|
+
for (const { entry, cwd, id } of additions) {
|
|
1516
|
+
let best;
|
|
1517
|
+
for (const target of targets) {
|
|
1518
|
+
if (!isUnder(cwd, target.path)) continue;
|
|
1519
|
+
if (best === void 0 || target.path.length > best.path.length) best = target;
|
|
1520
|
+
}
|
|
1521
|
+
if (best === void 0) continue;
|
|
1522
|
+
const updatedAt = finite(entry.updatedAt) ?? 0;
|
|
1523
|
+
const title = nonEmpty(entry.title);
|
|
1524
|
+
const added = {
|
|
1525
|
+
sessionId: id,
|
|
1526
|
+
updatedAt,
|
|
1527
|
+
lastActivityAt: updatedAt,
|
|
1528
|
+
running: entry.running === true,
|
|
1529
|
+
blank: entry.blank === true,
|
|
1530
|
+
cwd,
|
|
1531
|
+
...title === void 0 ? {} : { title }
|
|
1532
|
+
};
|
|
1533
|
+
const project = projects[best.projectIndex];
|
|
1534
|
+
if (best.worktreeIndex < 0) {
|
|
1535
|
+
projects[best.projectIndex] = { ...project, flatSessions: [added, ...project.flatSessions] };
|
|
1536
|
+
} else {
|
|
1537
|
+
const worktrees = project.worktrees.slice();
|
|
1538
|
+
const node = worktrees[best.worktreeIndex];
|
|
1539
|
+
worktrees[best.worktreeIndex] = { ...node, sessions: [added, ...node.sessions] };
|
|
1540
|
+
projects[best.projectIndex] = { ...project, worktrees };
|
|
1541
|
+
}
|
|
1542
|
+
changed = true;
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
if (!changed) return { tree, pendingIds };
|
|
1546
|
+
return { tree: { ...tree, projects, ungrouped }, pendingIds };
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1549
|
+
// src/row-memo.ts
|
|
1550
|
+
function shallowEqualRecord(a, b) {
|
|
1551
|
+
if (a === b) return true;
|
|
1552
|
+
const left = a;
|
|
1553
|
+
const right = b;
|
|
1554
|
+
const keys = Object.keys(left);
|
|
1555
|
+
if (keys.length !== Object.keys(right).length) return false;
|
|
1556
|
+
for (const key of keys) {
|
|
1557
|
+
if (!Object.prototype.hasOwnProperty.call(right, key)) return false;
|
|
1558
|
+
if (!Object.is(left[key], right[key])) return false;
|
|
1559
|
+
}
|
|
1560
|
+
return true;
|
|
1561
|
+
}
|
|
1562
|
+
function dragStateEqual(a, b) {
|
|
1563
|
+
if (a === void 0 || b === void 0) return a === b;
|
|
1564
|
+
return a.draggable === b.draggable && a.dragging === b.dragging && a.marker === b.marker;
|
|
1565
|
+
}
|
|
1566
|
+
function sessionRowPropsEqual(prev, next) {
|
|
1567
|
+
return prev.t === next.t && prev.handlers === next.handlers && prev.rowKey === next.rowKey && dragStateEqual(prev.drag, next.drag) && shallowEqualRecord(prev.row, next.row);
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
// src/sidebar.tsx
|
|
1571
|
+
var P = Primitives;
|
|
1572
|
+
function splitKey(props, key) {
|
|
1573
|
+
if (props === null || typeof props !== "object") return { rest: props, key };
|
|
1574
|
+
if (!Object.prototype.hasOwnProperty.call(props, "key")) return { rest: props, key };
|
|
1575
|
+
const { key: innerKey, ...rest } = props;
|
|
1576
|
+
return { rest, key: key ?? innerKey };
|
|
1577
|
+
}
|
|
1578
|
+
var jsx = ((type, props, key) => {
|
|
1579
|
+
const split = splitKey(props, key);
|
|
1580
|
+
return (0, import_jsx_runtime.jsx)(type, split.rest, split.key);
|
|
1581
|
+
});
|
|
1582
|
+
var jsxs = ((type, props, key) => {
|
|
1583
|
+
const split = splitKey(props, key);
|
|
1584
|
+
return (0, import_jsx_runtime.jsxs)(type, split.rest, split.key);
|
|
1585
|
+
});
|
|
1586
|
+
function icon(name2, props) {
|
|
1587
|
+
const resolved = resolveIcon(P, name2);
|
|
1588
|
+
if (resolved.candidate === void 0) return null;
|
|
1589
|
+
return jsx(resolved.Component, { size: iconSize(name2), ...props });
|
|
1590
|
+
}
|
|
1591
|
+
var SAME_LOCATION_START_SESSION = { clearPreviousDraft: false };
|
|
1592
|
+
var DIRECTORY_FLOW_SLOT = "sidebar.workspaces.worktreeDirectoryFlow";
|
|
1593
|
+
var LOCALE_NS = "dsh-worktree-groups";
|
|
1594
|
+
var FALLBACK_T = createT(zh);
|
|
1595
|
+
var PREFIX_WORKTREE = "w:";
|
|
1596
|
+
var PREFIX_UNGROUPED = `p:${UNGROUPED_KEY}`;
|
|
1597
|
+
var LS_COLLAPSED = "dsh-worktree-groups.collapsed";
|
|
1598
|
+
var LS_EXPAND_LEVELS = "dsh-worktree-groups.expandLevels";
|
|
1599
|
+
var LS_ORDER = "dsh-worktree-groups.order";
|
|
1600
|
+
var LS_ARCHIVED_PROJECTS = "dsh-worktree-groups.archivedProjects";
|
|
1601
|
+
var TREE_REFRESH_MS = 5e3;
|
|
1602
|
+
var RELOAD_DEBOUNCE_MS = 220;
|
|
1603
|
+
var ROW_HEIGHT = 28;
|
|
1604
|
+
var RAIL_BUTTON = 36;
|
|
1605
|
+
var ROUTE_TREE = "/dsh-worktree-groups/tree";
|
|
1606
|
+
var ROUTE_WORKSPACE_OPEN = "/dsh-worktree-groups/workspace-open";
|
|
1607
|
+
var ROUTE_WORKTREE_CREATE = "/dsh-worktree-groups/worktree-create";
|
|
1608
|
+
var ROUTE_WORKTREE_REMOVE = "/dsh-worktree-groups/worktree-remove";
|
|
1609
|
+
var ROUTE_REVEAL = "/dsh-worktree-groups/reveal";
|
|
1610
|
+
async function postJson(route, body) {
|
|
1611
|
+
const response = await fetch(route, {
|
|
1612
|
+
method: "POST",
|
|
1613
|
+
headers: { "content-type": "application/json" },
|
|
1614
|
+
body: JSON.stringify(body)
|
|
1615
|
+
});
|
|
1616
|
+
return await response.json();
|
|
1617
|
+
}
|
|
1618
|
+
var MENU = {
|
|
1619
|
+
newSession: "new-session",
|
|
1620
|
+
newWorktree: "new-worktree",
|
|
1621
|
+
reveal: "reveal",
|
|
1622
|
+
copyPath: "copy-path",
|
|
1623
|
+
renameWorkspace: "rename-workspace",
|
|
1624
|
+
removeWorktree: "remove-worktree",
|
|
1625
|
+
archiveWorkspace: "archive-workspace",
|
|
1626
|
+
renameSession: "rename-session",
|
|
1627
|
+
archiveSession: "archive-session",
|
|
1628
|
+
forkSession: "fork-session",
|
|
1629
|
+
/** D10:清除本地手动顺序,立即恢复默认排序(仅 `manual === true` 时出现)。 */
|
|
1630
|
+
resetOrder: "reset-order"
|
|
1631
|
+
};
|
|
1632
|
+
var archiveListeners = /* @__PURE__ */ new Set();
|
|
1633
|
+
var latestKnownProjects = [];
|
|
1634
|
+
function notifyArchiveWorkspaceChanged() {
|
|
1635
|
+
for (const listener of [...archiveListeners]) {
|
|
1636
|
+
try {
|
|
1637
|
+
listener();
|
|
1638
|
+
} catch {
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
function readBoolean(source, key) {
|
|
1643
|
+
const value = source[key];
|
|
1644
|
+
return typeof value === "boolean" ? value : void 0;
|
|
1645
|
+
}
|
|
1646
|
+
function readFunction(source, key) {
|
|
1647
|
+
const value = source[key];
|
|
1648
|
+
if (typeof value !== "function") return void 0;
|
|
1649
|
+
return value;
|
|
1650
|
+
}
|
|
1651
|
+
function readFlagMap(key) {
|
|
1652
|
+
try {
|
|
1653
|
+
const raw = localStorage.getItem(key);
|
|
1654
|
+
if (raw === null) return {};
|
|
1655
|
+
const parsed = JSON.parse(raw);
|
|
1656
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return {};
|
|
1657
|
+
const result = {};
|
|
1658
|
+
for (const [entryKey, entryValue] of Object.entries(parsed)) {
|
|
1659
|
+
if (entryValue === true) result[entryKey] = true;
|
|
1660
|
+
}
|
|
1661
|
+
return result;
|
|
1662
|
+
} catch {
|
|
1663
|
+
return {};
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
function readLevelMap(key) {
|
|
1667
|
+
try {
|
|
1668
|
+
const raw = localStorage.getItem(key);
|
|
1669
|
+
if (raw === null) return {};
|
|
1670
|
+
const parsed = JSON.parse(raw);
|
|
1671
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return {};
|
|
1672
|
+
const result = {};
|
|
1673
|
+
for (const [entryKey, entryValue] of Object.entries(parsed)) {
|
|
1674
|
+
if (typeof entryValue === "number" && Number.isFinite(entryValue) && entryValue >= 1) {
|
|
1675
|
+
result[entryKey] = Math.floor(entryValue);
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
return result;
|
|
1679
|
+
} catch {
|
|
1680
|
+
return {};
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
function writeLevelMap(key, value) {
|
|
1684
|
+
try {
|
|
1685
|
+
localStorage.setItem(key, JSON.stringify(value));
|
|
1686
|
+
} catch {
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
function writeFlagMap(key, value) {
|
|
1690
|
+
try {
|
|
1691
|
+
localStorage.setItem(key, JSON.stringify(value));
|
|
1692
|
+
} catch {
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
var EMPTY_ORDER = { manual: false };
|
|
1696
|
+
function stringListOf(value) {
|
|
1697
|
+
if (!Array.isArray(value)) return void 0;
|
|
1698
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1699
|
+
const result = [];
|
|
1700
|
+
for (const entry of value) {
|
|
1701
|
+
if (typeof entry !== "string" || entry === "" || seen.has(entry)) continue;
|
|
1702
|
+
seen.add(entry);
|
|
1703
|
+
result.push(entry);
|
|
1704
|
+
}
|
|
1705
|
+
return result;
|
|
1706
|
+
}
|
|
1707
|
+
function stringListMapOf(value) {
|
|
1708
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
|
|
1709
|
+
const result = {};
|
|
1710
|
+
let any = false;
|
|
1711
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
1712
|
+
const list = stringListOf(entry);
|
|
1713
|
+
if (list === void 0 || list.length === 0) continue;
|
|
1714
|
+
result[key] = list;
|
|
1715
|
+
any = true;
|
|
1716
|
+
}
|
|
1717
|
+
return any ? result : void 0;
|
|
1718
|
+
}
|
|
1719
|
+
function readManualOrder() {
|
|
1720
|
+
try {
|
|
1721
|
+
const raw = localStorage.getItem(LS_ORDER);
|
|
1722
|
+
if (raw === null) return EMPTY_ORDER;
|
|
1723
|
+
const parsed = JSON.parse(raw);
|
|
1724
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return EMPTY_ORDER;
|
|
1725
|
+
const record = parsed;
|
|
1726
|
+
if (record.manual !== true) return EMPTY_ORDER;
|
|
1727
|
+
const order = { manual: true };
|
|
1728
|
+
const projects = stringListOf(record.projects);
|
|
1729
|
+
if (projects !== void 0 && projects.length > 0) order.projects = projects;
|
|
1730
|
+
const worktrees = stringListMapOf(record.worktrees);
|
|
1731
|
+
if (worktrees !== void 0) order.worktrees = worktrees;
|
|
1732
|
+
const sessions = stringListMapOf(record.sessions);
|
|
1733
|
+
if (sessions !== void 0) order.sessions = sessions;
|
|
1734
|
+
return order;
|
|
1735
|
+
} catch {
|
|
1736
|
+
return EMPTY_ORDER;
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
function writeManualOrder(order) {
|
|
1740
|
+
try {
|
|
1741
|
+
localStorage.setItem(LS_ORDER, JSON.stringify(order));
|
|
1742
|
+
} catch {
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
function clearManualOrder() {
|
|
1746
|
+
try {
|
|
1747
|
+
localStorage.removeItem(LS_ORDER);
|
|
1748
|
+
} catch {
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
function readArchivedProjectsMap() {
|
|
1752
|
+
try {
|
|
1753
|
+
const raw = localStorage.getItem(LS_ARCHIVED_PROJECTS);
|
|
1754
|
+
if (raw === null) return {};
|
|
1755
|
+
const parsed = JSON.parse(raw);
|
|
1756
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return {};
|
|
1757
|
+
const result = {};
|
|
1758
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
1759
|
+
if (key === "" || typeof value !== "object" || value === null || Array.isArray(value)) continue;
|
|
1760
|
+
const entry = value;
|
|
1761
|
+
result[key] = {
|
|
1762
|
+
key,
|
|
1763
|
+
title: typeof entry.title === "string" && entry.title !== "" ? entry.title : key,
|
|
1764
|
+
...typeof entry.path === "string" && entry.path !== "" ? { path: entry.path } : {},
|
|
1765
|
+
isGit: entry.isGit === true,
|
|
1766
|
+
archivedAt: typeof entry.archivedAt === "number" && Number.isFinite(entry.archivedAt) ? entry.archivedAt : 0
|
|
1767
|
+
};
|
|
1768
|
+
}
|
|
1769
|
+
return result;
|
|
1770
|
+
} catch {
|
|
1771
|
+
return {};
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
function writeArchivedProjectsMap(map) {
|
|
1775
|
+
try {
|
|
1776
|
+
localStorage.setItem(LS_ARCHIVED_PROJECTS, JSON.stringify(map));
|
|
1777
|
+
} catch {
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
function archiveWorkspaceClient(item) {
|
|
1781
|
+
const current = readArchivedProjectsMap();
|
|
1782
|
+
current[item.key] = item;
|
|
1783
|
+
writeArchivedProjectsMap(current);
|
|
1784
|
+
notifyArchiveWorkspaceChanged();
|
|
1785
|
+
}
|
|
1786
|
+
function unarchiveWorkspaceByKeyClient(projectKey) {
|
|
1787
|
+
const current = readArchivedProjectsMap();
|
|
1788
|
+
if (current[projectKey] === void 0) return;
|
|
1789
|
+
delete current[projectKey];
|
|
1790
|
+
writeArchivedProjectsMap(current);
|
|
1791
|
+
notifyArchiveWorkspaceChanged();
|
|
1792
|
+
}
|
|
1793
|
+
function unarchiveWorkspaceByPathClient(path) {
|
|
1794
|
+
const target = normalizeRepoKey(path);
|
|
1795
|
+
if (target === void 0) return;
|
|
1796
|
+
const current = readArchivedProjectsMap();
|
|
1797
|
+
const keys = Object.keys(current);
|
|
1798
|
+
if (keys.length === 0) return;
|
|
1799
|
+
let changed = false;
|
|
1800
|
+
for (const [key, item] of Object.entries(current)) {
|
|
1801
|
+
if (item.path !== void 0 && normalizeRepoKey(item.path) === target) {
|
|
1802
|
+
delete current[key];
|
|
1803
|
+
changed = true;
|
|
1804
|
+
continue;
|
|
1805
|
+
}
|
|
1806
|
+
const proj = latestKnownProjects.find((p) => p.key === key);
|
|
1807
|
+
if (proj !== void 0) {
|
|
1808
|
+
const hitMain = proj.mainPath !== void 0 && normalizeRepoKey(proj.mainPath) === target;
|
|
1809
|
+
const hitWt = proj.worktrees.some((wt) => normalizeRepoKey(wt.path) === target);
|
|
1810
|
+
const hitFlat = proj.flatSessions.some((s) => s.cwd !== void 0 && normalizeRepoKey(s.cwd) === target);
|
|
1811
|
+
if (hitMain || hitWt || hitFlat) {
|
|
1812
|
+
delete current[key];
|
|
1813
|
+
changed = true;
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
if (changed) {
|
|
1818
|
+
writeArchivedProjectsMap(current);
|
|
1819
|
+
notifyArchiveWorkspaceChanged();
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
async function copyText(text) {
|
|
1823
|
+
if (typeof P.writeClipboard === "function") {
|
|
1824
|
+
await P.writeClipboard(text);
|
|
1825
|
+
return;
|
|
1826
|
+
}
|
|
1827
|
+
try {
|
|
1828
|
+
await navigator.clipboard.writeText(text);
|
|
1829
|
+
} catch {
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
function baseName(path) {
|
|
1833
|
+
const trimmed = path.replace(/[/\\]+$/, "");
|
|
1834
|
+
const cut = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"));
|
|
1835
|
+
return trimmed.slice(cut + 1);
|
|
1836
|
+
}
|
|
1837
|
+
function parentDirOf(path) {
|
|
1838
|
+
const trimmed = path.replace(/[/\\]+$/, "");
|
|
1839
|
+
const cut = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"));
|
|
1840
|
+
return cut <= 0 ? "" : trimmed.slice(0, cut);
|
|
1841
|
+
}
|
|
1842
|
+
function present(value) {
|
|
1843
|
+
return value !== void 0 && value !== null;
|
|
1844
|
+
}
|
|
1845
|
+
function indentOf(depth) {
|
|
1846
|
+
return 8 + depth * 14;
|
|
1847
|
+
}
|
|
1848
|
+
function StatusDot(props) {
|
|
1849
|
+
const state = props.pending === true ? "warning" : props.running === true ? "ongoing" : props.completed === true ? "done" : "idle";
|
|
1850
|
+
return jsx(P.StateDot, { state, size: 10 });
|
|
1851
|
+
}
|
|
1852
|
+
function withLiveState(row, live) {
|
|
1853
|
+
if (row.kind !== "session") return row;
|
|
1854
|
+
const client = liveStateOf(live, row.sessionId);
|
|
1855
|
+
const pendingKind = row.pendingInteraction !== void 0 ? visiblePendingKind(row.pendingInteraction) : client.pendingKind;
|
|
1856
|
+
const completed = row.completed === true || client.completionUnread;
|
|
1857
|
+
return {
|
|
1858
|
+
...row,
|
|
1859
|
+
completed,
|
|
1860
|
+
...pendingKind === void 0 ? {} : { pendingInteraction: pendingKind }
|
|
1861
|
+
};
|
|
1862
|
+
}
|
|
1863
|
+
function rowHalf(event) {
|
|
1864
|
+
const rect = event?.currentTarget?.getBoundingClientRect?.();
|
|
1865
|
+
if (rect === void 0) return "after";
|
|
1866
|
+
const top = Number(rect.top) || 0;
|
|
1867
|
+
const height = Number(rect.height) || 0;
|
|
1868
|
+
return (Number(event?.clientY) || 0) < top + height / 2 ? "before" : "after";
|
|
1869
|
+
}
|
|
1870
|
+
function dragLineStyle(half, _indent) {
|
|
1871
|
+
return {
|
|
1872
|
+
position: "absolute",
|
|
1873
|
+
left: 6,
|
|
1874
|
+
right: 6,
|
|
1875
|
+
height: 2,
|
|
1876
|
+
borderRadius: 1,
|
|
1877
|
+
background: "var(--dsw-alias-brand-primary)",
|
|
1878
|
+
pointerEvents: "none",
|
|
1879
|
+
...half === "before" ? { top: -1 } : { bottom: -1 }
|
|
1880
|
+
};
|
|
1881
|
+
}
|
|
1882
|
+
var DRAGGING_OPACITY = 0.45;
|
|
1883
|
+
function rowStyle(active, hovered, indent) {
|
|
1884
|
+
const leftMargin = Math.max(0, indent - 6);
|
|
1885
|
+
return {
|
|
1886
|
+
display: "flex",
|
|
1887
|
+
alignItems: "center",
|
|
1888
|
+
gap: 6,
|
|
1889
|
+
minHeight: ROW_HEIGHT,
|
|
1890
|
+
boxSizing: "border-box",
|
|
1891
|
+
marginLeft: leftMargin,
|
|
1892
|
+
padding: active ? "0 8px 0 10px" : "0 6px",
|
|
1893
|
+
borderRadius: 8,
|
|
1894
|
+
cursor: "pointer",
|
|
1895
|
+
userSelect: "none",
|
|
1896
|
+
color: "var(--dsw-alias-label-primary)",
|
|
1897
|
+
background: active ? "var(--dsw-alias-bg-selected, rgba(65, 118, 230, 0.14))" : hovered ? "var(--dsw-alias-interactive-bg-hover, rgba(127,127,127,0.12))" : "transparent",
|
|
1898
|
+
fontWeight: active ? 600 : 400
|
|
1899
|
+
};
|
|
1900
|
+
}
|
|
1901
|
+
function iconButtonStyle(visible) {
|
|
1902
|
+
return {
|
|
1903
|
+
display: "inline-flex",
|
|
1904
|
+
alignItems: "center",
|
|
1905
|
+
justifyContent: "center",
|
|
1906
|
+
width: 22,
|
|
1907
|
+
height: 22,
|
|
1908
|
+
padding: 0,
|
|
1909
|
+
flex: "none",
|
|
1910
|
+
border: "none",
|
|
1911
|
+
borderRadius: 6,
|
|
1912
|
+
background: "transparent",
|
|
1913
|
+
color: "var(--dsw-alias-label-tertiary, var(--dsw-alias-label-dimmed))",
|
|
1914
|
+
cursor: "pointer",
|
|
1915
|
+
opacity: visible ? 1 : 0,
|
|
1916
|
+
transition: "opacity 0.12s ease"
|
|
1917
|
+
};
|
|
1918
|
+
}
|
|
1919
|
+
function fieldStyle() {
|
|
1920
|
+
return {
|
|
1921
|
+
height: 34,
|
|
1922
|
+
boxSizing: "border-box",
|
|
1923
|
+
border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,0.3))",
|
|
1924
|
+
borderRadius: 10,
|
|
1925
|
+
background: "transparent",
|
|
1926
|
+
color: "var(--dsw-alias-label-primary)",
|
|
1927
|
+
fontFamily: "inherit",
|
|
1928
|
+
fontSize: 13.5,
|
|
1929
|
+
padding: "0 12px",
|
|
1930
|
+
outline: "none"
|
|
1931
|
+
};
|
|
1932
|
+
}
|
|
1933
|
+
function dimText(size = 12) {
|
|
1934
|
+
return { fontSize: size, color: "var(--dsw-alias-label-tertiary, var(--dsw-alias-label-dimmed))" };
|
|
1935
|
+
}
|
|
1936
|
+
function pillStyle() {
|
|
1937
|
+
return {
|
|
1938
|
+
flex: "none",
|
|
1939
|
+
fontSize: 10,
|
|
1940
|
+
lineHeight: "14px",
|
|
1941
|
+
padding: "0 5px",
|
|
1942
|
+
borderRadius: 4,
|
|
1943
|
+
color: "var(--dsw-alias-label-tertiary, var(--dsw-alias-label-dimmed))",
|
|
1944
|
+
border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,0.3))"
|
|
1945
|
+
};
|
|
1946
|
+
}
|
|
1947
|
+
function ContainerRowView(props) {
|
|
1948
|
+
const row = props.row;
|
|
1949
|
+
const isGroup = row.kind === "project";
|
|
1950
|
+
const chevron = row.expanded ? icon("chevronDown") : icon("chevronRight");
|
|
1951
|
+
const lead = row.kind === "history" ? icon("clock") : isGroup ? row.expanded ? icon("folderOpen") : icon("folderClose") : icon("branch");
|
|
1952
|
+
const drag = props.drag;
|
|
1953
|
+
const runningHighlight = row.kind === "history" ? false : row.hasRunningTasks === true;
|
|
1954
|
+
const children = [
|
|
1955
|
+
jsx("span", {
|
|
1956
|
+
key: "lead",
|
|
1957
|
+
...runningHighlight ? { title: props.t("a11y.runningTask") } : {},
|
|
1958
|
+
style: {
|
|
1959
|
+
display: "inline-flex",
|
|
1960
|
+
alignItems: "center",
|
|
1961
|
+
flex: "none",
|
|
1962
|
+
lineHeight: 0,
|
|
1963
|
+
...dimText(12),
|
|
1964
|
+
// 高亮色必须写在 `...dimText(12)` **之后**(dimText 带 label-tertiary 的 color)。
|
|
1965
|
+
// ⚠️ 不能给 `icon(...)` 传 style/color:宿主图标组件只解构 size/className/strokeWidth,
|
|
1966
|
+
// 其余 props 被丢弃(只有外层 span 的 color 会经 currentColor 生效)。
|
|
1967
|
+
...runningHighlight ? {
|
|
1968
|
+
color: "var(--dsw-alias-state-business-primary, #4176e6)",
|
|
1969
|
+
filter: "drop-shadow(0 0 2px var(--dsw-alias-state-business-primary, #4176e6))"
|
|
1970
|
+
} : {}
|
|
1971
|
+
},
|
|
1972
|
+
children: lead
|
|
1973
|
+
}),
|
|
1974
|
+
jsx("span", {
|
|
1975
|
+
key: "chevron",
|
|
1976
|
+
style: { display: "inline-flex", alignItems: "center", flex: "none", lineHeight: 0, ...dimText(12) },
|
|
1977
|
+
children: chevron
|
|
1978
|
+
}),
|
|
1979
|
+
jsx("span", {
|
|
1980
|
+
key: "label",
|
|
1981
|
+
title: row.kind === "worktree" ? row.path : row.label,
|
|
1982
|
+
style: {
|
|
1983
|
+
flex: "none",
|
|
1984
|
+
maxWidth: "62%",
|
|
1985
|
+
overflow: "hidden",
|
|
1986
|
+
textOverflow: "ellipsis",
|
|
1987
|
+
whiteSpace: "nowrap",
|
|
1988
|
+
fontSize: isGroup ? 13 : 12.5,
|
|
1989
|
+
fontWeight: isGroup ? 600 : 500
|
|
1990
|
+
},
|
|
1991
|
+
children: row.label
|
|
1992
|
+
})
|
|
1993
|
+
];
|
|
1994
|
+
if (row.kind === "worktree" && row.sublabel !== void 0) {
|
|
1995
|
+
children.push(jsx("span", {
|
|
1996
|
+
key: "sublabel",
|
|
1997
|
+
style: {
|
|
1998
|
+
flex: 1,
|
|
1999
|
+
minWidth: 0,
|
|
2000
|
+
overflow: "hidden",
|
|
2001
|
+
textOverflow: "ellipsis",
|
|
2002
|
+
whiteSpace: "nowrap",
|
|
2003
|
+
...dimText(11)
|
|
2004
|
+
},
|
|
2005
|
+
children: row.sublabel
|
|
2006
|
+
}));
|
|
2007
|
+
} else {
|
|
2008
|
+
children.push(jsx("span", { key: "spacer", style: { flex: 1, minWidth: 0 } }));
|
|
2009
|
+
}
|
|
2010
|
+
if (row.kind === "worktree" && row.isMain) {
|
|
2011
|
+
children.push(jsx("span", { key: "main", style: pillStyle(), children: props.t("worktree.main") }));
|
|
2012
|
+
}
|
|
2013
|
+
const actionNodes = props.renderActions(props.hovered);
|
|
2014
|
+
if (actionNodes.length > 0) {
|
|
2015
|
+
children.push(jsx("span", {
|
|
2016
|
+
key: "actions",
|
|
2017
|
+
style: { display: "inline-flex", alignItems: "center", gap: 2, flex: "none" },
|
|
2018
|
+
children: actionNodes
|
|
2019
|
+
}));
|
|
2020
|
+
}
|
|
2021
|
+
if (drag !== void 0 && drag.marker !== null) {
|
|
2022
|
+
children.push(jsx("span", {
|
|
2023
|
+
key: "drop-line",
|
|
2024
|
+
"aria-hidden": true,
|
|
2025
|
+
style: dragLineStyle(drag.marker, indentOf(row.depth))
|
|
2026
|
+
}));
|
|
2027
|
+
}
|
|
2028
|
+
return jsx("div", {
|
|
2029
|
+
role: "treeitem",
|
|
2030
|
+
"aria-expanded": row.expanded,
|
|
2031
|
+
"data-key": row.key,
|
|
2032
|
+
// 仅高亮时出现(不高亮时**没有**该属性,不是 "false")。与 `data-key` 共存;
|
|
2033
|
+
// 无浏览器环境下它是断言「视觉真的接上了判据」的唯一钩子(设计 §5.3)。
|
|
2034
|
+
...runningHighlight ? { "data-running": "true" } : {},
|
|
2035
|
+
style: {
|
|
2036
|
+
...rowStyle(false, props.hovered, indentOf(row.depth)),
|
|
2037
|
+
position: "relative",
|
|
2038
|
+
...drag !== void 0 && drag.dragging ? { opacity: DRAGGING_OPACITY } : {}
|
|
2039
|
+
},
|
|
2040
|
+
onMouseEnter: () => {
|
|
2041
|
+
props.onHoverChange(true);
|
|
2042
|
+
},
|
|
2043
|
+
onMouseLeave: () => {
|
|
2044
|
+
props.onHoverChange(false);
|
|
2045
|
+
},
|
|
2046
|
+
onClick: props.onToggle,
|
|
2047
|
+
onContextMenu: props.onContextMenu,
|
|
2048
|
+
draggable: drag !== void 0 && drag.draggable,
|
|
2049
|
+
onDragStart: drag?.onDragStart,
|
|
2050
|
+
onDragEnd: drag?.onDragEnd,
|
|
2051
|
+
onDragOver: drag?.onDragOver,
|
|
2052
|
+
onDrop: drag?.onDrop,
|
|
2053
|
+
children: children.filter(present)
|
|
2054
|
+
});
|
|
2055
|
+
}
|
|
2056
|
+
function HoverContainerRow(props) {
|
|
2057
|
+
const [hovered, setHovered] = (0, import_react.useState)(false);
|
|
2058
|
+
return jsx(ContainerRowView, {
|
|
2059
|
+
row: props.row,
|
|
2060
|
+
t: props.t,
|
|
2061
|
+
hovered,
|
|
2062
|
+
renderActions: props.renderActions,
|
|
2063
|
+
onToggle: props.onToggle,
|
|
2064
|
+
onHoverChange: setHovered,
|
|
2065
|
+
...props.onContextMenu === void 0 ? {} : { onContextMenu: props.onContextMenu },
|
|
2066
|
+
...props.drag === void 0 ? {} : { drag: props.drag }
|
|
2067
|
+
});
|
|
2068
|
+
}
|
|
2069
|
+
function SessionRowViewInner(props) {
|
|
2070
|
+
const row = props.row;
|
|
2071
|
+
const [hovered, setHovered] = (0, import_react.useState)(false);
|
|
2072
|
+
const drag = props.drag;
|
|
2073
|
+
const live = () => props.handlers.current.get(props.rowKey);
|
|
2074
|
+
const children = [
|
|
2075
|
+
row.isCurrent ? jsx("span", {
|
|
2076
|
+
key: "active-bar",
|
|
2077
|
+
"aria-hidden": true,
|
|
2078
|
+
style: {
|
|
2079
|
+
position: "absolute",
|
|
2080
|
+
left: 2,
|
|
2081
|
+
top: 5,
|
|
2082
|
+
bottom: 5,
|
|
2083
|
+
width: 3,
|
|
2084
|
+
borderRadius: 2,
|
|
2085
|
+
background: "var(--dsw-alias-state-business-primary, #4176e6)",
|
|
2086
|
+
pointerEvents: "none"
|
|
2087
|
+
}
|
|
2088
|
+
}) : null,
|
|
2089
|
+
jsx("span", {
|
|
2090
|
+
key: "dot",
|
|
2091
|
+
style: { display: "inline-flex", alignItems: "center", justifyContent: "center", width: 14, height: 14, flex: "none" },
|
|
2092
|
+
children: jsx(StatusDot, {
|
|
2093
|
+
running: row.running,
|
|
2094
|
+
pending: row.pendingInteraction !== void 0,
|
|
2095
|
+
completed: row.completed
|
|
2096
|
+
})
|
|
2097
|
+
}),
|
|
2098
|
+
jsx("span", {
|
|
2099
|
+
key: "label",
|
|
2100
|
+
style: { flex: 1, minWidth: 0, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", fontSize: 13, lineHeight: "18px" },
|
|
2101
|
+
children: row.label
|
|
2102
|
+
})
|
|
2103
|
+
];
|
|
2104
|
+
if (row.subagentCount > 0) {
|
|
2105
|
+
children.push(jsx("span", {
|
|
2106
|
+
key: "subs",
|
|
2107
|
+
title: props.t("a11y.subagents", { n: row.subagentCount }),
|
|
2108
|
+
style: { ...pillStyle(), fontSize: 11, lineHeight: "16px", padding: "0 6px", borderRadius: 8 },
|
|
2109
|
+
children: row.subagentCount
|
|
2110
|
+
}));
|
|
2111
|
+
}
|
|
2112
|
+
if (drag !== void 0 && drag.marker !== null) {
|
|
2113
|
+
children.push(jsx("span", {
|
|
2114
|
+
key: "drop-line",
|
|
2115
|
+
"aria-hidden": true,
|
|
2116
|
+
style: dragLineStyle(drag.marker, indentOf(row.depth))
|
|
2117
|
+
}));
|
|
2118
|
+
}
|
|
2119
|
+
return jsx("div", {
|
|
2120
|
+
role: "treeitem",
|
|
2121
|
+
"aria-current": row.isCurrent ? "true" : void 0,
|
|
2122
|
+
...row.isCurrent ? { "data-selected": "true" } : {},
|
|
2123
|
+
"data-session-id": row.sessionId,
|
|
2124
|
+
title: row.label,
|
|
2125
|
+
style: {
|
|
2126
|
+
...rowStyle(row.isCurrent, hovered, indentOf(row.depth)),
|
|
2127
|
+
position: "relative",
|
|
2128
|
+
...drag !== void 0 && drag.dragging ? { opacity: DRAGGING_OPACITY } : {}
|
|
2129
|
+
},
|
|
2130
|
+
onMouseEnter: () => {
|
|
2131
|
+
setHovered(true);
|
|
2132
|
+
},
|
|
2133
|
+
onMouseLeave: () => {
|
|
2134
|
+
setHovered(false);
|
|
2135
|
+
},
|
|
2136
|
+
onClick: () => {
|
|
2137
|
+
live()?.onOpen();
|
|
2138
|
+
},
|
|
2139
|
+
onContextMenu: (event) => {
|
|
2140
|
+
event.preventDefault();
|
|
2141
|
+
event.stopPropagation();
|
|
2142
|
+
live()?.onMenu({
|
|
2143
|
+
x: Math.round(Number(event.clientX) || 0),
|
|
2144
|
+
y: Math.round(Number(event.clientY) || 0),
|
|
2145
|
+
title: row.label,
|
|
2146
|
+
sessionId: row.sessionId
|
|
2147
|
+
});
|
|
2148
|
+
},
|
|
2149
|
+
draggable: drag !== void 0 && drag.draggable,
|
|
2150
|
+
...drag === void 0 ? {} : {
|
|
2151
|
+
onDragStart: (event) => {
|
|
2152
|
+
live()?.drag?.onDragStart(event);
|
|
2153
|
+
},
|
|
2154
|
+
onDragEnd: () => {
|
|
2155
|
+
live()?.drag?.onDragEnd();
|
|
2156
|
+
},
|
|
2157
|
+
onDragOver: (event) => {
|
|
2158
|
+
live()?.drag?.onDragOver(event);
|
|
2159
|
+
},
|
|
2160
|
+
onDrop: (event) => {
|
|
2161
|
+
live()?.drag?.onDrop(event);
|
|
2162
|
+
}
|
|
2163
|
+
},
|
|
2164
|
+
children: children.filter(present)
|
|
2165
|
+
});
|
|
2166
|
+
}
|
|
2167
|
+
var SessionRowView = (0, import_react.memo)(SessionRowViewInner, sessionRowPropsEqual);
|
|
2168
|
+
function RecentSectionHeaderView(props) {
|
|
2169
|
+
const [hovered, setHovered] = (0, import_react.useState)(false);
|
|
2170
|
+
const row = props.row;
|
|
2171
|
+
const chevron = row.expanded ? icon("chevronDown") : icon("chevronRight");
|
|
2172
|
+
return jsxs("div", {
|
|
2173
|
+
role: "treeitem",
|
|
2174
|
+
"aria-expanded": row.expanded,
|
|
2175
|
+
"data-key": row.key,
|
|
2176
|
+
style: {
|
|
2177
|
+
...rowStyle(false, hovered, indentOf(row.depth)),
|
|
2178
|
+
marginTop: 18,
|
|
2179
|
+
paddingTop: 6,
|
|
2180
|
+
borderTop: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,0.16))"
|
|
2181
|
+
},
|
|
2182
|
+
onMouseEnter: () => {
|
|
2183
|
+
setHovered(true);
|
|
2184
|
+
},
|
|
2185
|
+
onMouseLeave: () => {
|
|
2186
|
+
setHovered(false);
|
|
2187
|
+
},
|
|
2188
|
+
onClick: props.onToggle,
|
|
2189
|
+
children: [
|
|
2190
|
+
jsx("span", {
|
|
2191
|
+
key: "lead",
|
|
2192
|
+
style: { display: "inline-flex", alignItems: "center", flex: "none", lineHeight: 0, ...dimText(12) },
|
|
2193
|
+
children: icon("clock")
|
|
2194
|
+
}),
|
|
2195
|
+
jsx("span", {
|
|
2196
|
+
key: "chevron",
|
|
2197
|
+
style: { display: "inline-flex", alignItems: "center", flex: "none", lineHeight: 0, ...dimText(12) },
|
|
2198
|
+
children: chevron
|
|
2199
|
+
}),
|
|
2200
|
+
jsx("span", {
|
|
2201
|
+
key: "label",
|
|
2202
|
+
style: {
|
|
2203
|
+
flex: 1,
|
|
2204
|
+
minWidth: 0,
|
|
2205
|
+
overflow: "hidden",
|
|
2206
|
+
textOverflow: "ellipsis",
|
|
2207
|
+
whiteSpace: "nowrap",
|
|
2208
|
+
fontSize: 12.5,
|
|
2209
|
+
fontWeight: 600,
|
|
2210
|
+
color: "var(--dsw-alias-label-secondary, var(--dsw-alias-label-primary))"
|
|
2211
|
+
},
|
|
2212
|
+
children: row.label
|
|
2213
|
+
}),
|
|
2214
|
+
jsx("span", {
|
|
2215
|
+
key: "count",
|
|
2216
|
+
style: { flex: "none", ...dimText(11) },
|
|
2217
|
+
children: row.sessionCount
|
|
2218
|
+
})
|
|
2219
|
+
]
|
|
2220
|
+
});
|
|
2221
|
+
}
|
|
2222
|
+
function MoreRowView(props) {
|
|
2223
|
+
const [hovered, setHovered] = (0, import_react.useState)(null);
|
|
2224
|
+
const { row } = props;
|
|
2225
|
+
const button = (kind, label, onActivate, extra) => jsx("div", {
|
|
2226
|
+
key: kind,
|
|
2227
|
+
role: "button",
|
|
2228
|
+
tabIndex: 0,
|
|
2229
|
+
"data-more-action": kind,
|
|
2230
|
+
style: {
|
|
2231
|
+
...dimText(12),
|
|
2232
|
+
cursor: "pointer",
|
|
2233
|
+
borderRadius: 6,
|
|
2234
|
+
padding: "2px 6px",
|
|
2235
|
+
background: hovered === kind ? "var(--dsw-alias-fill-tertiary, rgba(127,127,127,0.12))" : "transparent",
|
|
2236
|
+
...extra
|
|
2237
|
+
},
|
|
2238
|
+
onMouseEnter: () => {
|
|
2239
|
+
setHovered(kind);
|
|
2240
|
+
},
|
|
2241
|
+
onMouseLeave: () => {
|
|
2242
|
+
setHovered(null);
|
|
2243
|
+
},
|
|
2244
|
+
onClick: (event) => {
|
|
2245
|
+
event?.stopPropagation?.();
|
|
2246
|
+
onActivate();
|
|
2247
|
+
},
|
|
2248
|
+
onKeyDown: (event) => {
|
|
2249
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
2250
|
+
event.preventDefault();
|
|
2251
|
+
onActivate();
|
|
2252
|
+
}
|
|
2253
|
+
},
|
|
2254
|
+
children: label
|
|
2255
|
+
});
|
|
2256
|
+
const children = [];
|
|
2257
|
+
if (row.hiddenCount > 0) {
|
|
2258
|
+
children.push(button("expand", props.t("sessions.expandMore", { n: row.nextCount }), props.onExpand, {}));
|
|
2259
|
+
}
|
|
2260
|
+
if (row.canCollapse) {
|
|
2261
|
+
children.push(button("collapse", props.t("sessions.collapse"), props.onCollapse, { marginLeft: "auto" }));
|
|
2262
|
+
}
|
|
2263
|
+
return jsxs("div", {
|
|
2264
|
+
style: {
|
|
2265
|
+
...rowStyle(false, false, indentOf(row.depth)),
|
|
2266
|
+
display: "flex",
|
|
2267
|
+
alignItems: "center",
|
|
2268
|
+
gap: 4
|
|
2269
|
+
},
|
|
2270
|
+
children
|
|
2271
|
+
});
|
|
2272
|
+
}
|
|
2273
|
+
function FieldRow(props) {
|
|
2274
|
+
return jsxs("label", {
|
|
2275
|
+
style: { display: "flex", flexDirection: "column", gap: 4, fontSize: 12.5 },
|
|
2276
|
+
children: [
|
|
2277
|
+
jsx("span", { key: "label", style: dimText(12), children: props.label }),
|
|
2278
|
+
props.children
|
|
2279
|
+
]
|
|
2280
|
+
});
|
|
2281
|
+
}
|
|
2282
|
+
function RadioOption(props) {
|
|
2283
|
+
return jsxs("label", {
|
|
2284
|
+
htmlFor: props.id,
|
|
2285
|
+
style: { display: "inline-flex", alignItems: "center", gap: 6, fontSize: 13, cursor: "pointer" },
|
|
2286
|
+
children: [
|
|
2287
|
+
jsx("input", {
|
|
2288
|
+
id: props.id,
|
|
2289
|
+
type: "radio",
|
|
2290
|
+
checked: props.checked,
|
|
2291
|
+
onChange: props.onSelect,
|
|
2292
|
+
style: { accentColor: "var(--dsw-alias-brand-primary)", width: 14, height: 14, margin: 0, cursor: "pointer" }
|
|
2293
|
+
}),
|
|
2294
|
+
props.label
|
|
2295
|
+
]
|
|
2296
|
+
});
|
|
2297
|
+
}
|
|
2298
|
+
function DialogActions(props) {
|
|
2299
|
+
return jsxs("div", {
|
|
2300
|
+
style: { display: "flex", justifyContent: "flex-end", gap: 8 },
|
|
2301
|
+
children: [
|
|
2302
|
+
jsx(P.Button, {
|
|
2303
|
+
key: "cancel",
|
|
2304
|
+
variant: "outline",
|
|
2305
|
+
size: "sm",
|
|
2306
|
+
disabled: props.busy,
|
|
2307
|
+
onClick: props.onCancel,
|
|
2308
|
+
children: props.t("dialog.cancel")
|
|
2309
|
+
}),
|
|
2310
|
+
jsx(P.Button, {
|
|
2311
|
+
key: "confirm",
|
|
2312
|
+
variant: "primary",
|
|
2313
|
+
size: "sm",
|
|
2314
|
+
disabled: props.busy || props.disabled === true,
|
|
2315
|
+
onClick: props.onConfirm,
|
|
2316
|
+
children: props.confirmText
|
|
2317
|
+
})
|
|
2318
|
+
]
|
|
2319
|
+
});
|
|
2320
|
+
}
|
|
2321
|
+
function RenameDialog(props) {
|
|
2322
|
+
const [draft, setDraft] = (0, import_react.useState)("");
|
|
2323
|
+
const inputRef = (0, import_react.useRef)(null);
|
|
2324
|
+
const state = props.state;
|
|
2325
|
+
(0, import_react.useEffect)(() => {
|
|
2326
|
+
if (state === null) return;
|
|
2327
|
+
setDraft(state.value);
|
|
2328
|
+
inputRef.current?.focus();
|
|
2329
|
+
}, [state]);
|
|
2330
|
+
if (state === null) return null;
|
|
2331
|
+
const title = state.kind === "session" ? props.t("dialog.renameSession") : props.t("dialog.renameWorkspace");
|
|
2332
|
+
const submit = () => {
|
|
2333
|
+
const value = draft.trim();
|
|
2334
|
+
if (value === "") return;
|
|
2335
|
+
props.onSubmit(value);
|
|
2336
|
+
};
|
|
2337
|
+
return jsx(P.Modal, {
|
|
2338
|
+
open: true,
|
|
2339
|
+
onClose: props.onClose,
|
|
2340
|
+
title,
|
|
2341
|
+
closeLabel: props.t("dialog.cancel"),
|
|
2342
|
+
children: jsxs("div", {
|
|
2343
|
+
style: { display: "flex", flexDirection: "column", gap: 10, minWidth: 320 },
|
|
2344
|
+
children: [
|
|
2345
|
+
jsx("input", {
|
|
2346
|
+
key: "input",
|
|
2347
|
+
ref: inputRef,
|
|
2348
|
+
value: draft,
|
|
2349
|
+
"aria-label": title,
|
|
2350
|
+
onChange: (event) => {
|
|
2351
|
+
setDraft(String(event?.target?.value ?? ""));
|
|
2352
|
+
},
|
|
2353
|
+
onKeyDown: (event) => {
|
|
2354
|
+
if (event.key === "Enter") submit();
|
|
2355
|
+
},
|
|
2356
|
+
style: { ...fieldStyle(), fontSize: 14 }
|
|
2357
|
+
}),
|
|
2358
|
+
jsx(DialogActions, {
|
|
2359
|
+
key: "actions",
|
|
2360
|
+
t: props.t,
|
|
2361
|
+
busy: false,
|
|
2362
|
+
confirmText: props.t("dialog.confirm"),
|
|
2363
|
+
disabled: draft.trim() === "",
|
|
2364
|
+
onCancel: props.onClose,
|
|
2365
|
+
onConfirm: submit
|
|
2366
|
+
})
|
|
2367
|
+
]
|
|
2368
|
+
})
|
|
2369
|
+
});
|
|
2370
|
+
}
|
|
2371
|
+
function AddWorkspaceDialog(props) {
|
|
2372
|
+
const [draft, setDraft] = (0, import_react.useState)("");
|
|
2373
|
+
const [busy, setBusy] = (0, import_react.useState)(false);
|
|
2374
|
+
const [error, setError] = (0, import_react.useState)(null);
|
|
2375
|
+
const inputRef = (0, import_react.useRef)(null);
|
|
2376
|
+
(0, import_react.useEffect)(() => {
|
|
2377
|
+
if (!props.open) return;
|
|
2378
|
+
setDraft("");
|
|
2379
|
+
setBusy(false);
|
|
2380
|
+
setError(null);
|
|
2381
|
+
inputRef.current?.focus();
|
|
2382
|
+
}, [props.open]);
|
|
2383
|
+
if (!props.open) return null;
|
|
2384
|
+
const title = props.t("project.add");
|
|
2385
|
+
const submit = () => {
|
|
2386
|
+
const path = draft.trim();
|
|
2387
|
+
if (path === "" || busy) return;
|
|
2388
|
+
setBusy(true);
|
|
2389
|
+
setError(null);
|
|
2390
|
+
void (async () => {
|
|
2391
|
+
try {
|
|
2392
|
+
await props.createWorkspace(path);
|
|
2393
|
+
props.onCreated();
|
|
2394
|
+
} catch (cause) {
|
|
2395
|
+
setError(cause instanceof Error ? cause.message : String(cause ?? ""));
|
|
2396
|
+
} finally {
|
|
2397
|
+
setBusy(false);
|
|
2398
|
+
}
|
|
2399
|
+
})();
|
|
2400
|
+
};
|
|
2401
|
+
return jsx(P.Modal, {
|
|
2402
|
+
open: true,
|
|
2403
|
+
onClose: props.onClose,
|
|
2404
|
+
title,
|
|
2405
|
+
closeLabel: props.t("dialog.cancel"),
|
|
2406
|
+
children: jsxs("div", {
|
|
2407
|
+
style: { display: "flex", flexDirection: "column", gap: 10, minWidth: 360 },
|
|
2408
|
+
children: [
|
|
2409
|
+
jsx("input", {
|
|
2410
|
+
key: "path",
|
|
2411
|
+
ref: inputRef,
|
|
2412
|
+
value: draft,
|
|
2413
|
+
"aria-label": props.t("worktree.path"),
|
|
2414
|
+
placeholder: "/absolute/path/to/workspace",
|
|
2415
|
+
onChange: (event) => {
|
|
2416
|
+
setDraft(String(event?.target?.value ?? ""));
|
|
2417
|
+
},
|
|
2418
|
+
onKeyDown: (event) => {
|
|
2419
|
+
if (event.key === "Enter") submit();
|
|
2420
|
+
},
|
|
2421
|
+
style: { ...fieldStyle(), fontSize: 13.5 }
|
|
2422
|
+
}),
|
|
2423
|
+
error === null ? null : jsx("div", {
|
|
2424
|
+
key: "error",
|
|
2425
|
+
style: {
|
|
2426
|
+
fontSize: 12.5,
|
|
2427
|
+
color: "var(--dsw-alias-state-error-primary, #d9534f)",
|
|
2428
|
+
wordBreak: "break-all"
|
|
2429
|
+
},
|
|
2430
|
+
children: error
|
|
2431
|
+
}),
|
|
2432
|
+
jsx(DialogActions, {
|
|
2433
|
+
key: "actions",
|
|
2434
|
+
t: props.t,
|
|
2435
|
+
busy,
|
|
2436
|
+
confirmText: props.t("dialog.confirm"),
|
|
2437
|
+
disabled: draft.trim() === "",
|
|
2438
|
+
onCancel: props.onClose,
|
|
2439
|
+
onConfirm: submit
|
|
2440
|
+
})
|
|
2441
|
+
].filter(present)
|
|
2442
|
+
})
|
|
2443
|
+
});
|
|
2444
|
+
}
|
|
2445
|
+
function CreateWorktreeDialog(props) {
|
|
2446
|
+
const [branch, setBranch] = (0, import_react.useState)("");
|
|
2447
|
+
const [createBranch, setCreateBranch] = (0, import_react.useState)(true);
|
|
2448
|
+
const [baseRef, setBaseRef] = (0, import_react.useState)("");
|
|
2449
|
+
const [busy, setBusy] = (0, import_react.useState)(false);
|
|
2450
|
+
const state = props.state;
|
|
2451
|
+
const stateKey = state === null ? "" : `${state.repoPath}\0${state.label}`;
|
|
2452
|
+
(0, import_react.useEffect)(() => {
|
|
2453
|
+
if (state === null) return;
|
|
2454
|
+
setBranch("");
|
|
2455
|
+
setCreateBranch(true);
|
|
2456
|
+
setBaseRef(state.baseCandidates[0] ?? "");
|
|
2457
|
+
setBusy(false);
|
|
2458
|
+
}, [stateKey, state]);
|
|
2459
|
+
if (state === null) return null;
|
|
2460
|
+
const t = props.t;
|
|
2461
|
+
const repoPath = state.repoPath;
|
|
2462
|
+
const trimmed = branch.trim();
|
|
2463
|
+
const sanitized = trimmed.replace(/[/\\]+/g, "-").replace(/\s+/g, "-");
|
|
2464
|
+
const preview = `${parentDirOf(repoPath)}/${baseName(repoPath)}-${sanitized !== "" ? sanitized : "<\u5206\u652F\u540D>"}`;
|
|
2465
|
+
const canSubmit = !busy && sanitized !== "";
|
|
2466
|
+
return jsx(P.Modal, {
|
|
2467
|
+
open: true,
|
|
2468
|
+
onClose: props.onClose,
|
|
2469
|
+
title: t("worktree.createTitle", { name: state.label }),
|
|
2470
|
+
closeLabel: t("worktree.cancel"),
|
|
2471
|
+
children: jsxs("div", {
|
|
2472
|
+
style: { display: "flex", flexDirection: "column", gap: 12, minWidth: 380 },
|
|
2473
|
+
children: [
|
|
2474
|
+
jsx(FieldRow, {
|
|
2475
|
+
key: "branch",
|
|
2476
|
+
label: t("worktree.branchName"),
|
|
2477
|
+
children: jsx("input", {
|
|
2478
|
+
value: branch,
|
|
2479
|
+
"aria-label": t("worktree.branchName"),
|
|
2480
|
+
placeholder: "feature/demo",
|
|
2481
|
+
onChange: (event) => {
|
|
2482
|
+
setBranch(String(event?.target?.value ?? ""));
|
|
2483
|
+
},
|
|
2484
|
+
style: fieldStyle()
|
|
2485
|
+
})
|
|
2486
|
+
}),
|
|
2487
|
+
jsx(FieldRow, {
|
|
2488
|
+
key: "mode",
|
|
2489
|
+
label: t("worktree.newBranch"),
|
|
2490
|
+
children: jsxs("div", {
|
|
2491
|
+
style: { display: "flex", gap: 14 },
|
|
2492
|
+
children: [
|
|
2493
|
+
jsx(RadioOption, {
|
|
2494
|
+
key: "new",
|
|
2495
|
+
id: "wtg-new-branch",
|
|
2496
|
+
label: t("worktree.newBranch"),
|
|
2497
|
+
checked: createBranch,
|
|
2498
|
+
onSelect: () => {
|
|
2499
|
+
setCreateBranch(true);
|
|
2500
|
+
}
|
|
2501
|
+
}),
|
|
2502
|
+
jsx(RadioOption, {
|
|
2503
|
+
key: "reuse",
|
|
2504
|
+
id: "wtg-use-branch",
|
|
2505
|
+
label: t("worktree.useExisting"),
|
|
2506
|
+
checked: !createBranch,
|
|
2507
|
+
onSelect: () => {
|
|
2508
|
+
setCreateBranch(false);
|
|
2509
|
+
}
|
|
2510
|
+
})
|
|
2511
|
+
]
|
|
2512
|
+
})
|
|
2513
|
+
}),
|
|
2514
|
+
createBranch && state.baseCandidates.length > 0 ? jsx(FieldRow, {
|
|
2515
|
+
key: "base",
|
|
2516
|
+
label: t("worktree.baseBranch"),
|
|
2517
|
+
children: jsx("select", {
|
|
2518
|
+
value: baseRef,
|
|
2519
|
+
"aria-label": t("worktree.baseBranch"),
|
|
2520
|
+
onChange: (event) => {
|
|
2521
|
+
setBaseRef(String(event?.target?.value ?? ""));
|
|
2522
|
+
},
|
|
2523
|
+
style: { ...fieldStyle(), padding: "0 8px" },
|
|
2524
|
+
children: state.baseCandidates.map(
|
|
2525
|
+
(candidate) => jsx("option", { key: candidate, value: candidate, children: candidate })
|
|
2526
|
+
)
|
|
2527
|
+
})
|
|
2528
|
+
}) : null,
|
|
2529
|
+
jsx(FieldRow, {
|
|
2530
|
+
key: "path",
|
|
2531
|
+
label: t("worktree.path"),
|
|
2532
|
+
children: jsx("code", {
|
|
2533
|
+
style: {
|
|
2534
|
+
display: "block",
|
|
2535
|
+
padding: "6px 10px",
|
|
2536
|
+
borderRadius: 8,
|
|
2537
|
+
background: "var(--dsw-alias-bg-multi-select, rgba(127,127,127,0.08))",
|
|
2538
|
+
color: "var(--dsw-alias-label-secondary, var(--dsw-alias-label-primary))",
|
|
2539
|
+
fontSize: 12,
|
|
2540
|
+
wordBreak: "break-all"
|
|
2541
|
+
},
|
|
2542
|
+
children: preview
|
|
2543
|
+
})
|
|
2544
|
+
}),
|
|
2545
|
+
jsx("div", { key: "hint", style: dimText(11.5), children: t("worktree.pathHint") }),
|
|
2546
|
+
jsx(DialogActions, {
|
|
2547
|
+
key: "actions",
|
|
2548
|
+
t,
|
|
2549
|
+
busy,
|
|
2550
|
+
confirmText: busy ? t("worktree.creating") : t("worktree.confirm"),
|
|
2551
|
+
disabled: !canSubmit,
|
|
2552
|
+
onCancel: props.onClose,
|
|
2553
|
+
onConfirm: () => {
|
|
2554
|
+
setBusy(true);
|
|
2555
|
+
props.onBusy(t("worktree.creating"));
|
|
2556
|
+
void (async () => {
|
|
2557
|
+
try {
|
|
2558
|
+
const body = await props.post(ROUTE_WORKTREE_CREATE, {
|
|
2559
|
+
repoPath,
|
|
2560
|
+
branch: trimmed,
|
|
2561
|
+
createBranch,
|
|
2562
|
+
...createBranch && baseRef !== "" ? { baseRef } : {}
|
|
2563
|
+
});
|
|
2564
|
+
if (body?.ok !== true) {
|
|
2565
|
+
throw new Error(typeof body?.message === "string" ? body.message : t("error.load"));
|
|
2566
|
+
}
|
|
2567
|
+
props.onClose();
|
|
2568
|
+
if (typeof body.workspaceWarning === "string" && body.workspaceWarning !== "") {
|
|
2569
|
+
props.onWarning(t("worktree.workspaceWarning", { message: body.workspaceWarning }));
|
|
2570
|
+
} else {
|
|
2571
|
+
props.onWarning(null);
|
|
2572
|
+
}
|
|
2573
|
+
props.onCreated(
|
|
2574
|
+
typeof body.worktreePath === "string" ? body.worktreePath : void 0,
|
|
2575
|
+
typeof body.workspaceId === "string" ? body.workspaceId : void 0
|
|
2576
|
+
);
|
|
2577
|
+
} catch (error) {
|
|
2578
|
+
props.onError(error instanceof Error ? error.message : t("error.load"));
|
|
2579
|
+
} finally {
|
|
2580
|
+
setBusy(false);
|
|
2581
|
+
props.onBusy(null);
|
|
2582
|
+
}
|
|
2583
|
+
})();
|
|
2584
|
+
}
|
|
2585
|
+
})
|
|
2586
|
+
].filter(present)
|
|
2587
|
+
})
|
|
2588
|
+
});
|
|
2589
|
+
}
|
|
2590
|
+
function RemoveWorktreeDialog(props) {
|
|
2591
|
+
const [needsForce, setNeedsForce] = (0, import_react.useState)(false);
|
|
2592
|
+
const [busy, setBusy] = (0, import_react.useState)(false);
|
|
2593
|
+
const target = props.target;
|
|
2594
|
+
const targetPath = target?.path ?? "";
|
|
2595
|
+
(0, import_react.useEffect)(() => {
|
|
2596
|
+
setNeedsForce(false);
|
|
2597
|
+
setBusy(false);
|
|
2598
|
+
}, [targetPath]);
|
|
2599
|
+
if (target === null) return null;
|
|
2600
|
+
const t = props.t;
|
|
2601
|
+
const run = (force) => {
|
|
2602
|
+
setBusy(true);
|
|
2603
|
+
props.onBusy(t("worktree.removing"));
|
|
2604
|
+
void (async () => {
|
|
2605
|
+
try {
|
|
2606
|
+
const body = await props.post(ROUTE_WORKTREE_REMOVE, {
|
|
2607
|
+
path: target.path,
|
|
2608
|
+
...force ? { force: true } : {}
|
|
2609
|
+
});
|
|
2610
|
+
if (body?.ok === true) {
|
|
2611
|
+
props.onClose();
|
|
2612
|
+
props.onRemoved();
|
|
2613
|
+
return;
|
|
2614
|
+
}
|
|
2615
|
+
if (body?.needsForce === true) {
|
|
2616
|
+
setNeedsForce(true);
|
|
2617
|
+
return;
|
|
2618
|
+
}
|
|
2619
|
+
throw new Error(typeof body?.message === "string" ? body.message : t("error.load"));
|
|
2620
|
+
} catch (error) {
|
|
2621
|
+
props.onError(error instanceof Error ? error.message : t("error.load"));
|
|
2622
|
+
} finally {
|
|
2623
|
+
setBusy(false);
|
|
2624
|
+
props.onBusy(null);
|
|
2625
|
+
}
|
|
2626
|
+
})();
|
|
2627
|
+
};
|
|
2628
|
+
return jsx(P.Modal, {
|
|
2629
|
+
open: true,
|
|
2630
|
+
onClose: props.onClose,
|
|
2631
|
+
title: t("worktree.remove"),
|
|
2632
|
+
closeLabel: t("dialog.cancel"),
|
|
2633
|
+
children: jsxs("div", {
|
|
2634
|
+
style: { display: "flex", flexDirection: "column", gap: 10, minWidth: 340 },
|
|
2635
|
+
children: [
|
|
2636
|
+
jsx("div", {
|
|
2637
|
+
key: "confirm",
|
|
2638
|
+
style: { fontSize: 13 },
|
|
2639
|
+
children: t("worktree.removeConfirm", { name: target.label })
|
|
2640
|
+
}),
|
|
2641
|
+
jsx("div", { key: "path", style: { ...dimText(12), wordBreak: "break-all" }, children: target.path }),
|
|
2642
|
+
jsx("div", { key: "keep", style: dimText(12), children: t("worktree.removeKeepBranch") }),
|
|
2643
|
+
needsForce ? jsxs("div", {
|
|
2644
|
+
key: "force",
|
|
2645
|
+
style: {
|
|
2646
|
+
display: "flex",
|
|
2647
|
+
flexDirection: "column",
|
|
2648
|
+
gap: 4,
|
|
2649
|
+
padding: "8px 10px",
|
|
2650
|
+
borderRadius: 8,
|
|
2651
|
+
border: "1px solid var(--dsw-alias-state-warn-primary, #d19a2f)"
|
|
2652
|
+
},
|
|
2653
|
+
children: [
|
|
2654
|
+
jsx("span", {
|
|
2655
|
+
key: "dirty",
|
|
2656
|
+
style: { fontSize: 12.5, color: "var(--dsw-alias-state-warn-primary, #d19a2f)" },
|
|
2657
|
+
children: t("worktree.dirty")
|
|
2658
|
+
}),
|
|
2659
|
+
jsx("span", { key: "loss", style: dimText(12), children: t("worktree.forceRemove") })
|
|
2660
|
+
]
|
|
2661
|
+
}) : null,
|
|
2662
|
+
jsx(DialogActions, {
|
|
2663
|
+
key: "actions",
|
|
2664
|
+
t,
|
|
2665
|
+
busy,
|
|
2666
|
+
confirmText: needsForce ? t("worktree.forceRemove") : t("dialog.confirm"),
|
|
2667
|
+
onCancel: props.onClose,
|
|
2668
|
+
onConfirm: () => {
|
|
2669
|
+
run(needsForce);
|
|
2670
|
+
}
|
|
2671
|
+
})
|
|
2672
|
+
].filter(present)
|
|
2673
|
+
})
|
|
2674
|
+
});
|
|
2675
|
+
}
|
|
2676
|
+
var SidebarBoundary = class extends import_react.Component {
|
|
2677
|
+
/** 当前捕获的错误;`null` = 正常渲染。 */
|
|
2678
|
+
state = { error: null };
|
|
2679
|
+
/** 捕获子树异常并切到错误 UI —— 不让它逃到宿主 `SlotErrorBoundary`。 */
|
|
2680
|
+
static getDerivedStateFromError(error) {
|
|
2681
|
+
return { error };
|
|
2682
|
+
}
|
|
2683
|
+
/** 打到控制台,便于在宿主日志里定位根因。 */
|
|
2684
|
+
componentDidCatch(error) {
|
|
2685
|
+
console.error("[dsh-worktree-groups] sidebar render failed:", error);
|
|
2686
|
+
}
|
|
2687
|
+
/** 渲染子树,或"可读错误 + 重试"。 */
|
|
2688
|
+
render() {
|
|
2689
|
+
if (this.state.error === null) return this.props.children ?? null;
|
|
2690
|
+
const detail = this.state.error instanceof Error ? this.state.error.message : String(this.state.error);
|
|
2691
|
+
return jsxs("div", {
|
|
2692
|
+
style: { padding: 12, display: "flex", flexDirection: "column", gap: 8, color: "var(--dsw-alias-label-primary)" },
|
|
2693
|
+
children: [
|
|
2694
|
+
jsx("div", { key: "title", style: { fontSize: 13, fontWeight: 600 }, children: FALLBACK_T("error.title") }),
|
|
2695
|
+
jsx("div", { key: "detail", style: { fontSize: 12, opacity: 0.8, wordBreak: "break-all" }, children: detail }),
|
|
2696
|
+
jsx("button", {
|
|
2697
|
+
key: "retry",
|
|
2698
|
+
type: "button",
|
|
2699
|
+
onClick: () => {
|
|
2700
|
+
this.setState({ error: null });
|
|
2701
|
+
},
|
|
2702
|
+
style: {
|
|
2703
|
+
alignSelf: "flex-start",
|
|
2704
|
+
padding: "3px 12px",
|
|
2705
|
+
border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,0.3))",
|
|
2706
|
+
borderRadius: 12,
|
|
2707
|
+
background: "transparent",
|
|
2708
|
+
color: "inherit",
|
|
2709
|
+
fontFamily: "inherit",
|
|
2710
|
+
fontSize: 12,
|
|
2711
|
+
cursor: "pointer"
|
|
2712
|
+
},
|
|
2713
|
+
children: FALLBACK_T("error.retry")
|
|
2714
|
+
})
|
|
2715
|
+
]
|
|
2716
|
+
});
|
|
2717
|
+
}
|
|
2718
|
+
};
|
|
2719
|
+
function SidebarBrowser(props) {
|
|
2720
|
+
return jsx(SidebarBoundary, { children: jsx(SidebarBrowserInner, props) });
|
|
2721
|
+
}
|
|
2722
|
+
function asHook(candidate) {
|
|
2723
|
+
return typeof candidate === "function" ? candidate : directSource;
|
|
2724
|
+
}
|
|
2725
|
+
function directSource(selector) {
|
|
2726
|
+
return selector(void 0);
|
|
2727
|
+
}
|
|
2728
|
+
function identity(value) {
|
|
2729
|
+
return value;
|
|
2730
|
+
}
|
|
2731
|
+
function SidebarBrowserInner(props) {
|
|
2732
|
+
const seat = props.t;
|
|
2733
|
+
const t = typeof seat === "function" ? createSeatT(seat) : FALLBACK_T;
|
|
2734
|
+
const bridge = props.bridge;
|
|
2735
|
+
const wide = readBoolean(props, "wide");
|
|
2736
|
+
const expandSidebar = readFunction(props, "expandSidebar");
|
|
2737
|
+
const renderSlot = readFunction(props, "renderSlot");
|
|
2738
|
+
const sourcesRef = (0, import_react.useRef)(null);
|
|
2739
|
+
if (sourcesRef.current === null) {
|
|
2740
|
+
sourcesRef.current = {
|
|
2741
|
+
sessions: asHook(props.useSessions),
|
|
2742
|
+
workspaces: asHook(props.useWorkspaces),
|
|
2743
|
+
status: asHook(props.useSessionStatus),
|
|
2744
|
+
pending: asHook(props.useSessionPendingInteraction),
|
|
2745
|
+
panelInfo: asHook(props.usePanelInfo)
|
|
2746
|
+
};
|
|
2747
|
+
}
|
|
2748
|
+
const sources = sourcesRef.current;
|
|
2749
|
+
const sessionsSnapshot = sources.sessions(identity);
|
|
2750
|
+
sources.workspaces(identity);
|
|
2751
|
+
const sessionStatus = sources.status(identity);
|
|
2752
|
+
const runningSignatureValue = runningSignature(sessionStatus);
|
|
2753
|
+
const pendingInteractions = sources.pending(identity);
|
|
2754
|
+
const panelInfoSnapshot = sources.panelInfo(identity);
|
|
2755
|
+
const [optimisticSessionId, setOptimisticSessionId] = (0, import_react.useState)(void 0);
|
|
2756
|
+
const currentSessionId = currentSessionIdOf({
|
|
2757
|
+
sessions: sessionsSnapshot,
|
|
2758
|
+
panelInfo: panelInfoSnapshot,
|
|
2759
|
+
optimisticSessionId
|
|
2760
|
+
});
|
|
2761
|
+
const [collapsedKeys, setCollapsedKeys] = (0, import_react.useState)(() => readFlagMap(LS_COLLAPSED));
|
|
2762
|
+
const [expandLevels, setExpandLevels] = (0, import_react.useState)(() => readLevelMap(LS_EXPAND_LEVELS));
|
|
2763
|
+
const [archivedMap, setArchivedMap] = (0, import_react.useState)(() => readArchivedProjectsMap());
|
|
2764
|
+
const [query, setQuery] = (0, import_react.useState)("");
|
|
2765
|
+
const [manualOrder, setManualOrder] = (0, import_react.useState)(() => readManualOrder());
|
|
2766
|
+
const [topZoneState, setTopZoneState] = (0, import_react.useState)(initialTopZoneState);
|
|
2767
|
+
const [drag, setDrag] = (0, import_react.useState)(null);
|
|
2768
|
+
const sessionHandlersRef = (0, import_react.useRef)(/* @__PURE__ */ new Map());
|
|
2769
|
+
const [dropTarget, setDropTarget] = (0, import_react.useState)(null);
|
|
2770
|
+
const [serverTree, setTree] = (0, import_react.useState)(null);
|
|
2771
|
+
const merged = (0, import_react.useMemo)(
|
|
2772
|
+
() => serverTree === null ? null : mergeLiveSessions(serverTree, sessionsSnapshot),
|
|
2773
|
+
[serverTree, sessionsSnapshot]
|
|
2774
|
+
);
|
|
2775
|
+
const tree = merged === null ? null : merged.tree;
|
|
2776
|
+
const pendingLiveSignature = merged === null ? "" : merged.pendingIds.join(",");
|
|
2777
|
+
const [loadError, setLoadError] = (0, import_react.useState)(null);
|
|
2778
|
+
const [busyText, setBusyText] = (0, import_react.useState)(null);
|
|
2779
|
+
const [notice, setNotice] = (0, import_react.useState)(null);
|
|
2780
|
+
const [menuTarget, setMenuTarget] = (0, import_react.useState)(null);
|
|
2781
|
+
const [renameState, setRenameState] = (0, import_react.useState)(null);
|
|
2782
|
+
const [createState, setCreateState] = (0, import_react.useState)(null);
|
|
2783
|
+
const [removeTarget, setRemoveTarget] = (0, import_react.useState)(null);
|
|
2784
|
+
const [addWorkspaceOpen, setAddWorkspaceOpen] = (0, import_react.useState)(false);
|
|
2785
|
+
const inflightRef = (0, import_react.useRef)(null);
|
|
2786
|
+
const trailingRef = (0, import_react.useRef)(false);
|
|
2787
|
+
const etagRef = (0, import_react.useRef)(null);
|
|
2788
|
+
const reload = (0, import_react.useCallback)(() => {
|
|
2789
|
+
if (typeof document !== "undefined" && document.visibilityState === "hidden") return;
|
|
2790
|
+
if (inflightRef.current !== null) {
|
|
2791
|
+
trailingRef.current = true;
|
|
2792
|
+
return;
|
|
2793
|
+
}
|
|
2794
|
+
const controller = new AbortController();
|
|
2795
|
+
inflightRef.current = controller;
|
|
2796
|
+
const headers = { "content-type": "application/json" };
|
|
2797
|
+
if (etagRef.current !== null) headers["if-none-match"] = etagRef.current;
|
|
2798
|
+
const finish = () => {
|
|
2799
|
+
if (inflightRef.current !== controller) return;
|
|
2800
|
+
inflightRef.current = null;
|
|
2801
|
+
if (trailingRef.current && !controller.signal.aborted) {
|
|
2802
|
+
trailingRef.current = false;
|
|
2803
|
+
reloadRef.current();
|
|
2804
|
+
}
|
|
2805
|
+
};
|
|
2806
|
+
void fetch(ROUTE_TREE, {
|
|
2807
|
+
method: "POST",
|
|
2808
|
+
headers,
|
|
2809
|
+
body: "{}",
|
|
2810
|
+
signal: controller.signal
|
|
2811
|
+
}).then(async (response) => {
|
|
2812
|
+
if (response.status === 304) return void 0;
|
|
2813
|
+
const etag = response.headers?.get?.("etag");
|
|
2814
|
+
const body2 = await response.json();
|
|
2815
|
+
if (body2?.ok === true) etagRef.current = typeof etag === "string" && etag !== "" ? etag : null;
|
|
2816
|
+
return body2;
|
|
2817
|
+
}).then((body2) => {
|
|
2818
|
+
if (controller.signal.aborted) return;
|
|
2819
|
+
if (body2 === void 0) {
|
|
2820
|
+
setLoadError(null);
|
|
2821
|
+
return;
|
|
2822
|
+
}
|
|
2823
|
+
if (body2?.ok !== true) {
|
|
2824
|
+
throw new Error(typeof body2?.message === "string" ? body2.message : t("error.load"));
|
|
2825
|
+
}
|
|
2826
|
+
const projects = Array.isArray(body2.projects) ? body2.projects : [];
|
|
2827
|
+
latestKnownProjects = projects;
|
|
2828
|
+
setTree({
|
|
2829
|
+
projects,
|
|
2830
|
+
ungrouped: Array.isArray(body2.ungrouped) ? body2.ungrouped : [],
|
|
2831
|
+
archivedSessionIds: Array.isArray(body2.archivedSessionIds) ? body2.archivedSessionIds : [],
|
|
2832
|
+
...Array.isArray(body2.archivedProjects) ? { archivedProjects: body2.archivedProjects } : {},
|
|
2833
|
+
...typeof body2.workspaceByPath === "object" && body2.workspaceByPath !== null ? { workspaceByPath: body2.workspaceByPath } : {}
|
|
2834
|
+
});
|
|
2835
|
+
setLoadError(null);
|
|
2836
|
+
}).catch((error) => {
|
|
2837
|
+
if (controller.signal.aborted) return;
|
|
2838
|
+
etagRef.current = null;
|
|
2839
|
+
setLoadError(error instanceof Error ? error.message : t("error.load"));
|
|
2840
|
+
}).finally(finish);
|
|
2841
|
+
}, [t]);
|
|
2842
|
+
const reloadRef = (0, import_react.useRef)(reload);
|
|
2843
|
+
reloadRef.current = reload;
|
|
2844
|
+
(0, import_react.useEffect)(() => {
|
|
2845
|
+
const timer = setTimeout(reload, RELOAD_DEBOUNCE_MS);
|
|
2846
|
+
return () => {
|
|
2847
|
+
clearTimeout(timer);
|
|
2848
|
+
};
|
|
2849
|
+
}, [reload, pendingLiveSignature, currentSessionId, runningSignatureValue]);
|
|
2850
|
+
(0, import_react.useEffect)(() => {
|
|
2851
|
+
reload();
|
|
2852
|
+
const interval = setInterval(reload, TREE_REFRESH_MS);
|
|
2853
|
+
const onFocus = () => {
|
|
2854
|
+
setArchivedMap(readArchivedProjectsMap());
|
|
2855
|
+
reload();
|
|
2856
|
+
};
|
|
2857
|
+
const onVisibility = () => {
|
|
2858
|
+
if (document.visibilityState === "visible") reload();
|
|
2859
|
+
};
|
|
2860
|
+
window.addEventListener("focus", onFocus);
|
|
2861
|
+
document.addEventListener("visibilitychange", onVisibility);
|
|
2862
|
+
archiveListeners.add(onFocus);
|
|
2863
|
+
return () => {
|
|
2864
|
+
clearInterval(interval);
|
|
2865
|
+
window.removeEventListener("focus", onFocus);
|
|
2866
|
+
document.removeEventListener("visibilitychange", onVisibility);
|
|
2867
|
+
archiveListeners.delete(onFocus);
|
|
2868
|
+
inflightRef.current?.abort();
|
|
2869
|
+
inflightRef.current = null;
|
|
2870
|
+
};
|
|
2871
|
+
}, [reload]);
|
|
2872
|
+
const actions = (0, import_react.useMemo)(() => ({
|
|
2873
|
+
openSession: (sessionId) => {
|
|
2874
|
+
const open = readFunction(props, "open");
|
|
2875
|
+
if (open !== void 0) {
|
|
2876
|
+
open(sessionId);
|
|
2877
|
+
return;
|
|
2878
|
+
}
|
|
2879
|
+
bridge?.openSession(sessionId);
|
|
2880
|
+
},
|
|
2881
|
+
// 2026-10-22 DR1:`options` 必须两条路径都原样转发 —— 宿主 props(若某个组合注入了
|
|
2882
|
+
// `startSession`)与 bridge 都只认「第二参非 undefined 才复用空白会话」的语义。
|
|
2883
|
+
startSession: (workspaceId, options) => {
|
|
2884
|
+
const start = readFunction(props, "startSession");
|
|
2885
|
+
if (start !== void 0) {
|
|
2886
|
+
start(workspaceId, options);
|
|
2887
|
+
return;
|
|
2888
|
+
}
|
|
2889
|
+
bridge?.startSession(workspaceId, options);
|
|
2890
|
+
},
|
|
2891
|
+
renameSession: async (sessionId, title) => {
|
|
2892
|
+
const rename = readFunction(props, "renameSession");
|
|
2893
|
+
if (rename !== void 0) {
|
|
2894
|
+
await rename(sessionId, title);
|
|
2895
|
+
return;
|
|
2896
|
+
}
|
|
2897
|
+
await bridge?.renameSession(sessionId, title);
|
|
2898
|
+
},
|
|
2899
|
+
archiveSession: async (sessionId) => {
|
|
2900
|
+
const archive = readFunction(props, "archiveSession");
|
|
2901
|
+
if (archive !== void 0) {
|
|
2902
|
+
await archive(sessionId);
|
|
2903
|
+
return;
|
|
2904
|
+
}
|
|
2905
|
+
await bridge?.archiveSession(sessionId);
|
|
2906
|
+
},
|
|
2907
|
+
forkSession: async (sessionId) => {
|
|
2908
|
+
const fork = readFunction(props, "forkSession");
|
|
2909
|
+
if (fork !== void 0) {
|
|
2910
|
+
await fork(sessionId);
|
|
2911
|
+
return;
|
|
2912
|
+
}
|
|
2913
|
+
await bridge?.forkSession(sessionId);
|
|
2914
|
+
},
|
|
2915
|
+
renameWorkspace: async (workspaceId, title) => {
|
|
2916
|
+
const rename = readFunction(props, "renameWorkspace");
|
|
2917
|
+
if (rename !== void 0) {
|
|
2918
|
+
await rename(workspaceId, title);
|
|
2919
|
+
return;
|
|
2920
|
+
}
|
|
2921
|
+
await bridge?.renameWorkspace(workspaceId, title);
|
|
2922
|
+
},
|
|
2923
|
+
pickDirectory: async () => {
|
|
2924
|
+
if (bridge === void 0) throw new Error("directory-picker/unavailable");
|
|
2925
|
+
return await bridge.pickDirectory();
|
|
2926
|
+
},
|
|
2927
|
+
createWorkspace: async (path) => {
|
|
2928
|
+
const trimmed = path.trim();
|
|
2929
|
+
if (trimmed === "") throw new Error("workspace path is empty");
|
|
2930
|
+
if (bridge !== void 0) {
|
|
2931
|
+
await bridge.createWorkspace(trimmed);
|
|
2932
|
+
return;
|
|
2933
|
+
}
|
|
2934
|
+
const body2 = await postJson(ROUTE_WORKSPACE_OPEN, { path: trimmed });
|
|
2935
|
+
if (body2?.ok !== true) {
|
|
2936
|
+
throw new Error(typeof body2?.message === "string" ? body2.message : "workspace-open failed");
|
|
2937
|
+
}
|
|
2938
|
+
},
|
|
2939
|
+
post: postJson
|
|
2940
|
+
}), [props, bridge]);
|
|
2941
|
+
const resetExpandLevels = (0, import_react.useCallback)((keys) => {
|
|
2942
|
+
setExpandLevels((previous) => {
|
|
2943
|
+
let next;
|
|
2944
|
+
for (const key of keys) {
|
|
2945
|
+
if (previous[key] === void 0) continue;
|
|
2946
|
+
next ??= { ...previous };
|
|
2947
|
+
delete next[key];
|
|
2948
|
+
}
|
|
2949
|
+
if (next === void 0) return previous;
|
|
2950
|
+
writeLevelMap(LS_EXPAND_LEVELS, next);
|
|
2951
|
+
return next;
|
|
2952
|
+
});
|
|
2953
|
+
}, []);
|
|
2954
|
+
const toggleCollapsed = (0, import_react.useCallback)((key) => {
|
|
2955
|
+
if (collapsedKeys[key] !== true) resetExpandLevels(containerKeysUnder(latestKnownProjects, key));
|
|
2956
|
+
setCollapsedKeys((previous) => {
|
|
2957
|
+
const next = { ...previous };
|
|
2958
|
+
if (next[key] === true) delete next[key];
|
|
2959
|
+
else next[key] = true;
|
|
2960
|
+
writeFlagMap(LS_COLLAPSED, next);
|
|
2961
|
+
return next;
|
|
2962
|
+
});
|
|
2963
|
+
}, [collapsedKeys, resetExpandLevels]);
|
|
2964
|
+
const expandKeys = (0, import_react.useCallback)((keys) => {
|
|
2965
|
+
setCollapsedKeys((previous) => {
|
|
2966
|
+
const next = { ...previous };
|
|
2967
|
+
let changed = false;
|
|
2968
|
+
for (const key of keys) {
|
|
2969
|
+
if (next[key] === true) {
|
|
2970
|
+
delete next[key];
|
|
2971
|
+
changed = true;
|
|
2972
|
+
}
|
|
2973
|
+
}
|
|
2974
|
+
if (!changed) return previous;
|
|
2975
|
+
writeFlagMap(LS_COLLAPSED, next);
|
|
2976
|
+
return next;
|
|
2977
|
+
});
|
|
2978
|
+
}, []);
|
|
2979
|
+
const expandMore = (0, import_react.useCallback)((key) => {
|
|
2980
|
+
setExpandLevels((previous) => {
|
|
2981
|
+
const next = { ...previous, [key]: (previous[key] ?? 0) + 1 };
|
|
2982
|
+
writeLevelMap(LS_EXPAND_LEVELS, next);
|
|
2983
|
+
return next;
|
|
2984
|
+
});
|
|
2985
|
+
}, []);
|
|
2986
|
+
const newSession = (0, import_react.useCallback)((extra) => {
|
|
2987
|
+
void (async () => {
|
|
2988
|
+
try {
|
|
2989
|
+
let workspaceId = extra.workspaceId;
|
|
2990
|
+
if (workspaceId === void 0) {
|
|
2991
|
+
const body2 = await actions.post(ROUTE_WORKSPACE_OPEN, { path: extra.path });
|
|
2992
|
+
if (body2?.ok !== true || typeof body2.workspaceId !== "string") {
|
|
2993
|
+
throw new Error(typeof body2?.message === "string" ? body2.message : t("error.load"));
|
|
2994
|
+
}
|
|
2995
|
+
workspaceId = body2.workspaceId;
|
|
2996
|
+
}
|
|
2997
|
+
actions.startSession(workspaceId, SAME_LOCATION_START_SESSION);
|
|
2998
|
+
reload();
|
|
2999
|
+
} catch (error) {
|
|
3000
|
+
setLoadError(error instanceof Error ? error.message : t("error.load"));
|
|
3001
|
+
}
|
|
3002
|
+
})();
|
|
3003
|
+
}, [actions, reload, t]);
|
|
3004
|
+
const addWorkspace = (0, import_react.useCallback)(() => {
|
|
3005
|
+
void (async () => {
|
|
3006
|
+
let picked;
|
|
3007
|
+
try {
|
|
3008
|
+
const selected = await actions.pickDirectory();
|
|
3009
|
+
if (typeof selected !== "string" || selected === "") return;
|
|
3010
|
+
picked = selected;
|
|
3011
|
+
} catch {
|
|
3012
|
+
setAddWorkspaceOpen(true);
|
|
3013
|
+
return;
|
|
3014
|
+
}
|
|
3015
|
+
try {
|
|
3016
|
+
await actions.createWorkspace(picked);
|
|
3017
|
+
reload();
|
|
3018
|
+
} catch (error) {
|
|
3019
|
+
setLoadError(error instanceof Error ? error.message : t("error.load"));
|
|
3020
|
+
}
|
|
3021
|
+
})();
|
|
3022
|
+
}, [actions, reload, t]);
|
|
3023
|
+
(0, import_react.useEffect)(() => {
|
|
3024
|
+
if (tree === null) return;
|
|
3025
|
+
setTopZoneState(
|
|
3026
|
+
(previous) => observeTopZone(
|
|
3027
|
+
previous,
|
|
3028
|
+
observationsOf({
|
|
3029
|
+
projects: tree.projects,
|
|
3030
|
+
ungrouped: tree.ungrouped,
|
|
3031
|
+
archivedSessionIds: tree.archivedSessionIds
|
|
3032
|
+
}),
|
|
3033
|
+
Date.now()
|
|
3034
|
+
)
|
|
3035
|
+
);
|
|
3036
|
+
}, [tree]);
|
|
3037
|
+
const topZone = (0, import_react.useMemo)(() => topZoneInputOf(topZoneState), [topZoneState]);
|
|
3038
|
+
const archivedProjectKeys = (0, import_react.useMemo)(() => {
|
|
3039
|
+
const keys = new Set(Object.keys(archivedMap));
|
|
3040
|
+
for (const item of tree?.archivedProjects ?? []) {
|
|
3041
|
+
if (typeof item?.key === "string" && item.key !== "") keys.add(item.key);
|
|
3042
|
+
}
|
|
3043
|
+
return [...keys];
|
|
3044
|
+
}, [archivedMap, tree]);
|
|
3045
|
+
const treeInput = (0, import_react.useMemo)(() => ({
|
|
3046
|
+
projects: tree?.projects ?? [],
|
|
3047
|
+
ungrouped: tree?.ungrouped ?? [],
|
|
3048
|
+
archivedSessionIds: tree?.archivedSessionIds ?? [],
|
|
3049
|
+
collapsedKeys,
|
|
3050
|
+
expandedAllKeys: {},
|
|
3051
|
+
expandLevels,
|
|
3052
|
+
query,
|
|
3053
|
+
titleOf: defaultTitleOf,
|
|
3054
|
+
t,
|
|
3055
|
+
manualOrder,
|
|
3056
|
+
topZone,
|
|
3057
|
+
includeRecent: true,
|
|
3058
|
+
archivedProjectKeys,
|
|
3059
|
+
...currentSessionId === void 0 ? {} : { currentSessionId }
|
|
3060
|
+
}), [tree, collapsedKeys, expandLevels, query, t, manualOrder, topZone, archivedProjectKeys, currentSessionId]);
|
|
3061
|
+
const view = (0, import_react.useMemo)(
|
|
3062
|
+
() => buildTreeView(tree, treeInput),
|
|
3063
|
+
[tree, treeInput]
|
|
3064
|
+
);
|
|
3065
|
+
(0, import_react.useEffect)(() => {
|
|
3066
|
+
if (manualOrder.manual !== true) return;
|
|
3067
|
+
if (pendingNewSessionIdsOf(topZoneState).length === 0) return;
|
|
3068
|
+
if (tree === null) return;
|
|
3069
|
+
const defaults = effectiveOrder({
|
|
3070
|
+
projects: tree.projects,
|
|
3071
|
+
ungrouped: tree.ungrouped,
|
|
3072
|
+
archivedSessionIds: tree.archivedSessionIds,
|
|
3073
|
+
collapsedKeys: {},
|
|
3074
|
+
expandedAllKeys: {},
|
|
3075
|
+
query: "",
|
|
3076
|
+
titleOf: defaultTitleOf,
|
|
3077
|
+
t,
|
|
3078
|
+
manualOrder: void 0
|
|
3079
|
+
});
|
|
3080
|
+
const plan = planNewSessionInserts(
|
|
3081
|
+
manualOrder,
|
|
3082
|
+
defaults.sessions,
|
|
3083
|
+
topZoneState.newSessionIds,
|
|
3084
|
+
topZoneState.writtenNewSessionIds
|
|
3085
|
+
);
|
|
3086
|
+
if (plan.consumed.length > 0) {
|
|
3087
|
+
const consumed = plan.consumed;
|
|
3088
|
+
setTopZoneState((previous) => markNewSessionsWritten(previous, consumed));
|
|
3089
|
+
}
|
|
3090
|
+
if (!plan.changed) return;
|
|
3091
|
+
setManualOrder(plan.order);
|
|
3092
|
+
writeManualOrder(plan.order);
|
|
3093
|
+
}, [topZoneState.newSessionIds, topZoneState.writtenNewSessionIds, manualOrder, tree, t]);
|
|
3094
|
+
const persistOrder = (0, import_react.useCallback)((next) => {
|
|
3095
|
+
setManualOrder(next);
|
|
3096
|
+
writeManualOrder(next);
|
|
3097
|
+
}, []);
|
|
3098
|
+
const commitDrag = (0, import_react.useCallback)((active, over) => {
|
|
3099
|
+
const defaults = effectiveOrder({ ...treeInput, manualOrder: void 0 });
|
|
3100
|
+
const base = manualOrder.manual === true ? manualOrder : {
|
|
3101
|
+
manual: true,
|
|
3102
|
+
projects: defaults.projects,
|
|
3103
|
+
worktrees: Object.fromEntries(defaults.worktrees),
|
|
3104
|
+
sessions: Object.fromEntries(defaults.sessions)
|
|
3105
|
+
};
|
|
3106
|
+
if (active.kind === "session") {
|
|
3107
|
+
const containerKey = active.containerKey ?? "";
|
|
3108
|
+
const next2 = reorderManualScope(
|
|
3109
|
+
manualOrder.manual === true ? manualOrder.sessions?.[containerKey] : void 0,
|
|
3110
|
+
defaults.sessions.get(containerKey) ?? [],
|
|
3111
|
+
active.itemId,
|
|
3112
|
+
over.key.slice("s:".length),
|
|
3113
|
+
over.half
|
|
3114
|
+
);
|
|
3115
|
+
if (next2 === null) return;
|
|
3116
|
+
const sessions = { ...base.sessions ?? {} };
|
|
3117
|
+
sessions[containerKey] = next2;
|
|
3118
|
+
persistOrder({ ...base, manual: true, sessions });
|
|
3119
|
+
return;
|
|
3120
|
+
}
|
|
3121
|
+
if (active.kind === "worktree") {
|
|
3122
|
+
const projectKey = active.projectKey ?? "";
|
|
3123
|
+
const next2 = reorderManualScope(
|
|
3124
|
+
manualOrder.manual === true ? manualOrder.worktrees?.[projectKey] : void 0,
|
|
3125
|
+
defaults.worktrees.get(projectKey) ?? [],
|
|
3126
|
+
active.itemId,
|
|
3127
|
+
over.key.slice("w:".length),
|
|
3128
|
+
over.half
|
|
3129
|
+
);
|
|
3130
|
+
if (next2 === null) return;
|
|
3131
|
+
const worktrees = { ...base.worktrees ?? {} };
|
|
3132
|
+
worktrees[projectKey] = next2;
|
|
3133
|
+
persistOrder({ ...base, manual: true, worktrees });
|
|
3134
|
+
return;
|
|
3135
|
+
}
|
|
3136
|
+
const next = reorderManualScope(
|
|
3137
|
+
manualOrder.manual === true ? manualOrder.projects : void 0,
|
|
3138
|
+
defaults.projects,
|
|
3139
|
+
active.itemId,
|
|
3140
|
+
over.key.slice("p:".length),
|
|
3141
|
+
over.half
|
|
3142
|
+
);
|
|
3143
|
+
if (next === null) return;
|
|
3144
|
+
persistOrder({ ...base, manual: true, projects: next });
|
|
3145
|
+
}, [treeInput, manualOrder, persistOrder]);
|
|
3146
|
+
const dragHandlersFor = (row, scope, draggable = true) => {
|
|
3147
|
+
if (scope === void 0) return void 0;
|
|
3148
|
+
const { kind, itemId, projectKey, containerKey } = scope;
|
|
3149
|
+
const state = {
|
|
3150
|
+
kind,
|
|
3151
|
+
key: row.key,
|
|
3152
|
+
itemId,
|
|
3153
|
+
...projectKey === void 0 ? {} : { projectKey },
|
|
3154
|
+
...containerKey === void 0 ? {} : { containerKey }
|
|
3155
|
+
};
|
|
3156
|
+
const accepts = (active) => {
|
|
3157
|
+
if (active.kind !== kind) return false;
|
|
3158
|
+
if (kind === "session") return active.containerKey === containerKey;
|
|
3159
|
+
if (kind === "worktree") return active.projectKey === projectKey;
|
|
3160
|
+
return true;
|
|
3161
|
+
};
|
|
3162
|
+
return {
|
|
3163
|
+
draggable,
|
|
3164
|
+
dragging: drag !== null && drag.key === row.key,
|
|
3165
|
+
marker: drag !== null && accepts(drag) && dropTarget?.key === row.key ? dropTarget.half : null,
|
|
3166
|
+
onDragStart: (event) => {
|
|
3167
|
+
if (!draggable) return;
|
|
3168
|
+
if (event?.dataTransfer !== null && event?.dataTransfer !== void 0) {
|
|
3169
|
+
event.dataTransfer.effectAllowed = "move";
|
|
3170
|
+
event.dataTransfer.setData("text/plain", row.key);
|
|
3171
|
+
}
|
|
3172
|
+
setDrag(state);
|
|
3173
|
+
setDropTarget(null);
|
|
3174
|
+
},
|
|
3175
|
+
onDragEnd: () => {
|
|
3176
|
+
setDrag(null);
|
|
3177
|
+
setDropTarget(null);
|
|
3178
|
+
},
|
|
3179
|
+
onDragOver: (event) => {
|
|
3180
|
+
if (drag === null || !accepts(drag)) return;
|
|
3181
|
+
event.preventDefault();
|
|
3182
|
+
if (event?.dataTransfer !== null && event?.dataTransfer !== void 0) {
|
|
3183
|
+
event.dataTransfer.dropEffect = "move";
|
|
3184
|
+
}
|
|
3185
|
+
const half = rowHalf(event);
|
|
3186
|
+
setDropTarget(
|
|
3187
|
+
(previous) => previous?.key === row.key && previous.half === half ? previous : { key: row.key, half }
|
|
3188
|
+
);
|
|
3189
|
+
},
|
|
3190
|
+
onDrop: (event) => {
|
|
3191
|
+
if (drag === null || !accepts(drag)) return;
|
|
3192
|
+
event.preventDefault();
|
|
3193
|
+
event.stopPropagation();
|
|
3194
|
+
const half = rowHalf(event);
|
|
3195
|
+
const active = drag;
|
|
3196
|
+
setDrag(null);
|
|
3197
|
+
setDropTarget(null);
|
|
3198
|
+
commitDrag(active, { key: row.key, half });
|
|
3199
|
+
}
|
|
3200
|
+
};
|
|
3201
|
+
};
|
|
3202
|
+
if (wide === false) {
|
|
3203
|
+
return jsx("div", {
|
|
3204
|
+
style: { display: "flex", justifyContent: "center", padding: "4px 0" },
|
|
3205
|
+
children: jsx("button", {
|
|
3206
|
+
type: "button",
|
|
3207
|
+
title: t("section.workspaces"),
|
|
3208
|
+
"aria-label": t("section.workspaces"),
|
|
3209
|
+
onClick: () => {
|
|
3210
|
+
expandSidebar?.();
|
|
3211
|
+
},
|
|
3212
|
+
style: {
|
|
3213
|
+
display: "inline-flex",
|
|
3214
|
+
alignItems: "center",
|
|
3215
|
+
justifyContent: "center",
|
|
3216
|
+
width: RAIL_BUTTON,
|
|
3217
|
+
height: RAIL_BUTTON,
|
|
3218
|
+
padding: 0,
|
|
3219
|
+
border: "none",
|
|
3220
|
+
borderRadius: 10,
|
|
3221
|
+
background: "transparent",
|
|
3222
|
+
color: "var(--dsw-alias-label-primary)",
|
|
3223
|
+
cursor: "pointer"
|
|
3224
|
+
},
|
|
3225
|
+
children: icon("panelLeft")
|
|
3226
|
+
})
|
|
3227
|
+
});
|
|
3228
|
+
}
|
|
3229
|
+
const openMenu = (target) => {
|
|
3230
|
+
setMenuTarget(target);
|
|
3231
|
+
};
|
|
3232
|
+
const pointOf = (event, fallback) => {
|
|
3233
|
+
const rect = fallback?.getBoundingClientRect?.();
|
|
3234
|
+
return {
|
|
3235
|
+
x: Math.round(Number(rect?.left ?? event?.clientX ?? 0)),
|
|
3236
|
+
y: Math.round(Number(rect?.bottom ?? event?.clientY ?? 0))
|
|
3237
|
+
};
|
|
3238
|
+
};
|
|
3239
|
+
const rowNodes = [];
|
|
3240
|
+
const sessionHandlers = /* @__PURE__ */ new Map();
|
|
3241
|
+
for (const viewRow of view.rows) {
|
|
3242
|
+
const row = withLiveState(viewRow, { status: sessionStatus, pending: pendingInteractions, sessions: sessionsSnapshot });
|
|
3243
|
+
if (row.kind === "session") {
|
|
3244
|
+
const sessionDrag = dragHandlersFor(
|
|
3245
|
+
row,
|
|
3246
|
+
{ kind: "session", itemId: row.sessionId, containerKey: row.parentKey },
|
|
3247
|
+
!isSessionDragLocked(row, topZone)
|
|
3248
|
+
);
|
|
3249
|
+
const rowDrag = row.parentKind === "recent" ? void 0 : sessionDrag;
|
|
3250
|
+
sessionHandlers.set(row.key, {
|
|
3251
|
+
onOpen: () => {
|
|
3252
|
+
setOptimisticSessionId(row.sessionId);
|
|
3253
|
+
actions.openSession(row.sessionId);
|
|
3254
|
+
},
|
|
3255
|
+
onMenu: (target) => {
|
|
3256
|
+
openMenu({ kind: "session", x: target.x, y: target.y, title: target.title, sessionId: target.sessionId });
|
|
3257
|
+
},
|
|
3258
|
+
...rowDrag === void 0 ? {} : { drag: rowDrag }
|
|
3259
|
+
});
|
|
3260
|
+
rowNodes.push(jsx(SessionRowView, {
|
|
3261
|
+
key: row.key,
|
|
3262
|
+
row,
|
|
3263
|
+
t,
|
|
3264
|
+
rowKey: row.key,
|
|
3265
|
+
handlers: sessionHandlersRef,
|
|
3266
|
+
...row.parentKind === "recent" || sessionDrag === void 0 ? {} : { drag: { draggable: sessionDrag.draggable, dragging: sessionDrag.dragging, marker: sessionDrag.marker } }
|
|
3267
|
+
}));
|
|
3268
|
+
continue;
|
|
3269
|
+
}
|
|
3270
|
+
if (row.kind === "more") {
|
|
3271
|
+
rowNodes.push(jsx(MoreRowView, {
|
|
3272
|
+
key: row.key,
|
|
3273
|
+
row,
|
|
3274
|
+
t,
|
|
3275
|
+
onExpand: () => {
|
|
3276
|
+
expandMore(row.parentKey);
|
|
3277
|
+
},
|
|
3278
|
+
onCollapse: () => {
|
|
3279
|
+
resetExpandLevels([row.parentKey]);
|
|
3280
|
+
}
|
|
3281
|
+
}));
|
|
3282
|
+
continue;
|
|
3283
|
+
}
|
|
3284
|
+
if (row.kind === "history") {
|
|
3285
|
+
rowNodes.push(jsx(HoverContainerRow, {
|
|
3286
|
+
key: row.key,
|
|
3287
|
+
row,
|
|
3288
|
+
t,
|
|
3289
|
+
renderActions: () => [],
|
|
3290
|
+
onToggle: () => {
|
|
3291
|
+
toggleCollapsed(row.key);
|
|
3292
|
+
}
|
|
3293
|
+
}));
|
|
3294
|
+
continue;
|
|
3295
|
+
}
|
|
3296
|
+
if (row.kind === "recent") {
|
|
3297
|
+
rowNodes.push(jsx(RecentSectionHeaderView, {
|
|
3298
|
+
key: row.key,
|
|
3299
|
+
row,
|
|
3300
|
+
onToggle: () => {
|
|
3301
|
+
toggleCollapsed(row.key);
|
|
3302
|
+
}
|
|
3303
|
+
}));
|
|
3304
|
+
continue;
|
|
3305
|
+
}
|
|
3306
|
+
if (row.kind === "worktree") {
|
|
3307
|
+
const owner = view.worktreeOwner.get(row.key);
|
|
3308
|
+
const worktreeDrag = dragHandlersFor(row, owner === void 0 ? void 0 : { kind: "worktree", itemId: row.path, projectKey: owner });
|
|
3309
|
+
const extra2 = view.worktrees.get(row.key);
|
|
3310
|
+
if (extra2 === void 0) {
|
|
3311
|
+
rowNodes.push(jsx(HoverContainerRow, {
|
|
3312
|
+
key: row.key,
|
|
3313
|
+
row,
|
|
3314
|
+
t,
|
|
3315
|
+
renderActions: () => [],
|
|
3316
|
+
onToggle: () => {
|
|
3317
|
+
toggleCollapsed(row.key);
|
|
3318
|
+
},
|
|
3319
|
+
...worktreeDrag === void 0 ? {} : { drag: worktreeDrag }
|
|
3320
|
+
}));
|
|
3321
|
+
continue;
|
|
3322
|
+
}
|
|
3323
|
+
const node = extra2;
|
|
3324
|
+
rowNodes.push(jsx(HoverContainerRow, {
|
|
3325
|
+
key: row.key,
|
|
3326
|
+
row,
|
|
3327
|
+
t,
|
|
3328
|
+
...worktreeDrag === void 0 ? {} : { drag: worktreeDrag },
|
|
3329
|
+
renderActions: (hovered) => [
|
|
3330
|
+
jsx("button", {
|
|
3331
|
+
key: "new",
|
|
3332
|
+
type: "button",
|
|
3333
|
+
title: t("menu.newSession"),
|
|
3334
|
+
"aria-label": t("menu.newSession"),
|
|
3335
|
+
style: iconButtonStyle(hovered),
|
|
3336
|
+
// D10:按钮**不可拖**且吞掉 dragstart —— 否则按住 `+` 拖动会拖走整行,
|
|
3337
|
+
// 点按钮的手感立刻变差(`draggable` 在父行上,事件会冒泡上来)。
|
|
3338
|
+
draggable: false,
|
|
3339
|
+
onDragStart: (event) => {
|
|
3340
|
+
event.stopPropagation();
|
|
3341
|
+
},
|
|
3342
|
+
onClick: (event) => {
|
|
3343
|
+
event.stopPropagation();
|
|
3344
|
+
newSession(node);
|
|
3345
|
+
},
|
|
3346
|
+
children: icon("plus")
|
|
3347
|
+
}),
|
|
3348
|
+
jsx("button", {
|
|
3349
|
+
key: "more",
|
|
3350
|
+
type: "button",
|
|
3351
|
+
title: t("worktree.menu"),
|
|
3352
|
+
"aria-label": t("worktree.menu"),
|
|
3353
|
+
style: iconButtonStyle(hovered),
|
|
3354
|
+
draggable: false,
|
|
3355
|
+
onDragStart: (event) => {
|
|
3356
|
+
event.stopPropagation();
|
|
3357
|
+
},
|
|
3358
|
+
onClick: (event) => {
|
|
3359
|
+
event.stopPropagation();
|
|
3360
|
+
const point = pointOf(event, event?.currentTarget);
|
|
3361
|
+
openMenu({ kind: "worktree", x: point.x, y: point.y, title: row.label, extra: node });
|
|
3362
|
+
},
|
|
3363
|
+
children: icon("ellipsis")
|
|
3364
|
+
})
|
|
3365
|
+
],
|
|
3366
|
+
onToggle: () => {
|
|
3367
|
+
toggleCollapsed(row.key);
|
|
3368
|
+
},
|
|
3369
|
+
onContextMenu: (event) => {
|
|
3370
|
+
event.preventDefault();
|
|
3371
|
+
const point = pointOf(event, void 0);
|
|
3372
|
+
openMenu({ kind: "worktree", x: point.x, y: point.y, title: row.label, extra: node });
|
|
3373
|
+
}
|
|
3374
|
+
}));
|
|
3375
|
+
continue;
|
|
3376
|
+
}
|
|
3377
|
+
const projectDrag = row.key === PREFIX_UNGROUPED ? void 0 : dragHandlersFor(row, { kind: "project", itemId: row.key.slice("p:".length) });
|
|
3378
|
+
const extra = view.projects.get(row.key);
|
|
3379
|
+
if (extra === void 0) {
|
|
3380
|
+
rowNodes.push(jsx(HoverContainerRow, {
|
|
3381
|
+
key: row.key,
|
|
3382
|
+
row,
|
|
3383
|
+
t,
|
|
3384
|
+
renderActions: () => [],
|
|
3385
|
+
onToggle: () => {
|
|
3386
|
+
toggleCollapsed(row.key);
|
|
3387
|
+
},
|
|
3388
|
+
...projectDrag === void 0 ? {} : { drag: projectDrag }
|
|
3389
|
+
}));
|
|
3390
|
+
continue;
|
|
3391
|
+
}
|
|
3392
|
+
const project = extra;
|
|
3393
|
+
rowNodes.push(jsx(HoverContainerRow, {
|
|
3394
|
+
key: row.key,
|
|
3395
|
+
row,
|
|
3396
|
+
t,
|
|
3397
|
+
...projectDrag === void 0 ? {} : { drag: projectDrag },
|
|
3398
|
+
renderActions: (hovered) => {
|
|
3399
|
+
if (project.isUngrouped) return [];
|
|
3400
|
+
if (project.isGit) {
|
|
3401
|
+
if (project.mainPath === void 0) return [];
|
|
3402
|
+
return [jsx("button", {
|
|
3403
|
+
key: "more",
|
|
3404
|
+
type: "button",
|
|
3405
|
+
title: t("worktree.menu"),
|
|
3406
|
+
"aria-label": t("worktree.menu"),
|
|
3407
|
+
style: iconButtonStyle(hovered),
|
|
3408
|
+
// D10:按钮不参与行拖拽(同 worktree 行的 `+` / `…`)。
|
|
3409
|
+
draggable: false,
|
|
3410
|
+
onDragStart: (event) => {
|
|
3411
|
+
event.stopPropagation();
|
|
3412
|
+
},
|
|
3413
|
+
onClick: (event) => {
|
|
3414
|
+
event.stopPropagation();
|
|
3415
|
+
const point = pointOf(event, event?.currentTarget);
|
|
3416
|
+
openMenu({ kind: "project", x: point.x, y: point.y, title: row.label, key: row.key, extra: project });
|
|
3417
|
+
},
|
|
3418
|
+
children: icon("ellipsis")
|
|
3419
|
+
})];
|
|
3420
|
+
}
|
|
3421
|
+
if (project.workspaceId === void 0) return [];
|
|
3422
|
+
const workspaceId = project.workspaceId;
|
|
3423
|
+
return [
|
|
3424
|
+
jsx("button", {
|
|
3425
|
+
key: "new-session",
|
|
3426
|
+
type: "button",
|
|
3427
|
+
title: t("menu.newSession"),
|
|
3428
|
+
"aria-label": t("menu.newSession"),
|
|
3429
|
+
style: iconButtonStyle(hovered),
|
|
3430
|
+
draggable: false,
|
|
3431
|
+
onDragStart: (event) => {
|
|
3432
|
+
event.stopPropagation();
|
|
3433
|
+
},
|
|
3434
|
+
// 2026-10-22 DR1:非 git 工作区与 worktree 同口径 —— 复用同目录空白会话、保留草稿。
|
|
3435
|
+
onClick: (event) => {
|
|
3436
|
+
event.stopPropagation();
|
|
3437
|
+
actions.startSession(workspaceId, SAME_LOCATION_START_SESSION);
|
|
3438
|
+
reload();
|
|
3439
|
+
},
|
|
3440
|
+
children: icon("plus")
|
|
3441
|
+
}),
|
|
3442
|
+
jsx("button", {
|
|
3443
|
+
key: "more",
|
|
3444
|
+
type: "button",
|
|
3445
|
+
title: t("worktree.menu"),
|
|
3446
|
+
"aria-label": t("worktree.menu"),
|
|
3447
|
+
style: iconButtonStyle(hovered),
|
|
3448
|
+
draggable: false,
|
|
3449
|
+
onDragStart: (event) => {
|
|
3450
|
+
event.stopPropagation();
|
|
3451
|
+
},
|
|
3452
|
+
onClick: (event) => {
|
|
3453
|
+
event.stopPropagation();
|
|
3454
|
+
const point = pointOf(event, event?.currentTarget);
|
|
3455
|
+
openMenu({ kind: "project", x: point.x, y: point.y, title: row.label, key: row.key, extra: project });
|
|
3456
|
+
},
|
|
3457
|
+
children: icon("ellipsis")
|
|
3458
|
+
})
|
|
3459
|
+
];
|
|
3460
|
+
},
|
|
3461
|
+
onToggle: () => {
|
|
3462
|
+
toggleCollapsed(row.key);
|
|
3463
|
+
},
|
|
3464
|
+
onContextMenu: project.isUngrouped ? void 0 : (event) => {
|
|
3465
|
+
event.preventDefault();
|
|
3466
|
+
const point = pointOf(event, void 0);
|
|
3467
|
+
openMenu({ kind: "project", x: point.x, y: point.y, title: row.label, key: row.key, extra: project });
|
|
3468
|
+
}
|
|
3469
|
+
}));
|
|
3470
|
+
}
|
|
3471
|
+
sessionHandlersRef.current = sessionHandlers;
|
|
3472
|
+
const body = [];
|
|
3473
|
+
body.push(jsxs("div", {
|
|
3474
|
+
key: "search",
|
|
3475
|
+
style: { display: "flex", alignItems: "center", gap: 4, padding: "2px 4px 6px" },
|
|
3476
|
+
children: [
|
|
3477
|
+
jsx("input", {
|
|
3478
|
+
key: "search-input",
|
|
3479
|
+
value: query,
|
|
3480
|
+
placeholder: t("search.placeholder"),
|
|
3481
|
+
"aria-label": t("search.placeholder"),
|
|
3482
|
+
onChange: (event) => {
|
|
3483
|
+
setQuery(String(event?.target?.value ?? ""));
|
|
3484
|
+
},
|
|
3485
|
+
style: {
|
|
3486
|
+
flex: 1,
|
|
3487
|
+
minWidth: 0,
|
|
3488
|
+
height: 30,
|
|
3489
|
+
boxSizing: "border-box",
|
|
3490
|
+
border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,0.3))",
|
|
3491
|
+
borderRadius: 8,
|
|
3492
|
+
background: "transparent",
|
|
3493
|
+
color: "var(--dsw-alias-label-primary)",
|
|
3494
|
+
fontFamily: "inherit",
|
|
3495
|
+
fontSize: 13,
|
|
3496
|
+
padding: "0 10px",
|
|
3497
|
+
outline: "none"
|
|
3498
|
+
}
|
|
3499
|
+
}),
|
|
3500
|
+
jsx("button", {
|
|
3501
|
+
key: "add-workspace",
|
|
3502
|
+
type: "button",
|
|
3503
|
+
title: t("project.add"),
|
|
3504
|
+
"aria-label": t("project.add"),
|
|
3505
|
+
onClick: () => {
|
|
3506
|
+
void addWorkspace();
|
|
3507
|
+
},
|
|
3508
|
+
style: {
|
|
3509
|
+
display: "inline-flex",
|
|
3510
|
+
alignItems: "center",
|
|
3511
|
+
justifyContent: "center",
|
|
3512
|
+
width: 28,
|
|
3513
|
+
height: 28,
|
|
3514
|
+
padding: 0,
|
|
3515
|
+
flex: "none",
|
|
3516
|
+
border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,0.3))",
|
|
3517
|
+
borderRadius: 8,
|
|
3518
|
+
background: "transparent",
|
|
3519
|
+
color: "var(--dsw-alias-label-tertiary, var(--dsw-alias-label-dimmed))",
|
|
3520
|
+
cursor: "pointer"
|
|
3521
|
+
},
|
|
3522
|
+
children: icon("projectAdd")
|
|
3523
|
+
})
|
|
3524
|
+
]
|
|
3525
|
+
}));
|
|
3526
|
+
if (tree === null && loadError === null) {
|
|
3527
|
+
body.push(jsx("div", {
|
|
3528
|
+
key: "loading",
|
|
3529
|
+
style: { padding: "10px 12px", ...dimText(12.5) },
|
|
3530
|
+
children: t("state.loadingTree")
|
|
3531
|
+
}));
|
|
3532
|
+
} else if (loadError !== null) {
|
|
3533
|
+
body.push(jsxs("div", {
|
|
3534
|
+
key: "load-error",
|
|
3535
|
+
style: {
|
|
3536
|
+
padding: "10px 12px",
|
|
3537
|
+
display: "flex",
|
|
3538
|
+
flexDirection: "column",
|
|
3539
|
+
gap: 4,
|
|
3540
|
+
fontSize: 12.5,
|
|
3541
|
+
color: "var(--dsw-alias-state-error-primary, #d9534f)"
|
|
3542
|
+
},
|
|
3543
|
+
children: [
|
|
3544
|
+
jsx("div", { key: "msg", children: t("error.load") }),
|
|
3545
|
+
jsx("div", { key: "detail", style: { opacity: 0.85, wordBreak: "break-all" }, children: loadError }),
|
|
3546
|
+
jsx("button", {
|
|
3547
|
+
key: "retry",
|
|
3548
|
+
type: "button",
|
|
3549
|
+
onClick: reload,
|
|
3550
|
+
style: {
|
|
3551
|
+
alignSelf: "flex-start",
|
|
3552
|
+
marginTop: 2,
|
|
3553
|
+
padding: "2px 10px",
|
|
3554
|
+
border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,0.3))",
|
|
3555
|
+
borderRadius: 12,
|
|
3556
|
+
background: "transparent",
|
|
3557
|
+
color: "inherit",
|
|
3558
|
+
fontFamily: "inherit",
|
|
3559
|
+
fontSize: 12,
|
|
3560
|
+
cursor: "pointer"
|
|
3561
|
+
},
|
|
3562
|
+
children: t("error.retry")
|
|
3563
|
+
})
|
|
3564
|
+
]
|
|
3565
|
+
}));
|
|
3566
|
+
} else if (query.trim() !== "" && rowNodes.length === 0) {
|
|
3567
|
+
body.push(jsx("div", {
|
|
3568
|
+
key: "search-empty",
|
|
3569
|
+
style: { padding: "10px 12px", ...dimText(12.5) },
|
|
3570
|
+
children: t("search.empty")
|
|
3571
|
+
}));
|
|
3572
|
+
} else {
|
|
3573
|
+
body.push(...rowNodes);
|
|
3574
|
+
}
|
|
3575
|
+
if (busyText !== null) {
|
|
3576
|
+
body.push(jsx("div", { key: "busy", style: { padding: "6px 12px", ...dimText(12) }, children: busyText }));
|
|
3577
|
+
}
|
|
3578
|
+
if (notice !== null) {
|
|
3579
|
+
body.push(jsx("div", {
|
|
3580
|
+
key: "notice",
|
|
3581
|
+
style: {
|
|
3582
|
+
padding: "6px 12px",
|
|
3583
|
+
fontSize: 12,
|
|
3584
|
+
wordBreak: "break-all",
|
|
3585
|
+
color: "var(--dsw-alias-state-warning-primary, #b8860b)"
|
|
3586
|
+
},
|
|
3587
|
+
children: notice
|
|
3588
|
+
}));
|
|
3589
|
+
}
|
|
3590
|
+
if (renderSlot !== void 0) {
|
|
3591
|
+
try {
|
|
3592
|
+
const flow = renderSlot(DIRECTORY_FLOW_SLOT);
|
|
3593
|
+
if (present(flow)) body.push(jsx("div", { key: "directory-flow", children: flow }));
|
|
3594
|
+
} catch (error) {
|
|
3595
|
+
console.warn("[dsh-worktree-groups] renderSlot(worktreeDirectoryFlow) failed:", error);
|
|
3596
|
+
}
|
|
3597
|
+
}
|
|
3598
|
+
return jsxs("div", {
|
|
3599
|
+
style: { display: "flex", flexDirection: "column", minHeight: 0, height: "100%", color: "var(--dsw-alias-label-primary)" },
|
|
3600
|
+
children: [
|
|
3601
|
+
jsx("div", {
|
|
3602
|
+
key: "scroll",
|
|
3603
|
+
style: { flex: 1, minHeight: 0, overflowY: "auto", overflowX: "hidden", padding: "0 4px 8px" },
|
|
3604
|
+
children: body
|
|
3605
|
+
}),
|
|
3606
|
+
jsx(MenuLayer, {
|
|
3607
|
+
key: "menu",
|
|
3608
|
+
target: menuTarget,
|
|
3609
|
+
t,
|
|
3610
|
+
actions,
|
|
3611
|
+
onClose: () => {
|
|
3612
|
+
setMenuTarget(null);
|
|
3613
|
+
},
|
|
3614
|
+
onNewSession: newSession,
|
|
3615
|
+
onRename: setRenameState,
|
|
3616
|
+
onCreateWorktree: (state) => {
|
|
3617
|
+
setCreateState(state);
|
|
3618
|
+
},
|
|
3619
|
+
onRemoveWorktree: setRemoveTarget,
|
|
3620
|
+
reload,
|
|
3621
|
+
setLoadError,
|
|
3622
|
+
collectBaseCandidates: (repoPath) => collectBaseCandidates(view, repoPath),
|
|
3623
|
+
// D10:**仅 `manual === true` 时**显示「恢复默认排序」。判据在 MenuLayer 里
|
|
3624
|
+
// (`orderIsManual`),这里只给「切回默认」的动作 + 当前是否 manual 的事实。
|
|
3625
|
+
orderIsManual: manualOrder.manual === true,
|
|
3626
|
+
onResetOrder: () => {
|
|
3627
|
+
clearManualOrder();
|
|
3628
|
+
setManualOrder(EMPTY_ORDER);
|
|
3629
|
+
reload();
|
|
3630
|
+
}
|
|
3631
|
+
}),
|
|
3632
|
+
jsx(CreateWorktreeDialog, {
|
|
3633
|
+
key: "create",
|
|
3634
|
+
state: createState,
|
|
3635
|
+
t,
|
|
3636
|
+
onClose: () => {
|
|
3637
|
+
setCreateState(null);
|
|
3638
|
+
},
|
|
3639
|
+
onBusy: setBusyText,
|
|
3640
|
+
// **D10**:警告用独立的 `notice` 行渲染,**不能**用 `setLoadError` ——
|
|
3641
|
+
// `loadError !== null` 会走错误分支而**整棵树被错误框替换**,恰好在
|
|
3642
|
+
// 「worktree 已建成、需要立刻显示新行」时把树藏起来。也不能用 `busyText`:
|
|
3643
|
+
// 提交结束的 `finally` 会立刻把它清掉。
|
|
3644
|
+
onWarning: setNotice,
|
|
3645
|
+
onError: setLoadError,
|
|
3646
|
+
post: actions.post,
|
|
3647
|
+
onCreated: (worktreePath, workspaceId) => {
|
|
3648
|
+
if (worktreePath !== void 0 && worktreePath !== "") {
|
|
3649
|
+
expandKeys([`${PREFIX_WORKTREE}${worktreePath}`]);
|
|
3650
|
+
}
|
|
3651
|
+
if (workspaceId !== void 0) actions.startSession(workspaceId, SAME_LOCATION_START_SESSION);
|
|
3652
|
+
reload();
|
|
3653
|
+
}
|
|
3654
|
+
}),
|
|
3655
|
+
jsx(RemoveWorktreeDialog, {
|
|
3656
|
+
key: "remove",
|
|
3657
|
+
target: removeTarget,
|
|
3658
|
+
t,
|
|
3659
|
+
onClose: () => {
|
|
3660
|
+
setRemoveTarget(null);
|
|
3661
|
+
},
|
|
3662
|
+
onBusy: setBusyText,
|
|
3663
|
+
onError: setLoadError,
|
|
3664
|
+
post: actions.post,
|
|
3665
|
+
onRemoved: reload
|
|
3666
|
+
}),
|
|
3667
|
+
jsx(RenameDialog, {
|
|
3668
|
+
key: "rename",
|
|
3669
|
+
state: renameState,
|
|
3670
|
+
t,
|
|
3671
|
+
onClose: () => {
|
|
3672
|
+
setRenameState(null);
|
|
3673
|
+
},
|
|
3674
|
+
onSubmit: (value) => {
|
|
3675
|
+
const state = renameState;
|
|
3676
|
+
setRenameState(null);
|
|
3677
|
+
if (state === null) return;
|
|
3678
|
+
void (async () => {
|
|
3679
|
+
try {
|
|
3680
|
+
if (state.kind === "session") await actions.renameSession(state.id, value);
|
|
3681
|
+
else await actions.renameWorkspace(state.id, value);
|
|
3682
|
+
reload();
|
|
3683
|
+
} catch (error) {
|
|
3684
|
+
setLoadError(error instanceof Error ? error.message : t("error.load"));
|
|
3685
|
+
}
|
|
3686
|
+
})();
|
|
3687
|
+
}
|
|
3688
|
+
}),
|
|
3689
|
+
jsx(AddWorkspaceDialog, {
|
|
3690
|
+
key: "add-workspace",
|
|
3691
|
+
open: addWorkspaceOpen,
|
|
3692
|
+
t,
|
|
3693
|
+
onClose: () => {
|
|
3694
|
+
setAddWorkspaceOpen(false);
|
|
3695
|
+
},
|
|
3696
|
+
createWorkspace: actions.createWorkspace,
|
|
3697
|
+
onCreated: () => {
|
|
3698
|
+
setAddWorkspaceOpen(false);
|
|
3699
|
+
reload();
|
|
3700
|
+
}
|
|
3701
|
+
})
|
|
3702
|
+
].filter(present)
|
|
3703
|
+
});
|
|
3704
|
+
}
|
|
3705
|
+
function MenuLayer(props) {
|
|
3706
|
+
const target = props.target;
|
|
3707
|
+
const t = props.t;
|
|
3708
|
+
const anchorX = target?.x ?? 0;
|
|
3709
|
+
const anchorY = target?.y ?? 0;
|
|
3710
|
+
const getAnchorRect = (0, import_react.useCallback)(
|
|
3711
|
+
() => ({ left: anchorX, top: anchorY, right: anchorX, bottom: anchorY, width: 0, height: 0 }),
|
|
3712
|
+
[anchorX, anchorY]
|
|
3713
|
+
);
|
|
3714
|
+
if (target === null) return null;
|
|
3715
|
+
const items = [];
|
|
3716
|
+
const pushResetOrder = () => {
|
|
3717
|
+
if (!props.orderIsManual) return;
|
|
3718
|
+
items.push({ type: "separator" });
|
|
3719
|
+
items.push({ id: MENU.resetOrder, label: t("menu.resetOrder"), icon: icon("refresh") });
|
|
3720
|
+
};
|
|
3721
|
+
if (target.kind === "worktree") {
|
|
3722
|
+
const extra = target.extra;
|
|
3723
|
+
const registered = extra.workspaceId !== void 0;
|
|
3724
|
+
items.push({ id: MENU.newSession, label: t("menu.newSession"), icon: icon("plus") });
|
|
3725
|
+
items.push({ id: MENU.reveal, label: t("menu.reveal"), icon: icon("folderOpen") });
|
|
3726
|
+
items.push({ id: MENU.copyPath, label: t("menu.copyPath"), icon: icon("copy") });
|
|
3727
|
+
if (registered) {
|
|
3728
|
+
items.push({ type: "separator" });
|
|
3729
|
+
items.push({ id: MENU.renameWorkspace, label: t("dialog.renameWorkspace"), icon: icon("edit") });
|
|
3730
|
+
items.push({ id: MENU.removeWorktree, label: t("worktree.remove"), danger: true, icon: icon("trash") });
|
|
3731
|
+
}
|
|
3732
|
+
pushResetOrder();
|
|
3733
|
+
} else if (target.kind === "session") {
|
|
3734
|
+
items.push({ id: MENU.renameSession, label: t("menu.rename"), icon: icon("edit") });
|
|
3735
|
+
items.push({ id: MENU.archiveSession, label: t("menu.archive"), icon: icon("archive") });
|
|
3736
|
+
items.push({ id: MENU.forkSession, label: t("menu.fork"), icon: icon("branch") });
|
|
3737
|
+
pushResetOrder();
|
|
3738
|
+
} else {
|
|
3739
|
+
const extra = target.extra;
|
|
3740
|
+
if (extra.isGit && extra.mainPath !== void 0) {
|
|
3741
|
+
items.push({ id: MENU.newWorktree, label: t("worktree.create"), icon: icon("plus") });
|
|
3742
|
+
} else if (extra.workspaceId !== void 0) {
|
|
3743
|
+
items.push({ id: MENU.newSession, label: t("menu.newSession"), icon: icon("newChat") });
|
|
3744
|
+
items.push({ id: MENU.renameWorkspace, label: t("dialog.renameWorkspace"), icon: icon("edit") });
|
|
3745
|
+
}
|
|
3746
|
+
if (!extra.isUngrouped) {
|
|
3747
|
+
if (items.length > 0) items.push({ type: "separator" });
|
|
3748
|
+
items.push({ id: MENU.archiveWorkspace, label: t("menu.archiveWorkspace"), icon: icon("archive") });
|
|
3749
|
+
pushResetOrder();
|
|
3750
|
+
}
|
|
3751
|
+
}
|
|
3752
|
+
const handleSelect = (id) => {
|
|
3753
|
+
props.onClose();
|
|
3754
|
+
void (async () => {
|
|
3755
|
+
try {
|
|
3756
|
+
if (id === MENU.resetOrder) {
|
|
3757
|
+
props.onResetOrder();
|
|
3758
|
+
return;
|
|
3759
|
+
}
|
|
3760
|
+
if (target.kind === "worktree") {
|
|
3761
|
+
if (id === MENU.newSession) {
|
|
3762
|
+
props.onNewSession(target.extra);
|
|
3763
|
+
return;
|
|
3764
|
+
}
|
|
3765
|
+
if (id === MENU.reveal) {
|
|
3766
|
+
await props.actions.post(ROUTE_REVEAL, { path: target.extra.path });
|
|
3767
|
+
return;
|
|
3768
|
+
}
|
|
3769
|
+
if (id === MENU.copyPath) {
|
|
3770
|
+
await copyText(target.extra.path);
|
|
3771
|
+
return;
|
|
3772
|
+
}
|
|
3773
|
+
if (id === MENU.renameWorkspace && target.extra.workspaceId !== void 0) {
|
|
3774
|
+
props.onRename({ kind: "workspace", id: target.extra.workspaceId, value: target.title });
|
|
3775
|
+
return;
|
|
3776
|
+
}
|
|
3777
|
+
if (id === MENU.removeWorktree) {
|
|
3778
|
+
props.onRemoveWorktree({ path: target.extra.path, label: target.title });
|
|
3779
|
+
}
|
|
3780
|
+
return;
|
|
3781
|
+
}
|
|
3782
|
+
if (target.kind === "session") {
|
|
3783
|
+
if (id === MENU.renameSession) {
|
|
3784
|
+
props.onRename({ kind: "session", id: target.sessionId, value: target.title });
|
|
3785
|
+
return;
|
|
3786
|
+
}
|
|
3787
|
+
if (id === MENU.archiveSession) {
|
|
3788
|
+
await props.actions.archiveSession(target.sessionId);
|
|
3789
|
+
props.reload();
|
|
3790
|
+
return;
|
|
3791
|
+
}
|
|
3792
|
+
if (id === MENU.forkSession) {
|
|
3793
|
+
await props.actions.forkSession(target.sessionId);
|
|
3794
|
+
props.reload();
|
|
3795
|
+
}
|
|
3796
|
+
return;
|
|
3797
|
+
}
|
|
3798
|
+
if (id === MENU.newWorktree && target.extra.mainPath !== void 0) {
|
|
3799
|
+
props.onCreateWorktree({
|
|
3800
|
+
repoPath: target.extra.mainPath,
|
|
3801
|
+
baseCandidates: props.collectBaseCandidates(target.extra.mainPath),
|
|
3802
|
+
label: target.title
|
|
3803
|
+
});
|
|
3804
|
+
return;
|
|
3805
|
+
}
|
|
3806
|
+
if (id === MENU.newSession && target.extra.workspaceId !== void 0) {
|
|
3807
|
+
props.actions.startSession(target.extra.workspaceId, SAME_LOCATION_START_SESSION);
|
|
3808
|
+
props.reload();
|
|
3809
|
+
return;
|
|
3810
|
+
}
|
|
3811
|
+
if (id === MENU.renameWorkspace && target.extra.workspaceId !== void 0) {
|
|
3812
|
+
props.onRename({ kind: "workspace", id: target.extra.workspaceId, value: target.title });
|
|
3813
|
+
return;
|
|
3814
|
+
}
|
|
3815
|
+
if (id === MENU.archiveWorkspace && !target.extra.isUngrouped) {
|
|
3816
|
+
const displayPath = target.extra.path ?? target.extra.mainPath;
|
|
3817
|
+
archiveWorkspaceClient({
|
|
3818
|
+
key: target.extra.projectKey,
|
|
3819
|
+
title: target.title,
|
|
3820
|
+
...displayPath === void 0 ? {} : { path: displayPath },
|
|
3821
|
+
isGit: target.extra.isGit,
|
|
3822
|
+
archivedAt: Date.now()
|
|
3823
|
+
});
|
|
3824
|
+
try {
|
|
3825
|
+
await props.actions.post(ROUTE_TREE, { archiveProjectKey: target.extra.projectKey });
|
|
3826
|
+
} catch {
|
|
3827
|
+
}
|
|
3828
|
+
props.reload();
|
|
3829
|
+
return;
|
|
3830
|
+
}
|
|
3831
|
+
if (id === MENU.copyPath && target.extra.mainPath !== void 0) {
|
|
3832
|
+
await copyText(target.extra.mainPath);
|
|
3833
|
+
}
|
|
3834
|
+
} catch (error) {
|
|
3835
|
+
props.setLoadError(error instanceof Error ? error.message : t("error.load"));
|
|
3836
|
+
}
|
|
3837
|
+
})();
|
|
3838
|
+
};
|
|
3839
|
+
return jsx(P.Menu, {
|
|
3840
|
+
open: true,
|
|
3841
|
+
portal: true,
|
|
3842
|
+
anchor: jsx("span", { style: { display: "inline-block", width: 0, height: 0 } }),
|
|
3843
|
+
getAnchorRect,
|
|
3844
|
+
items,
|
|
3845
|
+
onClose: props.onClose,
|
|
3846
|
+
onSelect: handleSelect
|
|
3847
|
+
});
|
|
3848
|
+
}
|
|
3849
|
+
function collectBaseCandidates(view, repoPath) {
|
|
3850
|
+
const target = normalizeRepoKey(repoPath);
|
|
3851
|
+
if (target === void 0) return [];
|
|
3852
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3853
|
+
for (const extra of view.worktrees.values()) {
|
|
3854
|
+
if (extra.repoPath === void 0 || normalizeRepoKey(extra.repoPath) !== target) continue;
|
|
3855
|
+
for (const branch of extra.baseCandidates) seen.add(branch);
|
|
3856
|
+
}
|
|
3857
|
+
return [...seen];
|
|
3858
|
+
}
|
|
3859
|
+
function normalizeRepoKey(path) {
|
|
3860
|
+
const trimmed = path.replace(/[/\\]+$/, "");
|
|
3861
|
+
return trimmed === "" ? void 0 : trimmed.toLowerCase();
|
|
3862
|
+
}
|
|
3863
|
+
function buildTreeView(tree, input) {
|
|
3864
|
+
const worktrees = /* @__PURE__ */ new Map();
|
|
3865
|
+
const projects = /* @__PURE__ */ new Map();
|
|
3866
|
+
const worktreeOwner = /* @__PURE__ */ new Map();
|
|
3867
|
+
if (tree === null) return { rows: [], worktrees, projects, worktreeOwner };
|
|
3868
|
+
for (const project of tree.projects) {
|
|
3869
|
+
const projectKey = `p:${project.key}`;
|
|
3870
|
+
const branchPool = project.worktrees.map((node) => node.branch).filter((branch) => typeof branch === "string" && branch !== "");
|
|
3871
|
+
const firstWorkspaceId = workspaceIdFromProjectKey(project.key) ?? project.worktrees.find((node) => node.workspaceId !== void 0)?.workspaceId;
|
|
3872
|
+
const displayPath = project.mainPath ?? project.worktrees[0]?.path ?? project.flatSessions[0]?.cwd;
|
|
3873
|
+
projects.set(projectKey, {
|
|
3874
|
+
projectKey: project.key,
|
|
3875
|
+
isGit: project.isGit === true,
|
|
3876
|
+
isUngrouped: project.key === UNGROUPED_KEY,
|
|
3877
|
+
...project.mainPath === void 0 ? {} : { mainPath: project.mainPath },
|
|
3878
|
+
...displayPath === void 0 ? {} : { path: displayPath },
|
|
3879
|
+
...firstWorkspaceId === void 0 ? {} : { workspaceId: firstWorkspaceId }
|
|
3880
|
+
});
|
|
3881
|
+
if (project.isGit !== true) continue;
|
|
3882
|
+
const repoPath = project.mainPath;
|
|
3883
|
+
for (const node of project.worktrees) {
|
|
3884
|
+
const key = `${PREFIX_WORKTREE}${node.path}`;
|
|
3885
|
+
worktreeOwner.set(key, project.key);
|
|
3886
|
+
worktrees.set(key, {
|
|
3887
|
+
path: node.path,
|
|
3888
|
+
...repoPath === void 0 ? {} : { repoPath },
|
|
3889
|
+
baseCandidates: branchPool.filter((branch) => branch !== node.branch),
|
|
3890
|
+
...node.workspaceId === void 0 ? {} : { workspaceId: node.workspaceId }
|
|
3891
|
+
});
|
|
3892
|
+
}
|
|
3893
|
+
}
|
|
3894
|
+
const rows = buildRows(input);
|
|
3895
|
+
return { rows, worktrees, projects, worktreeOwner };
|
|
3896
|
+
}
|
|
3897
|
+
function defaultTitleOf(session) {
|
|
3898
|
+
if (typeof session.title === "string" && session.title !== "") return session.title;
|
|
3899
|
+
const base = baseName(session.cwd ?? "");
|
|
3900
|
+
return base !== "" ? base : session.sessionId;
|
|
3901
|
+
}
|
|
3902
|
+
function mergeArchivedWorkspaceItems(localMap, serverList) {
|
|
3903
|
+
const merged = /* @__PURE__ */ new Map();
|
|
3904
|
+
for (const [key, item] of Object.entries(localMap)) {
|
|
3905
|
+
merged.set(key, item);
|
|
3906
|
+
}
|
|
3907
|
+
if (Array.isArray(serverList)) {
|
|
3908
|
+
for (const item of serverList) {
|
|
3909
|
+
if (typeof item?.key === "string" && item.key !== "" && !merged.has(item.key)) {
|
|
3910
|
+
merged.set(item.key, item);
|
|
3911
|
+
}
|
|
3912
|
+
}
|
|
3913
|
+
}
|
|
3914
|
+
return [...merged.values()].sort(
|
|
3915
|
+
(a, b) => b.archivedAt !== a.archivedAt ? b.archivedAt - a.archivedAt : a.key.localeCompare(b.key)
|
|
3916
|
+
);
|
|
3917
|
+
}
|
|
3918
|
+
function ArchivedWorkspacesSettingItem(props) {
|
|
3919
|
+
const seat = props?.t;
|
|
3920
|
+
const t = typeof seat === "function" ? createSeatT(seat) : FALLBACK_T;
|
|
3921
|
+
const [items, setItems] = (0, import_react.useState)(
|
|
3922
|
+
() => mergeArchivedWorkspaceItems(readArchivedProjectsMap())
|
|
3923
|
+
);
|
|
3924
|
+
const [busyKey, setBusyKey] = (0, import_react.useState)(null);
|
|
3925
|
+
const [expanded, setExpanded] = (0, import_react.useState)(false);
|
|
3926
|
+
const refresh = (0, import_react.useCallback)(() => {
|
|
3927
|
+
const localMap = readArchivedProjectsMap();
|
|
3928
|
+
setItems(mergeArchivedWorkspaceItems(localMap));
|
|
3929
|
+
void fetch(ROUTE_TREE, {
|
|
3930
|
+
method: "POST",
|
|
3931
|
+
headers: { "content-type": "application/json" },
|
|
3932
|
+
body: "{}"
|
|
3933
|
+
}).then(async (res) => await res.json()).then((body) => {
|
|
3934
|
+
const latestLocal = readArchivedProjectsMap();
|
|
3935
|
+
const serverList = Array.isArray(body?.archivedProjects) ? body.archivedProjects : void 0;
|
|
3936
|
+
setItems(mergeArchivedWorkspaceItems(latestLocal, serverList));
|
|
3937
|
+
}).catch(() => {
|
|
3938
|
+
});
|
|
3939
|
+
}, []);
|
|
3940
|
+
(0, import_react.useEffect)(() => {
|
|
3941
|
+
refresh();
|
|
3942
|
+
archiveListeners.add(refresh);
|
|
3943
|
+
return () => {
|
|
3944
|
+
archiveListeners.delete(refresh);
|
|
3945
|
+
};
|
|
3946
|
+
}, [refresh]);
|
|
3947
|
+
const restore = (projectKey) => {
|
|
3948
|
+
setBusyKey(projectKey);
|
|
3949
|
+
unarchiveWorkspaceByKeyClient(projectKey);
|
|
3950
|
+
void fetch(ROUTE_TREE, {
|
|
3951
|
+
method: "POST",
|
|
3952
|
+
headers: { "content-type": "application/json" },
|
|
3953
|
+
body: JSON.stringify({ unarchiveProjectKey: projectKey })
|
|
3954
|
+
}).then(async (res) => await res.json()).then((body) => {
|
|
3955
|
+
const latestLocal = readArchivedProjectsMap();
|
|
3956
|
+
const serverList = Array.isArray(body?.archivedProjects) ? body.archivedProjects : void 0;
|
|
3957
|
+
setItems(mergeArchivedWorkspaceItems(latestLocal, serverList));
|
|
3958
|
+
notifyArchiveWorkspaceChanged();
|
|
3959
|
+
}).catch(() => {
|
|
3960
|
+
}).finally(() => {
|
|
3961
|
+
setBusyKey(null);
|
|
3962
|
+
});
|
|
3963
|
+
};
|
|
3964
|
+
return jsxs("div", {
|
|
3965
|
+
style: {
|
|
3966
|
+
display: "flex",
|
|
3967
|
+
flexDirection: "column",
|
|
3968
|
+
gap: 10,
|
|
3969
|
+
padding: "12px 0",
|
|
3970
|
+
color: "var(--dsw-alias-label-primary)"
|
|
3971
|
+
},
|
|
3972
|
+
children: [
|
|
3973
|
+
jsxs("div", {
|
|
3974
|
+
key: "header",
|
|
3975
|
+
role: "button",
|
|
3976
|
+
tabIndex: 0,
|
|
3977
|
+
"aria-expanded": expanded,
|
|
3978
|
+
onClick: () => {
|
|
3979
|
+
setExpanded((value) => !value);
|
|
3980
|
+
},
|
|
3981
|
+
onKeyDown: (event) => {
|
|
3982
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
3983
|
+
event.preventDefault();
|
|
3984
|
+
setExpanded((value) => !value);
|
|
3985
|
+
}
|
|
3986
|
+
},
|
|
3987
|
+
style: {
|
|
3988
|
+
display: "flex",
|
|
3989
|
+
alignItems: "center",
|
|
3990
|
+
gap: 10,
|
|
3991
|
+
cursor: "pointer",
|
|
3992
|
+
userSelect: "none"
|
|
3993
|
+
},
|
|
3994
|
+
children: [
|
|
3995
|
+
jsxs("div", {
|
|
3996
|
+
key: "labels",
|
|
3997
|
+
style: { display: "flex", flexDirection: "column", gap: 2, minWidth: 0, flex: 1 },
|
|
3998
|
+
children: [
|
|
3999
|
+
jsx("div", {
|
|
4000
|
+
key: "title",
|
|
4001
|
+
style: { fontSize: 14, fontWeight: 500, lineHeight: "20px" },
|
|
4002
|
+
children: t("settings.archivedWorkspaces.title")
|
|
4003
|
+
}),
|
|
4004
|
+
jsx("div", {
|
|
4005
|
+
key: "desc",
|
|
4006
|
+
style: dimText(12),
|
|
4007
|
+
children: t("settings.archivedWorkspaces.description")
|
|
4008
|
+
})
|
|
4009
|
+
]
|
|
4010
|
+
}),
|
|
4011
|
+
jsxs("div", {
|
|
4012
|
+
key: "meta",
|
|
4013
|
+
style: { display: "flex", alignItems: "center", gap: 6, flex: "none", ...dimText(12) },
|
|
4014
|
+
children: [
|
|
4015
|
+
jsx("span", {
|
|
4016
|
+
key: "count",
|
|
4017
|
+
children: items.length
|
|
4018
|
+
}),
|
|
4019
|
+
jsx("span", {
|
|
4020
|
+
key: "chevron",
|
|
4021
|
+
style: { display: "inline-flex", alignItems: "center", lineHeight: 0, ...dimText(12) },
|
|
4022
|
+
children: expanded ? icon("chevronDown") : icon("chevronRight")
|
|
4023
|
+
})
|
|
4024
|
+
]
|
|
4025
|
+
})
|
|
4026
|
+
]
|
|
4027
|
+
}),
|
|
4028
|
+
expanded ? items.length === 0 ? jsx("div", {
|
|
4029
|
+
key: "empty",
|
|
4030
|
+
style: {
|
|
4031
|
+
padding: "10px 12px",
|
|
4032
|
+
borderRadius: 8,
|
|
4033
|
+
border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,0.2))",
|
|
4034
|
+
...dimText(12.5)
|
|
4035
|
+
},
|
|
4036
|
+
children: t("settings.archivedWorkspaces.empty")
|
|
4037
|
+
}) : jsx("div", {
|
|
4038
|
+
key: "list",
|
|
4039
|
+
style: {
|
|
4040
|
+
display: "flex",
|
|
4041
|
+
flexDirection: "column",
|
|
4042
|
+
gap: 6
|
|
4043
|
+
},
|
|
4044
|
+
children: items.map(
|
|
4045
|
+
(item) => jsxs("div", {
|
|
4046
|
+
key: item.key,
|
|
4047
|
+
style: {
|
|
4048
|
+
display: "flex",
|
|
4049
|
+
alignItems: "center",
|
|
4050
|
+
justifyContent: "space-between",
|
|
4051
|
+
gap: 10,
|
|
4052
|
+
padding: "8px 12px",
|
|
4053
|
+
borderRadius: 8,
|
|
4054
|
+
border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,0.25))"
|
|
4055
|
+
},
|
|
4056
|
+
children: [
|
|
4057
|
+
jsxs("div", {
|
|
4058
|
+
key: "info",
|
|
4059
|
+
style: { display: "flex", flexDirection: "column", gap: 2, minWidth: 0, flex: 1 },
|
|
4060
|
+
children: [
|
|
4061
|
+
jsx("div", {
|
|
4062
|
+
key: "name",
|
|
4063
|
+
style: {
|
|
4064
|
+
fontSize: 13,
|
|
4065
|
+
fontWeight: 500,
|
|
4066
|
+
overflow: "hidden",
|
|
4067
|
+
textOverflow: "ellipsis",
|
|
4068
|
+
whiteSpace: "nowrap"
|
|
4069
|
+
},
|
|
4070
|
+
children: item.title
|
|
4071
|
+
}),
|
|
4072
|
+
item.path !== void 0 ? jsx("div", {
|
|
4073
|
+
key: "path",
|
|
4074
|
+
style: {
|
|
4075
|
+
...dimText(11.5),
|
|
4076
|
+
overflow: "hidden",
|
|
4077
|
+
textOverflow: "ellipsis",
|
|
4078
|
+
whiteSpace: "nowrap"
|
|
4079
|
+
},
|
|
4080
|
+
children: item.path
|
|
4081
|
+
}) : null
|
|
4082
|
+
].filter(present)
|
|
4083
|
+
}),
|
|
4084
|
+
jsx(P.Button, {
|
|
4085
|
+
key: "restore",
|
|
4086
|
+
variant: "outline",
|
|
4087
|
+
size: "sm",
|
|
4088
|
+
disabled: busyKey === item.key,
|
|
4089
|
+
onClick: () => {
|
|
4090
|
+
restore(item.key);
|
|
4091
|
+
},
|
|
4092
|
+
children: t("settings.archivedWorkspaces.restore")
|
|
4093
|
+
})
|
|
4094
|
+
]
|
|
4095
|
+
})
|
|
4096
|
+
)
|
|
4097
|
+
}) : null
|
|
4098
|
+
]
|
|
4099
|
+
});
|
|
4100
|
+
}
|
|
4101
|
+
|
|
4102
|
+
// src/client.tsx
|
|
4103
|
+
function slotsOf(ctx) {
|
|
4104
|
+
return ctx.slots;
|
|
4105
|
+
}
|
|
4106
|
+
var name = "dsh-worktree-groups";
|
|
4107
|
+
var inject = ["slots"];
|
|
4108
|
+
var SLOT_NAME = "sidebar.workspaces";
|
|
4109
|
+
var SLOT_PRIORITY = -1;
|
|
4110
|
+
async function unarchivePathOnServer(path) {
|
|
4111
|
+
if (typeof path !== "string" || path.trim() === "") return;
|
|
4112
|
+
unarchiveWorkspaceByPathClient(path);
|
|
4113
|
+
try {
|
|
4114
|
+
await fetch("/dsh-worktree-groups/tree", {
|
|
4115
|
+
method: "POST",
|
|
4116
|
+
headers: { "content-type": "application/json" },
|
|
4117
|
+
body: JSON.stringify({ unarchivePath: path })
|
|
4118
|
+
});
|
|
4119
|
+
notifyArchiveWorkspaceChanged();
|
|
4120
|
+
} catch {
|
|
4121
|
+
}
|
|
4122
|
+
}
|
|
4123
|
+
function serviceOf(ctx, name2) {
|
|
4124
|
+
try {
|
|
4125
|
+
return ctx.get(name2);
|
|
4126
|
+
} catch {
|
|
4127
|
+
return void 0;
|
|
4128
|
+
}
|
|
4129
|
+
}
|
|
4130
|
+
function createBridge(ctx) {
|
|
4131
|
+
const uiWorkspace = () => serviceOf(ctx, "uiWorkspace");
|
|
4132
|
+
const workspaces = () => serviceOf(ctx, "workspaces");
|
|
4133
|
+
const sessions = () => serviceOf(ctx, "sessions");
|
|
4134
|
+
return {
|
|
4135
|
+
async pickDirectory() {
|
|
4136
|
+
const desktopPicker = globalThis.__DSH_DIRECTORY_PICKER__;
|
|
4137
|
+
if (typeof desktopPicker?.pick === "function") {
|
|
4138
|
+
const picked = await desktopPicker.pick();
|
|
4139
|
+
return typeof picked === "string" ? picked : null;
|
|
4140
|
+
}
|
|
4141
|
+
const service = uiWorkspace();
|
|
4142
|
+
if (typeof service?.pickDirectory === "function") {
|
|
4143
|
+
const picked = await service.pickDirectory();
|
|
4144
|
+
return typeof picked === "string" ? picked : null;
|
|
4145
|
+
}
|
|
4146
|
+
throw new Error("directory-picker/unavailable");
|
|
4147
|
+
},
|
|
4148
|
+
async createWorkspace(path) {
|
|
4149
|
+
const service = workspaces();
|
|
4150
|
+
if (service === void 0) throw new Error("workspaces service is unavailable");
|
|
4151
|
+
await service.create({ path });
|
|
4152
|
+
await unarchivePathOnServer(path);
|
|
4153
|
+
},
|
|
4154
|
+
async renameWorkspace(workspaceId, title) {
|
|
4155
|
+
const service = workspaces();
|
|
4156
|
+
if (service === void 0) throw new Error("workspaces service is unavailable");
|
|
4157
|
+
await service.rename(workspaceId, title);
|
|
4158
|
+
},
|
|
4159
|
+
async deleteWorkspace(workspaceId) {
|
|
4160
|
+
const service = workspaces();
|
|
4161
|
+
if (service === void 0) throw new Error("workspaces service is unavailable");
|
|
4162
|
+
await service.delete(workspaceId);
|
|
4163
|
+
},
|
|
4164
|
+
openSession(sessionId) {
|
|
4165
|
+
const workspace = uiWorkspace();
|
|
4166
|
+
if (workspace?.openSession !== void 0) {
|
|
4167
|
+
workspace.openSession(sessionId);
|
|
4168
|
+
return;
|
|
4169
|
+
}
|
|
4170
|
+
sessions()?.open?.(sessionId);
|
|
4171
|
+
},
|
|
4172
|
+
/**
|
|
4173
|
+
* 开新会话(2026-10-22 DR1)。
|
|
4174
|
+
*
|
|
4175
|
+
* `options` **必须原样**转发给 `uiWorkspace.startSession(workspaceId, options)`:
|
|
4176
|
+
* 宿主只在第二参**非 undefined** 时走 `createInWorkspace`(按 `summary.cwd === workspace.path`
|
|
4177
|
+
* 复用同目录空白会话),从而保留未发送草稿;漏传第二参会让宿主 `connectBlank(..., undefined)`
|
|
4178
|
+
* 分支每次铸新空白会话,草稿随旧 blank 会话被 `sessionVisible()` 隐藏而"消失"。
|
|
4179
|
+
*/
|
|
4180
|
+
startSession(workspaceId, options) {
|
|
4181
|
+
const workspace = uiWorkspace();
|
|
4182
|
+
if (workspace?.startSession !== void 0) {
|
|
4183
|
+
workspace.startSession(workspaceId, options);
|
|
4184
|
+
return;
|
|
4185
|
+
}
|
|
4186
|
+
void sessions()?.create?.({ workspaceId });
|
|
4187
|
+
},
|
|
4188
|
+
async renameSession(sessionId, title) {
|
|
4189
|
+
const binding = sessions()?.binding?.(sessionId)?.session;
|
|
4190
|
+
if (binding === void 0) throw new Error(`unknown session "${sessionId}"`);
|
|
4191
|
+
const result = await binding.rename(title);
|
|
4192
|
+
if (result?.ok === false) throw new Error(String(result?.error?.message ?? "rename rejected"));
|
|
4193
|
+
},
|
|
4194
|
+
async archiveSession(sessionId) {
|
|
4195
|
+
const service = workspaces();
|
|
4196
|
+
if (service === void 0) throw new Error("workspaces service is unavailable");
|
|
4197
|
+
await service.archiveSession(sessionId);
|
|
4198
|
+
},
|
|
4199
|
+
async forkSession(sessionId) {
|
|
4200
|
+
const workspace = uiWorkspace();
|
|
4201
|
+
if (workspace?.forkSession !== void 0) {
|
|
4202
|
+
await workspace.forkSession(sessionId);
|
|
4203
|
+
return;
|
|
4204
|
+
}
|
|
4205
|
+
const childId = await sessions()?.fork?.({ sessionId, increaseTitle: true });
|
|
4206
|
+
if (typeof childId === "string") {
|
|
4207
|
+
const service = uiWorkspace();
|
|
4208
|
+
if (service?.openSession !== void 0) service.openSession(childId);
|
|
4209
|
+
else sessions()?.open?.(childId);
|
|
4210
|
+
}
|
|
4211
|
+
}
|
|
4212
|
+
};
|
|
4213
|
+
}
|
|
4214
|
+
function apply(ctx) {
|
|
4215
|
+
const bridge = createBridge(ctx);
|
|
4216
|
+
ctx.inject(["locale"], (localeCtx) => {
|
|
4217
|
+
const locale = serviceOf(localeCtx, "locale");
|
|
4218
|
+
if (locale === void 0 || typeof locale.register !== "function") return;
|
|
4219
|
+
try {
|
|
4220
|
+
const dispose = locale.register(LOCALE_NS, { zh });
|
|
4221
|
+
if (typeof dispose === "function") localeCtx.effect(() => dispose, "dsh-worktree-groups: locale dictionary");
|
|
4222
|
+
} catch (error) {
|
|
4223
|
+
console.warn("[dsh-worktree-groups] locale dictionary registration failed:", error);
|
|
4224
|
+
}
|
|
4225
|
+
});
|
|
4226
|
+
const slots = slotsOf(ctx);
|
|
4227
|
+
slots.inject(
|
|
4228
|
+
SLOT_NAME,
|
|
4229
|
+
() => slots.register(
|
|
4230
|
+
{
|
|
4231
|
+
name: SLOT_NAME,
|
|
4232
|
+
// single slot 按 priority 遮蔽(最小者渲染);-1 压过 ui-workspace 的 0。
|
|
4233
|
+
priority: SLOT_PRIORITY,
|
|
4234
|
+
// 路线 3:**自建**新键。官方那个子键(见 DIRECTORY_FLOW_SLOT 上方注释)由
|
|
4235
|
+
// ui-workspace 声明,同键重复声明会抛 `slot "..." is already declared`。
|
|
4236
|
+
children: { [DIRECTORY_FLOW_SLOT]: { kind: "single", scope: "root" } },
|
|
4237
|
+
// 声明 locale 才拿到 `t`(renderer 的 standardKit 按 entry.locale 建 seat)。
|
|
4238
|
+
locale: LOCALE_NS,
|
|
4239
|
+
// 不声明 store:不需要原生分组/排序 store,展开态自管 localStorage。
|
|
4240
|
+
inject: () => ({ bridge })
|
|
4241
|
+
},
|
|
4242
|
+
SidebarBrowser
|
|
4243
|
+
)
|
|
4244
|
+
);
|
|
4245
|
+
ctx.inject(["slots"], (slotsCtx) => {
|
|
4246
|
+
const innerSlots = slotsOf(slotsCtx);
|
|
4247
|
+
innerSlots.inject(
|
|
4248
|
+
"settings.general.item",
|
|
4249
|
+
() => innerSlots.register(
|
|
4250
|
+
{
|
|
4251
|
+
name: "settings.general.item",
|
|
4252
|
+
id: "archived-workspaces",
|
|
4253
|
+
order: 90,
|
|
4254
|
+
locale: LOCALE_NS
|
|
4255
|
+
},
|
|
4256
|
+
ArchivedWorkspacesSettingItem
|
|
4257
|
+
)
|
|
4258
|
+
);
|
|
4259
|
+
});
|
|
4260
|
+
ctx.inject(["workspaces"], (wsCtx) => {
|
|
4261
|
+
const service = serviceOf(wsCtx, "workspaces");
|
|
4262
|
+
if (service === void 0 || typeof service.create !== "function") return;
|
|
4263
|
+
const originalCreate = service.create.bind(service);
|
|
4264
|
+
const wrappedCreate = async (input, ...rest) => {
|
|
4265
|
+
const result = await originalCreate(input, ...rest);
|
|
4266
|
+
const path = typeof input === "string" ? input : typeof input?.path === "string" ? input.path : void 0;
|
|
4267
|
+
if (path !== void 0) {
|
|
4268
|
+
await unarchivePathOnServer(path);
|
|
4269
|
+
}
|
|
4270
|
+
return result;
|
|
4271
|
+
};
|
|
4272
|
+
service.create = wrappedCreate;
|
|
4273
|
+
wsCtx.effect(() => () => {
|
|
4274
|
+
if (service.create === wrappedCreate) {
|
|
4275
|
+
service.create = originalCreate;
|
|
4276
|
+
}
|
|
4277
|
+
}, "dsh-worktree-groups: auto-unarchive workspace on create");
|
|
4278
|
+
});
|
|
4279
|
+
}
|
|
4280
|
+
;return module.exports;}});
|