dsh-sidebar-sessions 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -19,7 +19,6 @@ window.__ModuleLoader__.load({
19
19
  const { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } = React;
20
20
  const inject = ["slots", "sessions", "workspaces", "uiWorkspace", "uiSession", "remote", "remote.schedule"];
21
21
 
22
- const STORE_KEY = "dsh-session-groups.v1";
23
22
  const RECENT_LIMIT = 20;
24
23
 
25
24
  const CSS = `
@@ -68,6 +67,29 @@ window.__ModuleLoader__.load({
68
67
  .dsg-ws-btn{flex:1;display:flex;align-items:center;justify-content:center;height:34px;box-sizing:border-box;border:1px dashed var(--dsw-alias-border-l2,rgba(127,127,127,.25));background:transparent;color:var(--dsw-alias-label-secondary,#6b7280);font-size:13px;line-height:1;border-radius:var(--dsw-radius-sm,8px);cursor:pointer}
69
68
  .dsg-ws-btn:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
70
69
  .dsg-ws-row{display:flex;align-items:center;height:28px;padding:0 8px;font-size:12px;color:var(--dsw-alias-label-tertiary,#9ca3af)}
70
+ .dsg-ws-row{display:flex;align-items:center;height:28px;padding:0 8px;font-size:12px;color:var(--dsw-alias-label-tertiary,#9ca3af)}
71
+ .dsg-consent{margin:0 2px 8px;padding:8px 10px;border:1px solid var(--dsw-alias-state-business-primary,#4d6bfe);border-radius:var(--dsw-radius-md,12px);background:var(--dsw-alias-bg-layer-1,#1a1d21);display:flex;flex-direction:column;gap:6px}
72
+ .dsg-consent-title{font-size:12px;line-height:17px;color:var(--dsw-alias-label-primary,#e5e7eb)}
73
+ .dsg-consent-group{color:var(--dsw-alias-state-business-primary,#4d6bfe);font-weight:600}
74
+ .dsg-consent-note{font-size:11px;line-height:15px;color:var(--dsw-alias-label-tertiary,#9ca3af)}
75
+ .dsg-consent-actions{display:flex;flex-wrap:wrap;gap:6px}
76
+ .dsg-btn{height:26px;padding:0 10px;font-size:12px;line-height:1;border-radius:var(--dsw-radius-s,8px);border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.25));background:transparent;color:var(--dsw-alias-label-primary,#e5e7eb);cursor:pointer}
77
+ .dsg-btn:hover{background:var(--dsw-alias-interactive-bg-hover)}
78
+ .dsg-btn[data-tone="primary"]{border-color:var(--dsw-alias-state-business-primary,#4d6bfe);color:var(--dsw-alias-state-business-primary,#4d6bfe)}
79
+ .dsg-btn[data-tone="ghost"]{border-color:transparent;color:var(--dsw-alias-label-secondary,#6b7280)}
80
+ .dsg-panel{position:fixed;z-index:10000;left:8px;bottom:8px;width:min(380px,calc(100vw - 16px));max-height:min(72vh,600px);overflow:auto;box-sizing:border-box;padding:10px;background:var(--dsw-alias-bg-layer-2,#24272c);border:1px solid var(--dsw-alias-border-l4,rgba(127,127,127,.3));border-radius:var(--dsw-radius-md,12px);box-shadow:0 12px 32px rgba(0,0,0,.32);font-size:12px;color:var(--dsw-alias-label-primary,#e5e7eb);display:flex;flex-direction:column;gap:8px}
81
+ .dsg-panel-title{font-size:13px;font-weight:600;display:flex;align-items:center;gap:6px}
82
+ .dsg-panel-title .dsg-spacer{flex:1}
83
+ .dsg-field{display:flex;flex-direction:column;gap:4px}
84
+ .dsg-field-label{font-size:11px;color:var(--dsw-alias-label-tertiary,#9ca3af)}
85
+ .dsg-input,.dsg-select{height:28px;box-sizing:border-box;padding:0 8px;border-radius:var(--dsw-radius-s,8px);border:1px solid var(--dsw-alias-border-l2,rgba(127,127,127,.25));background:var(--dsw-alias-bg-layer-1,#1a1d21);color:var(--dsw-alias-label-primary,#e5e7eb);font-size:12px}
86
+ .dsg-sched{display:flex;align-items:center;gap:6px;font-size:11px;color:var(--dsw-alias-label-secondary,#6b7280);height:22px}
87
+ .dsg-rule{padding:6px 8px;border-radius:var(--dsw-radius-s,8px);background:var(--dsw-alias-bg-layer-1,#1a1d21);display:flex;flex-direction:column;gap:4px}
88
+ .dsg-rule-head{display:flex;align-items:center;gap:6px;font-size:12px;font-weight:600}
89
+ .dsg-rule-meta{font-size:11px;line-height:15px;color:var(--dsw-alias-label-tertiary,#9ca3af);word-break:break-all}
90
+ .dsg-rule-actions{display:flex;gap:4px;margin-left:auto}
91
+ .dsg-warn{font-size:11px;line-height:15px;padding:6px 8px;border-radius:var(--dsw-radius-s,8px);background:var(--dsw-alias-state-warning-bg,rgba(247,173,49,.12));color:var(--dsw-alias-state-warning-primary,#f7ad31)}
92
+ .dsg-dialog-mask{position:fixed;inset:0;z-index:9999;background:transparent}
71
93
  `;
72
94
 
73
95
  function injectStyles() {
@@ -80,49 +102,203 @@ window.__ModuleLoader__.load({
80
102
  return () => style.remove();
81
103
  }
82
104
 
83
- const EMPTY = { groups: [], assign: {}, collapsed: {}, hiddenWorkspaces: [], activeWorkspace: null, order: {} };
105
+ /* ── 状态由宿主侧持有 ───────────────────────────────────────────────
106
+ * 分组/规则/待确认建议存在宿主的一份 JSON 里(~/.dsh/sidebar-sessions/
107
+ * state.json),Web GUI 与桌面端(dsh-app://app)读同一份:桌面壳把同源
108
+ * 相对路径的请求原样转发给宿主 HTTP 服务,所以这里只发相对 URL。
109
+ * localStorage 只当首屏缓存,以及宿主没注册路由时(老版本)的降级。 */
110
+ const API = "/dsh-sidebar-sessions/api";
111
+ const CACHE_KEY = "dsh-session-groups.cache.v2";
112
+ const LEGACY_KEY = "dsh-session-groups.v1";
113
+
114
+ const EMPTY_STATE = {
115
+ version: 2,
116
+ groups: [],
117
+ assign: {},
118
+ autoDone: {},
119
+ autoAllow: {},
120
+ pending: {},
121
+ rules: [],
122
+ settings: { classifier: { mode: "off", provider: "", model: "" } },
123
+ order: {},
124
+ collapsed: {},
125
+ hiddenWorkspaces: [],
126
+ activeWorkspace: null,
127
+ imported: false,
128
+ online: false,
129
+ };
130
+
131
+ function asObject(value) {
132
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
133
+ }
134
+
135
+ function asArray(value) {
136
+ return Array.isArray(value) ? value : [];
137
+ }
84
138
 
85
- function readStore() {
139
+ function mergeState(raw, online) {
140
+ const source = asObject(raw);
141
+ const settings = asObject(source.settings);
142
+ const classifier = asObject(settings.classifier);
143
+ return {
144
+ ...EMPTY_STATE,
145
+ groups: asArray(source.groups)
146
+ .filter((group) => group && group.id && group.name)
147
+ .map((group) => ({ id: String(group.id), name: String(group.name) })),
148
+ assign: { ...asObject(source.assign) },
149
+ autoDone: { ...asObject(source.autoDone) },
150
+ autoAllow: { ...asObject(source.autoAllow) },
151
+ pending: { ...asObject(source.pending) },
152
+ rules: asArray(source.rules)
153
+ .filter((rule) => rule && rule.groupName)
154
+ .map((rule) => ({
155
+ id: String(rule.id || ""),
156
+ groupName: String(rule.groupName),
157
+ any: asArray(rule.any).map(String),
158
+ none: asArray(rule.none).map(String),
159
+ scheduleIds: asArray(rule.scheduleIds).map(String),
160
+ scheduleTitles: asArray(rule.scheduleTitles).map(String),
161
+ })),
162
+ settings: {
163
+ classifier: {
164
+ mode: classifier.mode === "llm" ? "llm" : "off",
165
+ provider: String(classifier.provider || ""),
166
+ model: String(classifier.model || ""),
167
+ },
168
+ },
169
+ order: { ...asObject(source.order) },
170
+ collapsed: { ...asObject(source.collapsed) },
171
+ hiddenWorkspaces: asArray(source.hiddenWorkspaces).map(String),
172
+ activeWorkspace:
173
+ source.activeWorkspace === null || source.activeWorkspace === undefined ? null : String(source.activeWorkspace),
174
+ imported: source.imported === true,
175
+ online: online === undefined ? false : online === true,
176
+ };
177
+ }
178
+
179
+ function readCache() {
86
180
  try {
87
- const raw = window.localStorage.getItem(STORE_KEY);
88
- if (!raw) return { ...EMPTY };
89
- const parsed = JSON.parse(raw);
90
- return {
91
- groups: Array.isArray(parsed.groups) ? parsed.groups : [],
92
- assign: parsed.assign && typeof parsed.assign === "object" ? parsed.assign : {},
93
- collapsed: parsed.collapsed && typeof parsed.collapsed === "object" ? parsed.collapsed : {},
94
- hiddenWorkspaces: Array.isArray(parsed.hiddenWorkspaces) ? parsed.hiddenWorkspaces : [],
95
- activeWorkspace: typeof parsed.activeWorkspace === "string" ? parsed.activeWorkspace : null,
96
- order: parsed.order && typeof parsed.order === "object" ? parsed.order : {},
97
- };
181
+ const raw = window.localStorage.getItem(CACHE_KEY);
182
+ if (!raw) return { ...EMPTY_STATE };
183
+ return mergeState(JSON.parse(raw), false);
184
+ } catch {
185
+ return { ...EMPTY_STATE };
186
+ }
187
+ }
188
+
189
+ function writeCache(state) {
190
+ try {
191
+ window.localStorage.setItem(CACHE_KEY, JSON.stringify({ ...state, online: false }));
192
+ } catch {}
193
+ }
194
+
195
+ function readLegacy() {
196
+ try {
197
+ const raw = window.localStorage.getItem(LEGACY_KEY);
198
+ return raw ? JSON.parse(raw) : undefined;
98
199
  } catch {
99
- return { ...EMPTY };
200
+ return undefined;
100
201
  }
101
202
  }
102
203
 
103
- function writeStore(next) {
204
+ async function request(path, init) {
205
+ const response = await fetch(API + path, { credentials: "same-origin", cache: "no-store", ...init });
206
+ const text = await response.text();
207
+ let value = {};
104
208
  try {
105
- window.localStorage.setItem(STORE_KEY, JSON.stringify(next));
209
+ value = text ? JSON.parse(text) : {};
106
210
  } catch {}
211
+ if (!response.ok || value.ok === false) throw new Error(String((value && value.error) || "HTTP " + response.status));
212
+ return value;
213
+ }
214
+
215
+ async function apiOp(payload) {
216
+ return request("/op", {
217
+ method: "POST",
218
+ headers: { "content-type": "application/json", "x-dsg-request": "1" },
219
+ body: JSON.stringify(payload),
220
+ });
107
221
  }
108
222
 
109
223
  const store = (() => {
110
- let state = readStore();
224
+ let state = readCache();
111
225
  const listeners = new Set();
226
+ let lastSyncAt = 0;
227
+ let lastDigest = "";
228
+ let legacyTried = false;
229
+ let meta = { statePath: "" };
112
230
  const emit = () => {
113
231
  for (const fn of listeners) fn();
114
232
  };
233
+ const commit = (next, online) => {
234
+ state = { ...next, online: online === undefined ? state.online : online === true };
235
+ writeCache(state);
236
+ emit();
237
+ };
115
238
  return {
116
239
  get: () => state,
117
- set(next) {
118
- state = next;
119
- writeStore(state);
120
- emit();
121
- },
240
+ meta: () => meta,
241
+ commit,
122
242
  subscribe(fn) {
123
243
  listeners.add(fn);
124
244
  return () => listeners.delete(fn);
125
245
  },
246
+ async load() {
247
+ try {
248
+ const result = await request("/state");
249
+ meta = { statePath: String((result.meta && result.meta.statePath) || "") };
250
+ commit(mergeState(result.state), true);
251
+ return true;
252
+ } catch {
253
+ if (state.online) commit({ ...state }, false);
254
+ return false;
255
+ }
256
+ },
257
+ /** 把会话/定时任务快照交给宿主:判定与写入只有宿主一处。 */
258
+ async sync(sessions, schedules) {
259
+ const digest =
260
+ sessions.map((row) => row.id + "\u0001" + row.title).join("\u0002") +
261
+ "\u0003" +
262
+ schedules.map((row) => row.id + ":" + (row.targetSessionId || "") + ":" + (row.deliveredAt || "")).join("\u0002");
263
+ if (digest === lastDigest && Date.now() - lastSyncAt < 15000) return;
264
+ lastDigest = digest;
265
+ lastSyncAt = Date.now();
266
+ try {
267
+ const result = await request("/sync", {
268
+ method: "POST",
269
+ headers: { "content-type": "application/json", "x-dsg-request": "1" },
270
+ body: JSON.stringify({ sessions, schedules }),
271
+ });
272
+ meta = { statePath: String((result.meta && result.meta.statePath) || meta.statePath) };
273
+ commit(mergeState(result.state), true);
274
+ } catch {
275
+ if (state.online) commit({ ...state }, false);
276
+ }
277
+ },
278
+ async op(payload) {
279
+ const result = await apiOp(payload);
280
+ commit(mergeState(result.state), true);
281
+ return result;
282
+ },
283
+ /** v1(纯 localStorage 时代)的分组只在第一次接上宿主时导入一次。 */
284
+ async importLegacy() {
285
+ if (legacyTried || state.imported) return;
286
+ legacyTried = true;
287
+ const legacy = readLegacy();
288
+ if (!legacy || !asArray(legacy.groups).length) return;
289
+ try {
290
+ const result = await apiOp({ op: "import", state: legacy });
291
+ commit(mergeState(result.state), true);
292
+ } catch {}
293
+ },
294
+ async models() {
295
+ try {
296
+ const result = await request("/models");
297
+ return asArray(result.providers);
298
+ } catch {
299
+ return [];
300
+ }
301
+ },
126
302
  };
127
303
  })();
128
304
 
@@ -130,9 +306,9 @@ window.__ModuleLoader__.load({
130
306
  return useSyncExternalStore(store.subscribe, store.get, store.get);
131
307
  }
132
308
 
133
- function newGroupId() {
134
- return "g_" + Math.random().toString(36).slice(2, 9);
135
- }
309
+ /* 分组判定(规则匹配、定时任务绑定、许可状态)全在宿主侧:客户端只
310
+ * 负责把那批会话/定时任务的快照送过去,并渲染宿主返回的待确认建议。 */
311
+
136
312
 
137
313
  function titleOf(row, id) {
138
314
  return String(row?.displayTitle || row?.title || id);
@@ -329,6 +505,365 @@ window.__ModuleLoader__.load({
329
505
  return h(RegionBoundary, null, h(Region, props));
330
506
  }
331
507
 
508
+ /* 许可条:自动分类永远先问人。四个选项就是产品约定:
509
+ * 是 / 否 / 始终允许该组别(以后同组不再问)/ 让我自己决定(手选)。 */
510
+ function ConsentBar(props) {
511
+ const { title, proposal, pendingCount, onAnswer, onPick } = props;
512
+ const reason = proposal.reason === "llm" ? "模型判断" : proposal.reason === "agent" ? "agent 建议" : "命中规则";
513
+ return h(
514
+ "div",
515
+ { className: "dsg-consent", "data-dsg": "consent" },
516
+ h(
517
+ "div",
518
+ { className: "dsg-consent-title" },
519
+ "「",
520
+ title,
521
+ "」建议归入 ",
522
+ h("span", { className: "dsg-consent-group" }, "「" + proposal.groupName + "」"),
523
+ h("span", { className: "dsg-consent-note" }, " · " + reason)
524
+ ),
525
+ pendingCount > 1 ? h("div", { className: "dsg-consent-note" }, `另有 ${pendingCount - 1} 条待确认,先处理这一条`) : null,
526
+ h(
527
+ "div",
528
+ { className: "dsg-consent-actions" },
529
+ h("button", { className: "dsg-btn", "data-tone": "primary", onClick: () => onAnswer("yes") }, "是"),
530
+ h("button", { className: "dsg-btn", onClick: () => onAnswer("no") }, "否"),
531
+ h("button", { className: "dsg-btn", onClick: () => onAnswer("always") }, "始终允许该组别"),
532
+ h("button", { className: "dsg-btn", "data-tone": "ghost", onClick: onPick }, "让我自己决定")
533
+ )
534
+ );
535
+ }
536
+
537
+ /* Electron 没有 window.prompt,桌面端里它直接抛错——所以文本输入也必须自绘。 */
538
+ function TextDialog(props) {
539
+ const { state, onCancel } = props;
540
+ const [value, setValue] = useState(state.value || "");
541
+ const inputRef = useRef(null);
542
+ useEffect(() => {
543
+ const el = inputRef.current;
544
+ if (!el) return;
545
+ el.focus();
546
+ try {
547
+ el.select();
548
+ } catch {}
549
+ }, []);
550
+ const submit = () => {
551
+ const text = String(value || "").trim();
552
+ if (!text) return;
553
+ onCancel();
554
+ state.onOk(text);
555
+ };
556
+ return h(
557
+ "div",
558
+ { className: "dsg-dialog-mask", onClick: onCancel },
559
+ h(
560
+ "div",
561
+ { className: "dsg-panel", role: "dialog", "aria-label": state.title, onClick: (e) => e.stopPropagation() },
562
+ h("div", { className: "dsg-panel-title" }, state.title),
563
+ h("input", {
564
+ ref: inputRef,
565
+ className: "dsg-input",
566
+ value,
567
+ placeholder: state.placeholder,
568
+ onChange: (e) => setValue(e.target.value),
569
+ onKeyDown: (e) => {
570
+ if (e.key === "Enter") submit();
571
+ if (e.key === "Escape") onCancel();
572
+ },
573
+ }),
574
+ h(
575
+ "div",
576
+ { className: "dsg-consent-actions" },
577
+ h("button", { className: "dsg-btn", "data-tone": "primary", onClick: submit }, "确定"),
578
+ h("button", { className: "dsg-btn", "data-tone": "ghost", onClick: onCancel }, "取消")
579
+ )
580
+ )
581
+ );
582
+ }
583
+
584
+ function ConfirmDialog(props) {
585
+ const { state, onCancel } = props;
586
+ return h(
587
+ "div",
588
+ { className: "dsg-dialog-mask", onClick: onCancel },
589
+ h(
590
+ "div",
591
+ { className: "dsg-panel", role: "dialog", "aria-label": state.title, onClick: (e) => e.stopPropagation() },
592
+ h("div", { className: "dsg-panel-title" }, state.title),
593
+ h("div", { className: "dsg-consent-note" }, state.body),
594
+ h(
595
+ "div",
596
+ { className: "dsg-consent-actions" },
597
+ h(
598
+ "button",
599
+ {
600
+ className: "dsg-btn",
601
+ "data-tone": "primary",
602
+ onClick: () => {
603
+ onCancel();
604
+ state.onOk();
605
+ },
606
+ },
607
+ "删除"
608
+ ),
609
+ h("button", { className: "dsg-btn", "data-tone": "ghost", onClick: onCancel }, "取消")
610
+ )
611
+ )
612
+ );
613
+ }
614
+
615
+ function GroupPickerPanel(props) {
616
+ const { title, groups, onPick, onNew, onCancel } = props;
617
+ return h(
618
+ "div",
619
+ { className: "dsg-dialog-mask", onClick: onCancel },
620
+ h(
621
+ "div",
622
+ { className: "dsg-panel", role: "dialog", "aria-label": "选择分组", onClick: (e) => e.stopPropagation() },
623
+ h("div", { className: "dsg-panel-title" }, "把「" + title + "」放到:"),
624
+ h(
625
+ "div",
626
+ { className: "dsg-consent-actions", style: { flexDirection: "column", alignItems: "stretch" } },
627
+ groups.map((group) =>
628
+ h("button", { key: group.id, className: "dsg-btn", style: { textAlign: "left" }, onClick: () => onPick(group.id) }, group.name)),
629
+ h("button", { className: "dsg-btn", style: { textAlign: "left" }, onClick: () => onPick(null) }, "未分组"),
630
+ h("button", { className: "dsg-btn", "data-tone": "ghost", style: { textAlign: "left" }, onClick: onNew }, "+ 新建分组…")
631
+ ),
632
+ h("div", { className: "dsg-consent-actions" },
633
+ h("button", { className: "dsg-btn", "data-tone": "ghost", onClick: onCancel }, "取消"))
634
+ )
635
+ );
636
+ }
637
+ /*
638
+ * 规则面板:定时任务可以按任务绑定(按 id,不再靠标题猜),关键词只是兜底。
639
+ * “始终允许”白名单也在这里撤销;状态文件路径直接显示,方便备份。
640
+ */
641
+ function RulesPanel(props) {
642
+ const { groups, rules, schedules, autoAllow, classifier, statePath, online, onOp, onClose, loadModels } = props;
643
+ const [draft, setDraft] = useState({ id: "", groupName: "", keywords: "", scheduleIds: [] });
644
+ const [mode, setMode] = useState(classifier.mode);
645
+ const [provider, setProvider] = useState(classifier.provider);
646
+ const [model, setModel] = useState(classifier.model);
647
+ const [providers, setProviders] = useState([]);
648
+
649
+ useEffect(() => {
650
+ let alive = true;
651
+ void Promise.resolve(loadModels()).then((rows) => {
652
+ if (alive) setProviders(Array.isArray(rows) ? rows : []);
653
+ });
654
+ return () => {
655
+ alive = false;
656
+ };
657
+ }, [loadModels]);
658
+
659
+ const providerRow = providers.find((row) => row.id === provider);
660
+ const modelRows = providerRow ? providerRow.models || [] : [];
661
+ const scheduled = (schedules || []).filter((row) => row.id);
662
+ const canSaveRule = draft.groupName.trim().length > 0 && (draft.keywords.trim().length > 0 || draft.scheduleIds.length > 0);
663
+
664
+ const startEdit = (rule) =>
665
+ setDraft({
666
+ id: rule.id,
667
+ groupName: rule.groupName,
668
+ keywords: (rule.any || []).join(","),
669
+ scheduleIds: [...(rule.scheduleIds || [])],
670
+ });
671
+ const resetDraft = () => setDraft({ id: "", groupName: "", keywords: "", scheduleIds: [] });
672
+ const saveRule = () => {
673
+ if (!canSaveRule) return;
674
+ onOp({
675
+ op: "rule.upsert",
676
+ rule: {
677
+ id: draft.id,
678
+ groupName: draft.groupName.trim(),
679
+ any: draft.keywords.split(/[,,\n]/),
680
+ scheduleIds: draft.scheduleIds,
681
+ },
682
+ });
683
+ resetDraft();
684
+ };
685
+ const toggleSchedule = (id) =>
686
+ setDraft((current) => ({
687
+ ...current,
688
+ scheduleIds: current.scheduleIds.includes(id)
689
+ ? current.scheduleIds.filter((entry) => entry !== id)
690
+ : current.scheduleIds.concat([id]),
691
+ }));
692
+
693
+ return h(
694
+ "div",
695
+ { className: "dsg-panel", role: "dialog", "aria-label": "自动归组设置", "data-dsg": "rules" },
696
+ h(
697
+ "div",
698
+ { className: "dsg-panel-title" },
699
+ "自动归组",
700
+ h("span", { className: "dsg-spacer" }),
701
+ h("button", { className: "dsg-icon", title: "关闭", onClick: onClose }, "✕")
702
+ ),
703
+ online
704
+ ? null
705
+ : h("div", { className: "dsg-warn" }, "宿主端未连接:本次改动只进浏览器缓存,不会跨端同步。"),
706
+
707
+ h(
708
+ "div",
709
+ { className: "dsg-field" },
710
+ h("div", { className: "dsg-field-label" }, "规则(定时任务绑定优先于关键词;命中后先问再归组)"),
711
+ rules.length === 0
712
+ ? h("div", { className: "dsg-consent-note" }, "还没有规则。新会话就只能靠模型兜底或手动分组。")
713
+ : rules.map((rule) =>
714
+ h(
715
+ "div",
716
+ { key: rule.id, className: "dsg-rule" },
717
+ h(
718
+ "div",
719
+ { className: "dsg-rule-head" },
720
+ rule.groupName,
721
+ h(
722
+ "span",
723
+ { className: "dsg-rule-actions" },
724
+ h("button", { className: "dsg-btn", style: { height: 22, fontSize: 11 }, onClick: () => startEdit(rule) }, "改"),
725
+ h("button", { className: "dsg-btn", style: { height: 22, fontSize: 11 }, onClick: () => onOp({ op: "rule.delete", ruleId: rule.id }) }, "删")
726
+ )
727
+ ),
728
+ h(
729
+ "div",
730
+ { className: "dsg-rule-meta" },
731
+ (rule.any || []).length ? "关键词:" + rule.any.join("、") : "无关键词",
732
+ (rule.scheduleIds || []).length
733
+ ? " · 定时任务:" +
734
+ rule.scheduleIds
735
+ .map((id) => {
736
+ const found = scheduled.find((row) => row.id === id);
737
+ return found && found.title ? found.title : id;
738
+ })
739
+ .join("、")
740
+ : ""
741
+ )
742
+ )
743
+ )
744
+ ),
745
+
746
+ h(
747
+ "div",
748
+ { className: "dsg-field" },
749
+ h("div", { className: "dsg-field-label" }, draft.id ? "编辑规则" : "新增规则"),
750
+ h("input", {
751
+ className: "dsg-input",
752
+ list: "dsg-group-names",
753
+ value: draft.groupName,
754
+ placeholder: "分组名(可选已有或新建)",
755
+ onChange: (e) => setDraft({ ...draft, groupName: e.target.value }),
756
+ }),
757
+ h("datalist", { id: "dsg-group-names" }, groups.map((group) => h("option", { key: group.id, value: group.name }))),
758
+ h("input", {
759
+ className: "dsg-input",
760
+ value: draft.keywords,
761
+ placeholder: "关键词,逗号分隔(可留空)",
762
+ onChange: (e) => setDraft({ ...draft, keywords: e.target.value }),
763
+ }),
764
+ scheduled.length
765
+ ? h(
766
+ "div",
767
+ { style: { display: "flex", flexDirection: "column", gap: 2, maxHeight: 132, overflow: "auto" } },
768
+ scheduled.map((row) =>
769
+ h(
770
+ "label",
771
+ { key: row.id, className: "dsg-sched" },
772
+ h("input", {
773
+ type: "checkbox",
774
+ checked: draft.scheduleIds.includes(row.id),
775
+ onChange: () => toggleSchedule(row.id),
776
+ }),
777
+ row.title || row.id
778
+ )
779
+ )
780
+ )
781
+ : null,
782
+ h(
783
+ "div",
784
+ { className: "dsg-consent-actions" },
785
+ h("button", { className: "dsg-btn", "data-tone": "primary", disabled: !canSaveRule, onClick: saveRule }, draft.id ? "保存修改" : "添加规则"),
786
+ draft.id ? h("button", { className: "dsg-btn", "data-tone": "ghost", onClick: resetDraft }, "取消编辑") : null
787
+ )
788
+ ),
789
+
790
+ h(
791
+ "div",
792
+ { className: "dsg-field" },
793
+ h("div", { className: "dsg-field-label" }, "规则没命中时让模型判断(默认关,每次最多 3 个新会话)"),
794
+ h(
795
+ "div",
796
+ { className: "dsg-consent-actions" },
797
+ h("button", { className: "dsg-btn", "data-tone": mode === "off" ? "primary" : undefined, onClick: () => setMode("off") }, "关闭"),
798
+ h("button", { className: "dsg-btn", "data-tone": mode === "llm" ? "primary" : undefined, onClick: () => setMode("llm") }, "模型判断")
799
+ ),
800
+ mode === "llm"
801
+ ? h(
802
+ React.Fragment,
803
+ null,
804
+ h(
805
+ "select",
806
+ {
807
+ className: "dsg-select",
808
+ value: provider,
809
+ onChange: (e) => {
810
+ setProvider(e.target.value);
811
+ setModel("");
812
+ },
813
+ },
814
+ h("option", { value: "" }, "选择提供方"),
815
+ providers.map((row) => h("option", { key: row.id, value: row.id }, row.name || row.id))
816
+ ),
817
+ h(
818
+ "select",
819
+ { className: "dsg-select", value: model, onChange: (e) => setModel(e.target.value) },
820
+ h("option", { value: "" }, "选择模型"),
821
+ modelRows.map((row) => h("option", { key: row.id, value: row.id }, row.name || row.id))
822
+ )
823
+ )
824
+ : null,
825
+ h(
826
+ "div",
827
+ { className: "dsg-consent-actions" },
828
+ h(
829
+ "button",
830
+ {
831
+ className: "dsg-btn",
832
+ "data-tone": "primary",
833
+ disabled: mode === "llm" && (!provider || !model),
834
+ onClick: () => onOp({ op: "setting", classifier: { mode, provider, model } }),
835
+ },
836
+ "保存分类方式"
837
+ )
838
+ )
839
+ ),
840
+
841
+ h(
842
+ "div",
843
+ { className: "dsg-field" },
844
+ h("div", { className: "dsg-field-label" }, "始终允许(不再询问)的组别"),
845
+ Object.keys(autoAllow).length === 0
846
+ ? h("div", { className: "dsg-consent-note" }, "暂无。在许可条上点「始终允许该组别」就会加进来。")
847
+ : h(
848
+ "div",
849
+ { className: "dsg-consent-actions" },
850
+ Object.keys(autoAllow).map((groupId) => {
851
+ const group = groups.find((entry) => entry.id === groupId);
852
+ if (!group) return null;
853
+ return h(
854
+ "button",
855
+ { key: groupId, className: "dsg-btn", title: "撤销,恢复逐次询问", onClick: () => onOp({ op: "autoAllow.revoke", groupId }) },
856
+ group.name + " ×"
857
+ );
858
+ })
859
+ )
860
+ ),
861
+
862
+ h("div", { className: "dsg-consent-note" }, "状态文件:" + (statePath || "(未连接)"))
863
+ );
864
+ }
865
+
866
+
332
867
  function Region(props) {
333
868
  const {
334
869
  useSessions, useWorkspaces, useSessionStatus, useScheduleCatalog, open,
@@ -400,11 +935,66 @@ window.__ModuleLoader__.load({
400
935
  const assign = groups.assign || {};
401
936
  const collapsed = groups.collapsed || {};
402
937
  const orders = groups.order || {};
403
- const hidden = store.get().hiddenWorkspaces || [];
938
+ const hidden = groups.hiddenWorkspaces || [];
404
939
 
405
940
  const ids = useMemo(() => (list?.ids || []).filter((id) => byId[id] && !isSubagent(byId[id])), [list, byId]);
406
941
  const archived = useMemo(() => ids.filter((id) => archivedSet.has(id)), [ids, archivedSet]);
407
942
  const live = useMemo(() => ids.filter((id) => !archivedSet.has(id)), [ids, archivedSet]);
943
+
944
+ /* 会话/定时任务快照交给宿主。判定、许可状态与落盘都在宿主侧,
945
+ * 客户端只报数并渲染返回的待确认建议。 */
946
+ const scheduleDigest = useMemo(
947
+ () =>
948
+ (Array.isArray(schedules) ? schedules : []).map((row) => ({
949
+ /* 目录行有两种形状:存储里的 {record, target, lastDelivery}
950
+ * 与客户端目录拍扁后的同名行,两种都认。 */
951
+ id: String((row && ((row.record && row.record.id) || row.id)) || ""),
952
+ title: String((row && ((row.record && row.record.title) || row.title)) || ""),
953
+ targetSessionId: String((row && row.lastDelivery && row.lastDelivery.targetSessionId) || ""),
954
+ deliveredAt: String((row && row.lastDelivery && row.lastDelivery.deliveredAt) || ""),
955
+ })),
956
+ [schedules]
957
+ );
958
+ const sessionDigest = useMemo(
959
+ () =>
960
+ live.map((id) => ({
961
+ id,
962
+ title: titleOf(byId[id], id),
963
+ createdAt: Number(byId[id] && byId[id].createdAt) || undefined,
964
+ updatedAt: Number(byId[id] && byId[id].updatedAt) || undefined,
965
+ })),
966
+ [live, byId]
967
+ );
968
+
969
+ useEffect(() => {
970
+ void (async () => {
971
+ const reachable = await store.load();
972
+ if (!reachable) return;
973
+ await store.importLegacy();
974
+ await store.sync(sessionDigest, scheduleDigest);
975
+ })();
976
+ // 只在挂载时跑一次;后续靠下面的 digest 变化与轮询。
977
+ // eslint-disable-next-line react-hooks/exhaustive-deps
978
+ }, []);
979
+
980
+ useEffect(() => {
981
+ if (sessionDigest.length === 0 && scheduleDigest.length === 0) return undefined;
982
+ const timer = setTimeout(() => {
983
+ void store.sync(sessionDigest, scheduleDigest);
984
+ }, 400);
985
+ return () => clearTimeout(timer);
986
+ }, [sessionDigest, scheduleDigest]);
987
+
988
+ /* 另一扇窗、或桌面端刚 accept 过许可时让本窗跟上;页面隐藏时不跑。 */
989
+ useEffect(() => {
990
+ const timer = setInterval(() => {
991
+ try {
992
+ if (document.visibilityState === "hidden") return;
993
+ } catch {}
994
+ void store.load();
995
+ }, 20000);
996
+ return () => clearInterval(timer);
997
+ }, []);
408
998
  const archivedOrdered = useMemo(() => applyManualOrder(archived, orders["archived"]), [archived, orders]);
409
999
  const liveSorted = useMemo(() => sortRecent(live, byId), [live, byId]);
410
1000
  const recentBase = useMemo(() => liveSorted.slice(0, recentLimit), [liveSorted, recentLimit]);
@@ -438,9 +1028,11 @@ window.__ModuleLoader__.load({
438
1028
  for (const item of visibleWorkspaces) for (const id of item.sessionIds || []) shownInWorkspaces.add(id);
439
1029
  for (const id of live) {
440
1030
  if (pinnedSet.has(id)) continue;
441
- if (shownInWorkspaces.has(id)) continue;
1031
+ /* 分组优先:明确分组的会话只出现在它所属分组里,不在工作区树重复一份。 */
442
1032
  const gid = assign[id];
443
- if (gid && byGroup.has(gid)) byGroup.get(gid).push(id);
1033
+ const grouped = gid && byGroup.has(gid);
1034
+ if (!grouped && shownInWorkspaces.has(id)) continue;
1035
+ if (grouped) byGroup.get(gid).push(id);
444
1036
  else rest.push(id);
445
1037
  }
446
1038
  for (const [gid, arr] of byGroup) byGroup.set(gid, applyManualOrder(sortRecent(arr, byId), orders["g:" + gid]));
@@ -473,7 +1065,9 @@ window.__ModuleLoader__.load({
473
1065
  if (Array.isArray(saved) && saved.length > 0) {
474
1066
  const seen = new Set(saved);
475
1067
  const revealed = liveSortedRef.current.slice(limit, next).filter((id) => !seen.has(id));
476
- if (revealed.length > 0) store.set({ ...cur, order: { ...cur.order, recent: saved.concat(revealed) } });
1068
+ if (revealed.length > 0) {
1069
+ void store.op({ op: "order.set", key: "recent", ids: saved.concat(revealed) }).catch(() => {});
1070
+ }
477
1071
  }
478
1072
  setRecentLimit(next);
479
1073
  }, 140);
@@ -549,65 +1143,56 @@ window.__ModuleLoader__.load({
549
1143
  return visibleWorkspaces[0]?.workspaceId;
550
1144
  }, [groups.activeWorkspace, recent, ws, visibleWorkspaces]);
551
1145
 
552
- const toggle = useCallback((key) => {
553
- const cur = store.get();
554
- store.set({ ...cur, collapsed: { ...cur.collapsed, [key]: !(cur.collapsed || {})[key] } });
1146
+ /* 所有写操作都发给宿主:宿主是唯一写入方,返回的整份状态直接替换本地。 */
1147
+ const op = useCallback((payload) => {
1148
+ void store.op(payload).catch((err) => console.error("[dsh-sidebar-sessions] op failed", err));
555
1149
  }, []);
556
1150
 
557
- const assignTo = useCallback((id, gid) => {
558
- const cur = store.get();
559
- const nextAssign = { ...cur.assign };
560
- if (gid) nextAssign[id] = gid;
561
- else delete nextAssign[id];
562
- store.set({ ...cur, assign: nextAssign });
1151
+ /* 自绘输入/确认框:Electron 不实现 window.prompt,桌面端里它直接抛错,
1152
+ * 以前新建分组、重命名分组、重命名对话在桌面端全是静的。 */
1153
+ const [promptState, setPromptState] = useState(null);
1154
+ const [confirmState, setConfirmState] = useState(null);
1155
+ const [rulesOpen, setRulesOpen] = useState(false);
1156
+ const [picker, setPicker] = useState(null);
1157
+
1158
+ const askText = useCallback((title, value, placeholder, onOk) => {
1159
+ setPromptState({ title, value: value || "", placeholder: placeholder || "", onOk });
563
1160
  }, []);
1161
+ const askConfirm = useCallback((title, body, onOk) => setConfirmState({ title, body: body || "", onOk }), []);
1162
+
1163
+ const toggle = useCallback((key) => op({ op: "collapsed", key, value: !(collapsed || {})[key] }), [collapsed, op]);
1164
+ const assignTo = useCallback((id, gid) => op({ op: "assign", sessionId: id, groupId: gid || null }), [op]);
1165
+ const consent = useCallback((sessionId, choice) => op({ op: "consent", sessionId, choice }), [op]);
564
1166
 
565
1167
  const createGroup = useCallback((sessionId) => {
566
- const name = window.prompt("新分组名称");
567
- if (!name || !name.trim()) return;
568
- const g = { id: newGroupId(), name: name.trim().slice(0, 20) };
569
- const cur = store.get();
570
- const next = { ...cur, groups: [...cur.groups, g] };
571
- if (sessionId) next.assign = { ...cur.assign, [sessionId]: g.id };
572
- store.set(next);
573
- }, []);
1168
+ askText("新建分组", "", "分组名称", (name) => op({ op: "group.create", name, sessionId }));
1169
+ }, [askText, op]);
574
1170
 
575
1171
  const renameGroup = useCallback((g) => {
576
- const name = window.prompt("分组名称", g.name);
577
- if (!name || !name.trim()) return;
578
- const cur = store.get();
579
- store.set({ ...cur, groups: cur.groups.map((x) => (x.id === g.id ? { ...x, name: name.trim().slice(0, 20) } : x)) });
580
- }, []);
1172
+ askText("重命名分组", g.name, "分组名称", (name) => op({ op: "group.rename", groupId: g.id, name }));
1173
+ }, [askText, op]);
581
1174
 
582
1175
  const deleteGroup = useCallback((g) => {
583
- if (!window.confirm(`删除分组「${g.name}」?组内会话会回到未分组。`)) return;
584
- const cur = store.get();
585
- const nextAssign = { ...cur.assign };
586
- for (const [sid, gid] of Object.entries(nextAssign)) if (gid === g.id) delete nextAssign[sid];
587
- store.set({ ...cur, groups: cur.groups.filter((x) => x.id !== g.id), assign: nextAssign });
588
- }, []);
1176
+ askConfirm(`删除分组「${g.name}」`, "组内会话会回到未分组,绑定该组的规则也会一起删掉。", () =>
1177
+ op({ op: "group.delete", groupId: g.id }));
1178
+ }, [askConfirm, op]);
589
1179
 
590
1180
  const switchWorkspace = useCallback((item) => {
591
- const cur = store.get();
592
- store.set({ ...cur, activeWorkspace: String(item.workspaceId) });
1181
+ op({ op: "workspace.active", id: String(item.workspaceId) });
593
1182
  try {
594
1183
  if (openWorkspace) Promise.resolve(openWorkspace(item.workspaceId)).catch((err) => console.error("[dsh-sidebar-sessions] switch workspace failed", err));
595
1184
  } catch (err) {
596
1185
  console.error("[dsh-sidebar-sessions] switch workspace failed", err);
597
1186
  }
598
- }, [openWorkspace]);
1187
+ }, [openWorkspace, op]);
599
1188
 
600
1189
  const hideWorkspace = useCallback((item) => {
601
- const cur = store.get();
602
- const id = String(item.workspaceId);
603
- store.set({ ...cur, hiddenWorkspaces: [...new Set([...(cur.hiddenWorkspaces || []), id])] });
604
- }, []);
1190
+ op({ op: "workspaces.hidden", ids: [...new Set([...(hidden || []), String(item.workspaceId)])] });
1191
+ }, [hidden, op]);
605
1192
 
606
1193
  const unhideWorkspace = useCallback((item) => {
607
- const cur = store.get();
608
- const id = String(item.workspaceId);
609
- store.set({ ...cur, hiddenWorkspaces: (cur.hiddenWorkspaces || []).filter((x) => x !== id) });
610
- }, []);
1194
+ op({ op: "workspaces.hidden", ids: (hidden || []).filter((id) => id !== String(item.workspaceId)) });
1195
+ }, [hidden, op]);
611
1196
 
612
1197
  const closeMenu = useCallback(() => setMenu(null), []);
613
1198
  const openMenu = useCallback((id, el) => {
@@ -615,15 +1200,16 @@ window.__ModuleLoader__.load({
615
1200
  setMenu({ id, x: Math.min(r.right - 190, Math.max(8, window.innerWidth - 210)), y: Math.min(r.bottom + 2, window.innerHeight - 280) });
616
1201
  }, []);
617
1202
 
618
- const renameRow = useCallback(async (id) => {
619
- const name = window.prompt("重命名对话", titleOf(byId[id], id));
620
- if (!name || !name.trim() || !renameSession) return;
621
- try {
622
- await renameSession(id, name.trim());
623
- } catch (err) {
624
- console.error("[dsh-sidebar-sessions] rename failed", err);
625
- }
626
- }, [byId, renameSession]);
1203
+ const renameRow = useCallback((id) => {
1204
+ askText("重命名对话", titleOf(byId[id], id), "对话标题", async (name) => {
1205
+ if (!renameSession) return;
1206
+ try {
1207
+ await renameSession(id, name);
1208
+ } catch (err) {
1209
+ console.error("[dsh-sidebar-sessions] rename failed", err);
1210
+ }
1211
+ });
1212
+ }, [askText, byId, renameSession]);
627
1213
 
628
1214
  const copy = useCallback((text) => {
629
1215
  try {
@@ -633,17 +1219,10 @@ window.__ModuleLoader__.load({
633
1219
 
634
1220
  const commitSectionOrder = useCallback((sectionKey, next) => {
635
1221
  if (!next || sectionKey === "search") return;
636
- const cur = store.get();
637
- store.set({ ...cur, order: { ...(cur.order || {}), [sectionKey]: next } });
638
- }, []);
1222
+ op({ op: "order.set", key: sectionKey, ids: next });
1223
+ }, [op]);
639
1224
 
640
- const clearSectionOrder = useCallback((sectionKey) => {
641
- const cur = store.get();
642
- const order = { ...(cur.order || {}) };
643
- if (!(sectionKey in order)) return;
644
- delete order[sectionKey];
645
- store.set({ ...cur, order });
646
- }, []);
1225
+ const clearSectionOrder = useCallback((sectionKey) => op({ op: "order.clear", key: sectionKey }), [op]);
647
1226
 
648
1227
  const handleDragOver = useCallback((section, id, half) => {
649
1228
  if (!id) {
@@ -715,7 +1294,8 @@ window.__ModuleLoader__.load({
715
1294
 
716
1295
  const sections = { recent, pinned, archived: archivedOrdered, search: filtered || [], ungrouped: groupRows.rest };
717
1296
  for (const g of groups.groups) sections["g:" + g.id] = groupRows.byGroup.get(g.id) || [];
718
- for (const item of visibleWorkspaces) sections["ws:" + String(item.workspaceId)] = applyManualOrder((item.sessionIds || []).filter((id) => byId[id] && !archivedSet.has(id)), orders["ws:" + String(item.workspaceId)]);
1297
+ const isGrouped = (id) => { const gid = assign[id]; return !!(gid && (groups.groups || []).some((g) => g.id === gid)); };
1298
+ for (const item of visibleWorkspaces) sections["ws:" + String(item.workspaceId)] = applyManualOrder((item.sessionIds || []).filter((id) => byId[id] && !archivedSet.has(id) && !isGrouped(id)), orders["ws:" + String(item.workspaceId)]);
719
1299
  sectionIdsRef.current = sections;
720
1300
 
721
1301
  const renderRow = useCallback(
@@ -795,6 +1375,13 @@ window.__ModuleLoader__.load({
795
1375
  }
796
1376
  return null;
797
1377
  })();
1378
+ /* 待确认建议:一次只问一条,其余条数在许可条里提示。 */
1379
+ const loadModels = useCallback(() => store.models(), []);
1380
+ const statePath = store.meta().statePath || "";
1381
+ const consentEntries = Object.entries(groups.pending || {}).filter(([id]) => byId[id]);
1382
+ const consentEntry = consentEntries[0];
1383
+ const consentTitle = consentEntry ? titleOf(byId[consentEntry[0]], consentEntry[0]) : "";
1384
+
798
1385
  const menuEl = menu
799
1386
  ? h(
800
1387
  "div",
@@ -813,6 +1400,28 @@ window.__ModuleLoader__.load({
813
1400
  h("span", { className: "dsg-dot-sm" }, "●"), g.name)
814
1401
  ),
815
1402
  h("div", { className: "dsg-menu-item", onClick: () => { createGroup(menu.id); closeMenu(); } }, "+ 新建分组…"),
1403
+ (() => {
1404
+ const current = groups.groups.find((g) => g.id === assign[menu.id]);
1405
+ if (!current) return null;
1406
+ const via = (Array.isArray(schedules) ? schedules : []).find(
1407
+ (row) => row && row.lastDelivery && row.lastDelivery.targetSessionId === menu.id
1408
+ );
1409
+ const viaId = via ? (via.record && via.record.id) || via.id : undefined;
1410
+ if (!viaId) return null;
1411
+ const scheduleId = String(viaId);
1412
+ return h(
1413
+ "div",
1414
+ {
1415
+ className: "dsg-menu-item",
1416
+ title: "为这个定时任务建规则:以后它新建的会话直接进这个组",
1417
+ onClick: () => {
1418
+ op({ op: "rule.upsert", rule: { groupName: current.name, scheduleIds: [scheduleId] } });
1419
+ closeMenu();
1420
+ },
1421
+ },
1422
+ "记住:该定时任务归这里"
1423
+ );
1424
+ })(),
816
1425
  h("div", { className: "dsg-menu-sep" }),
817
1426
  h("div", { className: "dsg-menu-item", onClick: () => { archivedSet.has(menu.id) ? unarchiveSession(menu.id) : archiveSession(menu.id); closeMenu(); } },
818
1427
  archivedSet.has(menu.id) ? "取消归档" : "归档")
@@ -844,6 +1453,31 @@ window.__ModuleLoader__.load({
844
1453
  console.error("[dsh-sidebar-sessions] create workspace failed", err);
845
1454
  }
846
1455
  } }, "+ 新建工作区")),
1456
+ h("div", { className: "dsg-consent-actions", style: { margin: "0 2px 6px" } },
1457
+ h(
1458
+ "button",
1459
+ {
1460
+ className: "dsg-btn",
1461
+ "data-tone": "ghost",
1462
+ style: { height: 24, fontSize: 11, padding: "0 8px" },
1463
+ title: "自动归组规则 / 模型分类 / 始终允许白名单",
1464
+ onClick: () => setRulesOpen(true),
1465
+ },
1466
+ "⚙ 自动归组" + (groups.rules.length ? `(${groups.rules.length})` : "")
1467
+ ),
1468
+ groups.online ? null : h("span", { className: "dsg-consent-note" }, "宿主未连接")),
1469
+ consentEntry
1470
+ ? h(ConsentBar, {
1471
+ title: consentTitle,
1472
+ proposal: consentEntry[1],
1473
+ pendingCount: consentEntries.length,
1474
+ onAnswer: (choice) => consent(consentEntry[0], choice),
1475
+ onPick: () => {
1476
+ setPicker({ sessionId: consentEntry[0], title: consentTitle });
1477
+ consent(consentEntry[0], "later");
1478
+ },
1479
+ })
1480
+ : null,
847
1481
  h("div", { className: "dsg-search" },
848
1482
  h("input", {
849
1483
  value: query,
@@ -893,7 +1527,7 @@ window.__ModuleLoader__.load({
893
1527
  ? h("div", { className: "dsg-empty" }, "还没有工作区,点上方「+ 新建工作区」")
894
1528
  : visibleWorkspaces.map((item) => {
895
1529
  const key = "ws:" + String(item.workspaceId);
896
- const members = applyManualOrder((item.sessionIds || []).filter((id) => byId[id] && !archivedSet.has(id)), orders[key]);
1530
+ const members = applyManualOrder((item.sessionIds || []).filter((id) => byId[id] && !archivedSet.has(id) && !isGrouped(id)), orders[key]);
897
1531
  const isCurrent = String(currentWsId) === String(item.workspaceId);
898
1532
  const label = item.title || item.path || String(item.workspaceId);
899
1533
  return h("div", { key },
@@ -915,6 +1549,38 @@ window.__ModuleLoader__.load({
915
1549
  : null)
916
1550
  : null),
917
1551
  ),
1552
+ rulesOpen
1553
+ ? h(RulesPanel, {
1554
+ groups: groups.groups,
1555
+ rules: groups.rules,
1556
+ schedules: scheduleDigest,
1557
+ autoAllow: groups.autoAllow,
1558
+ classifier: groups.settings.classifier,
1559
+ statePath: statePath,
1560
+ online: groups.online,
1561
+ onOp: op,
1562
+ onClose: () => setRulesOpen(false),
1563
+ loadModels: loadModels,
1564
+ })
1565
+ : null,
1566
+ picker
1567
+ ? h(GroupPickerPanel, {
1568
+ title: picker.title,
1569
+ groups: groups.groups,
1570
+ onPick: (gid) => {
1571
+ assignTo(picker.sessionId, gid);
1572
+ setPicker(null);
1573
+ },
1574
+ onNew: () => {
1575
+ const sessionId = picker.sessionId;
1576
+ setPicker(null);
1577
+ createGroup(sessionId);
1578
+ },
1579
+ onCancel: () => setPicker(null),
1580
+ })
1581
+ : null,
1582
+ promptState ? h(TextDialog, { key: "prompt", state: promptState, onCancel: () => setPromptState(null) }) : null,
1583
+ confirmState ? h(ConfirmDialog, { key: "confirm", state: confirmState, onCancel: () => setConfirmState(null) }) : null,
918
1584
  menuEl
919
1585
  );
920
1586
  }