dsh-sidebar-sessions 0.1.5 → 0.1.6

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/README.md CHANGED
@@ -10,8 +10,9 @@ DeepSeek Harness 的会话侧边栏增强插件:**最近优先 + 自定义分
10
10
 
11
11
  - **最近优先**:顶部「最近」区按最近活跃时间排序,首屏 20 条;滚到底部附近自动接上下一批 20 条,也可以点底部的「显示更多(还有 N 条)」,到底显示「已经是最早的对话了 · 共 N 条」。
12
12
  - **置顶**:手动置顶的会话单独一组。
13
- - **自定义分组**:新建 / 重命名 / 删除分组,任意会话可移入分组(数据存 localStorage)。
13
+ - **自定义分组**:新建 / 重命名 / 删除分组,任意会话可移入分组(数据存 localStorage)。**分组优先**(v0.1.6):已分组的会话只出现在它所属分组里,不再在工作区树重复一份;移出分组后回到工作区树。
14
14
  - **工作区树**:📁 工作区节点可折叠,展开列出各工作区;📌 标记当前工作区,点击工作区名即可切换(调用宿主 `openWorkspace`)。
15
+ - **自动分组**(v0.1.6):命中规则的新会话自动进指定分组,分组不存在则创建。默认规则:含「新闻简报 / 每日简报」→「每日简报」,含「项目数据雷达 / 数据雷达」→「个人开发工具」。判定优先看「该会话是不是某个定时任务刚创建的新会话(`lastDelivery.targetSessionId`,12 小时内)」,其次才看会话标题;一旦自动分过就记进 `autoDone`,你手动挪走后不会被拉回。规则可在 localStorage `dsh-session-groups.v1` 的 `autoRules` 字段改:`[{ groupName, any: [关键词…], none: [排除词…] }]`。
15
16
  - **归档**:已归档会话收进「已归档」分组,可展开查看 / 取消归档。
16
17
  - **搜索**:顶部搜索框按标题过滤,`Esc` 清空;匹配多时同样分批,底部提示「还有 N 条匹配」。
17
18
  - **状态点**(官方 StateDot 同源数据):
package/lib/client.js CHANGED
@@ -80,7 +80,7 @@ window.__ModuleLoader__.load({
80
80
  return () => style.remove();
81
81
  }
82
82
 
83
- const EMPTY = { groups: [], assign: {}, collapsed: {}, hiddenWorkspaces: [], activeWorkspace: null, order: {} };
83
+ const EMPTY = { groups: [], assign: {}, collapsed: {}, hiddenWorkspaces: [], activeWorkspace: null, order: {}, autoRules: [], autoDone: {} };
84
84
 
85
85
  function readStore() {
86
86
  try {
@@ -94,6 +94,8 @@ window.__ModuleLoader__.load({
94
94
  hiddenWorkspaces: Array.isArray(parsed.hiddenWorkspaces) ? parsed.hiddenWorkspaces : [],
95
95
  activeWorkspace: typeof parsed.activeWorkspace === "string" ? parsed.activeWorkspace : null,
96
96
  order: parsed.order && typeof parsed.order === "object" ? parsed.order : {},
97
+ autoRules: Array.isArray(parsed.autoRules) ? parsed.autoRules : [],
98
+ autoDone: parsed.autoDone && typeof parsed.autoDone === "object" ? parsed.autoDone : {},
97
99
  };
98
100
  } catch {
99
101
  return { ...EMPTY };
@@ -130,6 +132,25 @@ window.__ModuleLoader__.load({
130
132
  return useSyncExternalStore(store.subscribe, store.get, store.get);
131
133
  }
132
134
 
135
+ /* 自动分组:定时任务现在每次投递到新会话,新会话标题由投递词生成。
136
+ * 命中规则的新会话自动放进指定分组(分组不存在则创建)。
137
+ * 处理过一次就记进 autoDone,之后你手动挪走也不会被拉回来。
138
+ * 想改规则:localStorage 里 dsh-session-groups.v1 的 autoRules 字段
139
+ * ([{ groupName, any: [关键词...], none: [排除词...] }]),留空用默认值。 */
140
+ const DEFAULT_AUTO_RULES = [
141
+ { id: "r_brief", groupName: "每日简报", any: ["新闻简报", "每日简报"], schedules: ["新闻简报", "每日简报"] },
142
+ { id: "r_radar", groupName: "个人开发工具", any: ["项目数据雷达", "数据雷达", "npm 与 GitHub 项目数据"], schedules: ["项目数据雷达", "数据雷达"] },
143
+ ];
144
+
145
+ function matchAutoRule(rule, text) {
146
+ if (!rule || !text) return false;
147
+ const hay = String(text).toLowerCase();
148
+ const any = Array.isArray(rule.any) ? rule.any : [];
149
+ const none = Array.isArray(rule.none) ? rule.none : [];
150
+ if (none.some((k) => hay.includes(String(k).toLowerCase()))) return false;
151
+ return any.length === 0 || any.some((k) => hay.includes(String(k).toLowerCase()));
152
+ }
153
+
133
154
  function newGroupId() {
134
155
  return "g_" + Math.random().toString(36).slice(2, 9);
135
156
  }
@@ -405,6 +426,52 @@ window.__ModuleLoader__.load({
405
426
  const ids = useMemo(() => (list?.ids || []).filter((id) => byId[id] && !isSubagent(byId[id])), [list, byId]);
406
427
  const archived = useMemo(() => ids.filter((id) => archivedSet.has(id)), [ids, archivedSet]);
407
428
  const live = useMemo(() => ids.filter((id) => !archivedSet.has(id)), [ids, archivedSet]);
429
+
430
+ /* 自动分组落地:只处理既没手动分过、也没被自动处理过的会话。 */
431
+ useEffect(() => {
432
+ if (!live.length) return;
433
+ const cur = store.get();
434
+ const rules = Array.isArray(cur.autoRules) && cur.autoRules.length > 0 ? cur.autoRules : DEFAULT_AUTO_RULES;
435
+ const done = cur.autoDone || {};
436
+ const groupsNext = [...(cur.groups || [])];
437
+ const assignNext = { ...(cur.assign || {}) };
438
+ const doneNext = { ...done };
439
+ /* 判定优先级:先看「这个会话是不是某个定时任务刚创建的」——宿主会把新会话记在
440
+ * schedule.lastDelivery.targetSessionId;这比标题可靠得多。其次才看会话标题。 */
441
+ const bySchedule = new Map();
442
+ const FRESH_MS = 12 * 60 * 60 * 1000;
443
+ const now = Date.now();
444
+ for (const row of Array.isArray(schedules) ? schedules : []) {
445
+ const sid = row && row.lastDelivery && row.lastDelivery.targetSessionId;
446
+ if (!sid) continue;
447
+ /* 只认最近的投递:旧配置曾把任务投到已有会话,那些会话不该被动搬家。 */
448
+ const at = Date.parse((row.lastDelivery && row.lastDelivery.deliveredAt) || "");
449
+ if (!Number.isFinite(at) || now - at > FRESH_MS) continue;
450
+ bySchedule.set(sid, [row.title, row.prompt].filter(Boolean).join(" \n "));
451
+ }
452
+ let changed = false;
453
+ for (const id of live) {
454
+ if (assignNext[id] || doneNext[id]) continue;
455
+ const row = byId[id];
456
+ /* 标题匹配只认标题:预览/摘要里提到「简报」的老会话不该被拖进新分组。 */
457
+ const sessionText = titleOf(row, id);
458
+ const schText = bySchedule.get(id) || "";
459
+ let rule = rules.find((r) => schText && matchAutoRule(r, schText));
460
+ if (!rule) rule = rules.find((r) => matchAutoRule(r, sessionText));
461
+ if (!rule) continue;
462
+ const name = String(rule.groupName || "").trim();
463
+ if (!name) continue;
464
+ let g = groupsNext.find((x) => x.name === name);
465
+ if (!g) {
466
+ g = { id: newGroupId(), name: name.slice(0, 20) };
467
+ groupsNext.push(g);
468
+ }
469
+ assignNext[id] = g.id;
470
+ doneNext[id] = 1;
471
+ changed = true;
472
+ }
473
+ if (changed) store.set({ ...cur, groups: groupsNext, assign: assignNext, autoDone: doneNext });
474
+ }, [live, byId, schedules]);
408
475
  const archivedOrdered = useMemo(() => applyManualOrder(archived, orders["archived"]), [archived, orders]);
409
476
  const liveSorted = useMemo(() => sortRecent(live, byId), [live, byId]);
410
477
  const recentBase = useMemo(() => liveSorted.slice(0, recentLimit), [liveSorted, recentLimit]);
@@ -438,9 +505,11 @@ window.__ModuleLoader__.load({
438
505
  for (const item of visibleWorkspaces) for (const id of item.sessionIds || []) shownInWorkspaces.add(id);
439
506
  for (const id of live) {
440
507
  if (pinnedSet.has(id)) continue;
441
- if (shownInWorkspaces.has(id)) continue;
508
+ /* 分组优先:明确分组的会话只出现在它所属分组里,不在工作区树重复一份。 */
442
509
  const gid = assign[id];
443
- if (gid && byGroup.has(gid)) byGroup.get(gid).push(id);
510
+ const grouped = gid && byGroup.has(gid);
511
+ if (!grouped && shownInWorkspaces.has(id)) continue;
512
+ if (grouped) byGroup.get(gid).push(id);
444
513
  else rest.push(id);
445
514
  }
446
515
  for (const [gid, arr] of byGroup) byGroup.set(gid, applyManualOrder(sortRecent(arr, byId), orders["g:" + gid]));
@@ -715,7 +784,8 @@ window.__ModuleLoader__.load({
715
784
 
716
785
  const sections = { recent, pinned, archived: archivedOrdered, search: filtered || [], ungrouped: groupRows.rest };
717
786
  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)]);
787
+ const isGrouped = (id) => { const gid = assign[id]; return !!(gid && (groups.groups || []).some((g) => g.id === gid)); };
788
+ 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
789
  sectionIdsRef.current = sections;
720
790
 
721
791
  const renderRow = useCallback(
@@ -893,7 +963,7 @@ window.__ModuleLoader__.load({
893
963
  ? h("div", { className: "dsg-empty" }, "还没有工作区,点上方「+ 新建工作区」")
894
964
  : visibleWorkspaces.map((item) => {
895
965
  const key = "ws:" + String(item.workspaceId);
896
- const members = applyManualOrder((item.sessionIds || []).filter((id) => byId[id] && !archivedSet.has(id)), orders[key]);
966
+ const members = applyManualOrder((item.sessionIds || []).filter((id) => byId[id] && !archivedSet.has(id) && !isGrouped(id)), orders[key]);
897
967
  const isCurrent = String(currentWsId) === String(item.workspaceId);
898
968
  const label = item.title || item.path || String(item.workspaceId);
899
969
  return h("div", { key },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-sidebar-sessions",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Recent-first session sidebar for DeepSeek Harness: user groups, workspace tree, archive bucket, status dots, drag reorder and scheduled-task marks.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",