dsh-sidebar-sessions 0.1.6 → 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/rules.js ADDED
@@ -0,0 +1,548 @@
1
+ /* dsh-sidebar-sessions — shared, side-effect-free state rules.
2
+ *
3
+ * One authority for grouping state lives here so the host route, the agent
4
+ * tool, and the tests all reduce the same operations the same way. Nothing in
5
+ * this module touches the filesystem, the network, or a clock of its own: the
6
+ * caller passes `now` whenever a decision depends on time.
7
+ */
8
+
9
+ /** Bumped whenever the persisted shape changes incompatibly. */
10
+ export const STORE_VERSION = 2;
11
+
12
+ /**
13
+ * How long after a scheduled delivery its target session is still considered
14
+ * "created by that task". Wide enough for a task that runs while the GUI is
15
+ * closed, narrow enough that a twenty-day-old session is never pulled in.
16
+ */
17
+ export const FRESH_DELIVERY_MS = 24 * 60 * 60 * 1000;
18
+
19
+ /**
20
+ * How old a conversation may be and still get a suggestion. Without this,
21
+ * switching on a keyword rule would ask about every historical conversation
22
+ * that ever matched it; the point is the newest chat, not a re-sort of history.
23
+ */
24
+ export const PROPOSAL_MAX_AGE_MS = 48 * 60 * 60 * 1000;
25
+ /** Longest group name / title fragment we persist. */
26
+ export const MAX_NAME_LENGTH = 30;
27
+
28
+ /** A rule with no keywords and no schedule binding would swallow every session. */
29
+ const MAX_KEYWORDS = 24;
30
+ const MAX_KEYWORD_LENGTH = 40;
31
+
32
+ export function emptyState() {
33
+ return {
34
+ version: STORE_VERSION,
35
+ groups: [],
36
+ assign: {},
37
+ autoDone: {},
38
+ autoAllow: {},
39
+ pending: {},
40
+ rules: [],
41
+ settings: { classifier: { mode: "off", provider: "", model: "" } },
42
+ order: {},
43
+ collapsed: {},
44
+ hiddenWorkspaces: [],
45
+ activeWorkspace: null,
46
+ imported: false,
47
+ updatedAt: null,
48
+ };
49
+ }
50
+
51
+ export function newGroupId() {
52
+ return "g_" + Math.random().toString(36).slice(2, 9);
53
+ }
54
+
55
+ export function newRuleId() {
56
+ return "r_" + Math.random().toString(36).slice(2, 9);
57
+ }
58
+
59
+ export function cleanName(value) {
60
+ return String(value === undefined || value === null ? "" : value).trim().slice(0, MAX_NAME_LENGTH);
61
+ }
62
+
63
+ function keywordList(value) {
64
+ const list = Array.isArray(value) ? value : typeof value === "string" ? value.split(/[,,\n]/) : [];
65
+ const seen = new Set();
66
+ const out = [];
67
+ for (const item of list) {
68
+ const text = String(item === undefined || item === null ? "" : item).trim().slice(0, MAX_KEYWORD_LENGTH);
69
+ const key = text.toLowerCase();
70
+ if (!text || seen.has(key)) continue;
71
+ seen.add(key);
72
+ out.push(text);
73
+ if (out.length >= MAX_KEYWORDS) break;
74
+ }
75
+ return out;
76
+ }
77
+
78
+ function idList(value) {
79
+ const list = Array.isArray(value) ? value : [];
80
+ return [...new Set(list.map((item) => String(item)).filter(Boolean))];
81
+ }
82
+
83
+ function plainObject(value) {
84
+ return value && typeof value === "object" && !Array.isArray(value) ? value : {};
85
+ }
86
+
87
+ /** A rule as persisted: at least one of `any` / `scheduleIds` must be present. */
88
+ export function normalizeRule(raw, fallbackId) {
89
+ const source = plainObject(raw);
90
+ const groupName = cleanName(source.groupName || source.name);
91
+ const any = keywordList(source.any || source.keywords);
92
+ const none = keywordList(source.none || source.exclude);
93
+ const scheduleIds = idList(source.scheduleIds);
94
+ const scheduleTitles = keywordList(source.scheduleTitles);
95
+ if (!groupName) return undefined;
96
+ if (any.length === 0 && scheduleIds.length === 0 && scheduleTitles.length === 0) return undefined;
97
+ return {
98
+ id: String(source.id || fallbackId || newRuleId()),
99
+ groupName,
100
+ any,
101
+ none,
102
+ scheduleIds,
103
+ scheduleTitles,
104
+ };
105
+ }
106
+
107
+ /**
108
+ * Bring any persisted or imported payload up to the current shape. Unknown
109
+ * fields are dropped; missing ones get defaults, so a state file written by an
110
+ * older release keeps working after an upgrade.
111
+ */
112
+ export function normalizeState(raw) {
113
+ const base = emptyState();
114
+ const source = plainObject(raw);
115
+ const groups = [];
116
+ const groupIds = new Set();
117
+ for (const entry of Array.isArray(source.groups) ? source.groups : []) {
118
+ const name = cleanName(plainObject(entry).name);
119
+ const id = String(plainObject(entry).id || "");
120
+ if (!name || !id || groupIds.has(id)) continue;
121
+ groupIds.add(id);
122
+ groups.push({ id, name });
123
+ }
124
+ const assign = {};
125
+ const rawAssign = plainObject(source.assign);
126
+ for (const [sessionId, groupId] of Object.entries(rawAssign)) {
127
+ const gid = String(groupId);
128
+ if (groupIds.has(gid)) assign[String(sessionId)] = gid;
129
+ }
130
+ const autoDone = {};
131
+ for (const [sessionId, value] of Object.entries(plainObject(source.autoDone))) {
132
+ const text = typeof value === "string" ? value : value ? "applied" : "";
133
+ if (text) autoDone[String(sessionId)] = text;
134
+ }
135
+ const autoAllow = {};
136
+ for (const [groupId, value] of Object.entries(plainObject(source.autoAllow))) {
137
+ if (value && groupIds.has(String(groupId))) autoAllow[String(groupId)] = 1;
138
+ }
139
+ const pending = {};
140
+ for (const [sessionId, value] of Object.entries(plainObject(source.pending))) {
141
+ const entry = plainObject(value);
142
+ const groupId = entry.groupId && groupIds.has(String(entry.groupId)) ? String(entry.groupId) : undefined;
143
+ const groupName = cleanName(entry.groupName);
144
+ if (!groupId && !groupName) continue;
145
+ if (assign[String(sessionId)] || autoDone[String(sessionId)]) continue;
146
+ pending[String(sessionId)] = {
147
+ groupId,
148
+ groupName: groupId ? baseGroupName(groups, groupId) || groupName : groupName,
149
+ reason: ["rule", "llm", "agent"].includes(entry.reason) ? entry.reason : "rule",
150
+ at: typeof entry.at === "string" ? entry.at : null,
151
+ };
152
+ }
153
+ const rules = [];
154
+ const ruleIds = new Set();
155
+ for (const entry of Array.isArray(source.rules) ? source.rules : []) {
156
+ const rule = normalizeRule(entry);
157
+ if (!rule || ruleIds.has(rule.id)) continue;
158
+ ruleIds.add(rule.id);
159
+ rules.push(rule);
160
+ }
161
+ const settings = plainObject(source.settings);
162
+ const classifier = plainObject(settings.classifier);
163
+ const order = {};
164
+ for (const [key, value] of Object.entries(plainObject(source.order))) {
165
+ if (Array.isArray(value)) order[String(key)] = value.map((id) => String(id));
166
+ }
167
+ const collapsed = {};
168
+ for (const [key, value] of Object.entries(plainObject(source.collapsed))) {
169
+ if (value) collapsed[String(key)] = true;
170
+ }
171
+ return {
172
+ version: STORE_VERSION,
173
+ groups,
174
+ assign,
175
+ autoDone,
176
+ autoAllow,
177
+ pending,
178
+ rules,
179
+ settings: {
180
+ classifier: {
181
+ mode: classifier.mode === "llm" ? "llm" : "off",
182
+ provider: String(classifier.provider || ""),
183
+ model: String(classifier.model || ""),
184
+ },
185
+ },
186
+ order,
187
+ collapsed,
188
+ hiddenWorkspaces: Array.isArray(source.hiddenWorkspaces) ? idList(source.hiddenWorkspaces) : [],
189
+ activeWorkspace:
190
+ source.activeWorkspace === null || source.activeWorkspace === undefined ? null : String(source.activeWorkspace),
191
+ imported: source.imported === true,
192
+ updatedAt: typeof source.updatedAt === "string" ? source.updatedAt : null,
193
+ };
194
+ }
195
+
196
+ function baseGroupName(groups, groupId) {
197
+ const found = groups.find((group) => group.id === groupId);
198
+ return found ? found.name : "";
199
+ }
200
+
201
+ export function groupByName(state, name) {
202
+ const wanted = cleanName(name);
203
+ if (!wanted) return undefined;
204
+ return state.groups.find((group) => group.name === wanted);
205
+ }
206
+
207
+ function ensureGroup(state, name) {
208
+ const wanted = cleanName(name);
209
+ if (!wanted) return undefined;
210
+ const existing = state.groups.find((group) => group.name === wanted);
211
+ if (existing) return existing;
212
+ const created = { id: newGroupId(), name: wanted };
213
+ state.groups.push(created);
214
+ return created;
215
+ }
216
+
217
+ /**
218
+ * True when `text` satisfies a rule's keyword lists. A rule with no keywords
219
+ * never matches by text: it is bound to a scheduled task, and letting an empty
220
+ * `any` mean "everything" would pull every conversation into that group.
221
+ */
222
+ export function ruleMatches(rule, text) {
223
+ if (!rule) return false;
224
+ const any = Array.isArray(rule.any) ? rule.any : [];
225
+ if (any.length === 0) return false;
226
+ const hay = String(text || "").toLowerCase();
227
+ if (!hay) return false;
228
+ const none = Array.isArray(rule.none) ? rule.none : [];
229
+ if (none.some((word) => hay.includes(String(word).toLowerCase()))) return false;
230
+ return any.some((word) => hay.includes(String(word).toLowerCase()));
231
+ }
232
+
233
+ /**
234
+ * Pick the rule that explains a session. A schedule binding wins over title
235
+ * keywords: the delivery record is a fact, a title is a guess.
236
+ * @param state - normalized state.
237
+ * @param session - `{ id, title }` as the client reported it.
238
+ * @param schedule - optional `{ id, title, deliveredAt }` of the delivery that
239
+ * created this session, already filtered to a fresh delivery.
240
+ */
241
+ export function pickRule(state, session, schedule) {
242
+ const rules = state.rules || [];
243
+ const title = String((session && session.title) || "");
244
+ if (schedule) {
245
+ const byId = rules.find((rule) => (rule.scheduleIds || []).includes(String(schedule.id)));
246
+ if (byId) return byId;
247
+ const byTitle = rules.find((rule) => ruleMatches(rule, schedule.title));
248
+ if (byTitle) return byTitle;
249
+ }
250
+ return rules.find((rule) => ruleMatches(rule, title));
251
+ }
252
+
253
+ /**
254
+ * Compute the proposals the current session list deserves.
255
+ *
256
+ * Applied silently when the target group is on the "always allow" list;
257
+ * otherwise the proposal waits for a human answer. A session is proposed at
258
+ * most once: `autoDone` records every session we acted on or dismissed, so a
259
+ * manually moved session is never dragged back.
260
+ */
261
+ export function planProposals(state, input, now = Date.now()) {
262
+ const sessions = Array.isArray(input && input.sessions) ? input.sessions : [];
263
+ const schedules = Array.isArray(input && input.schedules) ? input.schedules : [];
264
+ const fresh = new Map();
265
+ for (const entry of schedules) {
266
+ const sessionId = entry && entry.targetSessionId ? String(entry.targetSessionId) : "";
267
+ if (!sessionId) continue;
268
+ const at = Date.parse(entry.deliveredAt || "");
269
+ if (!Number.isFinite(at) || now - at > FRESH_DELIVERY_MS) continue;
270
+ fresh.set(sessionId, { id: String(entry.id || ""), title: String(entry.title || ""), deliveredAt: entry.deliveredAt });
271
+ }
272
+ const next = { ...state, groups: [...state.groups], assign: { ...state.assign }, autoDone: { ...state.autoDone }, pending: { ...state.pending } };
273
+ const applied = [];
274
+ const proposed = [];
275
+ for (const session of sessions) {
276
+ const id = session && session.id ? String(session.id) : "";
277
+ if (!id) continue;
278
+ if (next.assign[id] || next.autoDone[id] || next.pending[id]) continue;
279
+ const created = Number(session.createdAt ?? session.updatedAt);
280
+ if (Number.isFinite(created) && created > 0 && now - created > PROPOSAL_MAX_AGE_MS) continue;
281
+ const rule = pickRule(next, session, fresh.get(id));
282
+ if (!rule) continue;
283
+ const group = next.groups.find((entry) => entry.name === rule.groupName);
284
+ if (group && next.autoAllow[group.id]) {
285
+ next.assign[id] = group.id;
286
+ next.autoDone[id] = "applied";
287
+ applied.push({ sessionId: id, groupId: group.id, groupName: group.name, ruleId: rule.id });
288
+ continue;
289
+ }
290
+ next.pending[id] = {
291
+ groupId: group ? group.id : undefined,
292
+ groupName: rule.groupName,
293
+ reason: "rule",
294
+ at: new Date(now).toISOString(),
295
+ };
296
+ proposed.push({ sessionId: id, groupName: rule.groupName, ruleId: rule.id });
297
+ }
298
+ const changed = applied.length > 0 || proposed.length > 0;
299
+ return { state: changed ? next : state, applied, proposed, changed };
300
+ }
301
+
302
+ function requireSessionId(op) {
303
+ const sessionId = op && op.sessionId ? String(op.sessionId) : "";
304
+ if (!sessionId) throw new Error("缺少 sessionId");
305
+ return sessionId;
306
+ }
307
+
308
+ function touch(state, now) {
309
+ return { ...state, updatedAt: new Date(now).toISOString() };
310
+ }
311
+
312
+ /**
313
+ * Reduce one UI/agent operation into the next state.
314
+ *
315
+ * Pure: the caller persists what comes back. A rejected operation returns the
316
+ * unchanged state plus an error, never a half-applied change.
317
+ */
318
+ export function applyOp(state, op, now = Date.now()) {
319
+ const base = normalizeState(state);
320
+ const action = op && op.op;
321
+ const next = {
322
+ ...base,
323
+ groups: [...base.groups],
324
+ assign: { ...base.assign },
325
+ autoDone: { ...base.autoDone },
326
+ autoAllow: { ...base.autoAllow },
327
+ pending: { ...base.pending },
328
+ rules: [...base.rules],
329
+ settings: { classifier: { ...base.settings.classifier } },
330
+ order: { ...base.order },
331
+ collapsed: { ...base.collapsed },
332
+ hiddenWorkspaces: [...base.hiddenWorkspaces],
333
+ };
334
+ switch (action) {
335
+ case "assign": {
336
+ const sessionId = requireSessionId(op);
337
+ const groupId = op.groupId ? String(op.groupId) : "";
338
+ if (groupId && !next.groups.some((group) => group.id === groupId)) throw new Error("分组不存在");
339
+ if (groupId) next.assign[sessionId] = groupId;
340
+ else delete next.assign[sessionId];
341
+ delete next.pending[sessionId];
342
+ next.autoDone[sessionId] = "manual";
343
+ return { state: touch(next, now) };
344
+ }
345
+ case "consent": {
346
+ const sessionId = requireSessionId(op);
347
+ const proposal = next.pending[sessionId];
348
+ const choice = String(op.choice || "");
349
+ if (!proposal) {
350
+ // Nothing pending: a stale click after another window applied it.
351
+ return { state: touch(next, now) };
352
+ }
353
+ if (choice === "no") {
354
+ delete next.pending[sessionId];
355
+ next.autoDone[sessionId] = "rejected";
356
+ return { state: touch(next, now) };
357
+ }
358
+ if (choice === "later") {
359
+ delete next.pending[sessionId];
360
+ next.autoDone[sessionId] = "deferred";
361
+ return { state: touch(next, now) };
362
+ }
363
+ if (choice !== "yes" && choice !== "always") throw new Error("未知的许可选项");
364
+ const group = ensureGroup(next, proposal.groupName);
365
+ if (!group) throw new Error("分组名为空");
366
+ next.assign[sessionId] = group.id;
367
+ delete next.pending[sessionId];
368
+ next.autoDone[sessionId] = "applied";
369
+ if (choice === "always") next.autoAllow[group.id] = 1;
370
+ return { state: touch(next, now) };
371
+ }
372
+ case "group.create": {
373
+ const name = cleanName(op.name);
374
+ if (!name) throw new Error("分组名不能为空");
375
+ if (next.groups.some((group) => group.name === name)) throw new Error("分组已存在");
376
+ const group = { id: newGroupId(), name };
377
+ next.groups.push(group);
378
+ if (op.sessionId) {
379
+ next.assign[String(op.sessionId)] = group.id;
380
+ delete next.pending[String(op.sessionId)];
381
+ next.autoDone[String(op.sessionId)] = "manual";
382
+ }
383
+ return { state: touch(next, now) };
384
+ }
385
+ case "group.rename": {
386
+ const name = cleanName(op.name);
387
+ if (!name) throw new Error("分组名不能为空");
388
+ const group = next.groups.find((entry) => entry.id === String(op.groupId));
389
+ if (!group) throw new Error("分组不存在");
390
+ if (next.groups.some((entry) => entry.name === name && entry.id !== group.id)) throw new Error("分组名重复");
391
+ const previous = group.name;
392
+ group.name = name;
393
+ for (const rule of next.rules) if (rule.groupName === previous) rule.groupName = name;
394
+ return { state: touch(next, now) };
395
+ }
396
+ case "group.delete": {
397
+ const groupId = String(op.groupId || "");
398
+ const group = next.groups.find((entry) => entry.id === groupId);
399
+ if (!group) throw new Error("分组不存在");
400
+ next.groups = next.groups.filter((entry) => entry.id !== groupId);
401
+ for (const [sessionId, assigned] of Object.entries(next.assign)) if (assigned === groupId) delete next.assign[sessionId];
402
+ delete next.autoAllow[groupId];
403
+ for (const [sessionId, proposal] of Object.entries(next.pending)) if (proposal.groupId === groupId) delete next.pending[sessionId];
404
+ next.rules = next.rules.filter((rule) => rule.groupName !== group.name);
405
+ for (const key of ["g:" + groupId]) delete next.order[key];
406
+ return { state: touch(next, now) };
407
+ }
408
+ case "rule.upsert": {
409
+ const rule = normalizeRule(op.rule);
410
+ if (!rule) throw new Error("规则至少需要一个关键词或一条定时任务");
411
+ /* One rule per scheduled task: a second binding for the same task would
412
+ * make which group wins depend on array order. */
413
+ if (rule.scheduleIds.length > 0) {
414
+ next.rules = next.rules.filter(
415
+ (entry) => entry.id === rule.id || !entry.scheduleIds.some((id) => rule.scheduleIds.includes(id))
416
+ );
417
+ }
418
+ const at = next.rules.findIndex((entry) => entry.id === rule.id);
419
+ if (at >= 0) next.rules[at] = rule;
420
+ else next.rules.push(rule);
421
+ return { state: touch(next, now) };
422
+ }
423
+ case "rule.delete": {
424
+ const ruleId = String(op.ruleId || "");
425
+ next.rules = next.rules.filter((rule) => rule.id !== ruleId);
426
+ return { state: touch(next, now) };
427
+ }
428
+ case "setting": {
429
+ const classifier = plainObject(op.classifier);
430
+ const mode = classifier.mode === "llm" ? "llm" : "off";
431
+ const provider = String(classifier.provider || "");
432
+ const model = String(classifier.model || "");
433
+ if (mode === "llm" && (!provider || !model)) throw new Error("开启 LLM 兜底需要先选模型");
434
+ next.settings.classifier = { mode, provider, model };
435
+ return { state: touch(next, now) };
436
+ }
437
+ case "autoAllow.revoke": {
438
+ const groupId = String(op.groupId || "");
439
+ if (!groupId) throw new Error("缺少 groupId");
440
+ delete next.autoAllow[groupId];
441
+ return { state: touch(next, now) };
442
+ }
443
+ case "forget": {
444
+ const sessionId = requireSessionId(op);
445
+ delete next.autoDone[sessionId];
446
+ delete next.pending[sessionId];
447
+ return { state: touch(next, now) };
448
+ }
449
+ case "order.set": {
450
+ const key = String(op.key || "");
451
+ if (!key) throw new Error("缺少排序键");
452
+ next.order[key] = idList(op.ids);
453
+ return { state: touch(next, now) };
454
+ }
455
+ case "order.clear": {
456
+ delete next.order[String(op.key || "")];
457
+ return { state: touch(next, now) };
458
+ }
459
+ case "collapsed": {
460
+ const key = String(op.key || "");
461
+ if (!key) throw new Error("缺少折叠键");
462
+ if (op.value) next.collapsed[key] = true;
463
+ else delete next.collapsed[key];
464
+ return { state: touch(next, now) };
465
+ }
466
+ case "workspaces.hidden": {
467
+ next.hiddenWorkspaces = idList(op.ids);
468
+ return { state: touch(next, now) };
469
+ }
470
+ case "workspace.active": {
471
+ next.activeWorkspace = op.id === null || op.id === undefined ? null : String(op.id);
472
+ return { state: touch(next, now) };
473
+ }
474
+ case "import": {
475
+ if (next.imported) return { state: base, skipped: true };
476
+ const legacy = plainObject(op.state);
477
+ const merged = normalizeState({
478
+ ...next,
479
+ groups: Array.isArray(legacy.groups) ? legacy.groups : next.groups,
480
+ assign: { ...(plainObject(legacy.assign) || {}), ...next.assign },
481
+ order: { ...(plainObject(legacy.order) || {}), ...next.order },
482
+ collapsed: { ...(plainObject(legacy.collapsed) || {}), ...next.collapsed },
483
+ hiddenWorkspaces: Array.isArray(legacy.hiddenWorkspaces) ? legacy.hiddenWorkspaces : next.hiddenWorkspaces,
484
+ activeWorkspace: legacy.activeWorkspace === undefined ? next.activeWorkspace : legacy.activeWorkspace,
485
+ autoDone: { ...(plainObject(legacy.autoDone) || {}), ...next.autoDone },
486
+ rules: next.rules.length > 0 ? next.rules : legacyRules(legacy),
487
+ });
488
+ merged.imported = true;
489
+ return { state: touch(merged, now) };
490
+ }
491
+ case "llm.proposal": {
492
+ // Produced by the host when the classifier answered; the human still has
493
+ // to consent, so this only fills the pending slot.
494
+ const sessionId = requireSessionId(op);
495
+ const groupName = cleanName(op.groupName);
496
+ if (!groupName) throw new Error("分组名为空");
497
+ const group = groupByName(next, groupName);
498
+ if (group && next.autoAllow[group.id]) {
499
+ next.assign[sessionId] = group.id;
500
+ next.autoDone[sessionId] = "applied";
501
+ delete next.pending[sessionId];
502
+ return { state: touch(next, now), applied: true };
503
+ }
504
+ next.pending[sessionId] = { groupId: group ? group.id : undefined, groupName, reason: "llm", at: new Date(now).toISOString() };
505
+ return { state: touch(next, now) };
506
+ }
507
+ case "propose": {
508
+ const sessionId = requireSessionId(op);
509
+ const groupName = cleanName(op.groupName);
510
+ if (!groupName) throw new Error("分组名为空");
511
+ if (next.assign[sessionId]) return { state: base, skipped: "assigned" };
512
+ const group = groupByName(next, groupName);
513
+ if (group && next.autoAllow[group.id]) {
514
+ next.assign[sessionId] = group.id;
515
+ next.autoDone[sessionId] = "applied";
516
+ delete next.pending[sessionId];
517
+ return { state: touch(next, now), applied: true, groupId: group.id };
518
+ }
519
+ next.pending[sessionId] = { groupId: group ? group.id : undefined, groupName, reason: "agent", at: new Date(now).toISOString() };
520
+ return { state: touch(next, now), applied: false };
521
+ }
522
+ default:
523
+ throw new Error("未知操作:" + String(action));
524
+ }
525
+ }
526
+
527
+ /** Legacy `autoRules` (v1, keyword only) mapped onto the v2 rule shape. */
528
+ export function legacyRules(legacy) {
529
+ const source = Array.isArray(legacy && legacy.autoRules) ? legacy.autoRules : [];
530
+ const out = [];
531
+ for (const entry of source) {
532
+ const rule = normalizeRule({ groupName: entry && entry.groupName, any: entry && entry.any, none: entry && entry.none });
533
+ if (rule) out.push(rule);
534
+ }
535
+ return out;
536
+ }
537
+
538
+ /** Group rows for display, including groups that only exist as rule targets. */
539
+ export function displayGroups(state) {
540
+ const groups = [...state.groups];
541
+ const names = new Set(groups.map((group) => group.name));
542
+ for (const rule of state.rules) {
543
+ if (names.has(rule.groupName)) continue;
544
+ names.add(rule.groupName);
545
+ groups.push({ id: "pending:" + rule.groupName, name: rule.groupName, virtual: true });
546
+ }
547
+ return groups;
548
+ }
package/package.json CHANGED
@@ -1,56 +1,60 @@
1
- {
2
- "name": "dsh-sidebar-sessions",
3
- "version": "0.1.6",
4
- "description": "Recent-first session sidebar for DeepSeek Harness: user groups, workspace tree, archive bucket, status dots, drag reorder and scheduled-task marks.",
5
- "type": "module",
6
- "main": "lib/index.js",
7
- "exports": {
8
- ".": "./lib/index.js",
9
- "./client": "./lib/client.js"
10
- },
11
- "files": [
12
- "lib",
13
- "cordis.patch.yml",
14
- "README.md",
15
- "LICENSE"
16
- ],
17
- "license": "MIT",
18
- "author": "sss-1012",
19
- "repository": {
20
- "type": "git",
21
- "url": "git+https://github.com/sss-1012/dsh-sidebar-sessions.git"
22
- },
23
- "homepage": "https://github.com/sss-1012/dsh-sidebar-sessions#readme",
24
- "bugs": {
25
- "url": "https://github.com/sss-1012/dsh-sidebar-sessions/issues"
26
- },
27
- "keywords": [
28
- "dsh",
29
- "dsh-plugin",
30
- "deepseek-harness",
31
- "sidebar",
32
- "sessions",
33
- "workspace",
34
- "archive"
35
- ],
36
- "engines": {
37
- "dsh": ">=0.2.1-rc.3 <0.3.0"
38
- },
39
- "dsh": {
40
- "manifestVersion": 1,
41
- "bundle": {
42
- "patch": "./cordis.patch.yml"
43
- },
44
- "client": {
45
- "platform": "web",
46
- "immediately": true,
47
- "inject": [
48
- "@deepseek-ai/dsh-api-session-controller",
49
- "@deepseek-ai/dsh-api-workspace-controller",
50
- "@deepseek-ai/dsh-client-connection",
51
- "@deepseek-ai/dsh-client-ui-session",
52
- "@deepseek-ai/dsh-client-ui-workspace"
53
- ]
54
- }
55
- }
56
- }
1
+ {
2
+ "name": "dsh-sidebar-sessions",
3
+ "version": "0.2.0",
4
+ "description": "Recent-first session sidebar for DeepSeek Harness: user groups, workspace tree, archive bucket, status dots, drag reorder, host-backed auto-grouping with a consent prompt, and an agent tool to propose groups.",
5
+ "type": "module",
6
+ "main": "lib/index.js",
7
+ "exports": {
8
+ ".": "./lib/index.js",
9
+ "./client": "./lib/client.js"
10
+ },
11
+ "files": [
12
+ "lib",
13
+ "cordis.patch.yml",
14
+ "README.md",
15
+ "LICENSE"
16
+ ],
17
+ "license": "MIT",
18
+ "author": "sss-1012",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/sss-1012/dsh-sidebar-sessions.git"
22
+ },
23
+ "homepage": "https://github.com/sss-1012/dsh-sidebar-sessions#readme",
24
+ "bugs": {
25
+ "url": "https://github.com/sss-1012/dsh-sidebar-sessions/issues"
26
+ },
27
+ "keywords": [
28
+ "dsh",
29
+ "dsh-plugin",
30
+ "deepseek-harness",
31
+ "sidebar",
32
+ "sessions",
33
+ "workspace",
34
+ "archive",
35
+ "grouping"
36
+ ],
37
+ "scripts": {
38
+ "test": "node test/order.test.mjs && node test/rules.test.mjs && node test/host-api.test.mjs"
39
+ },
40
+ "engines": {
41
+ "dsh": ">=0.2.1-rc.3 <0.3.0"
42
+ },
43
+ "dsh": {
44
+ "manifestVersion": 1,
45
+ "bundle": {
46
+ "patch": "./cordis.patch.yml"
47
+ },
48
+ "client": {
49
+ "platform": "web",
50
+ "immediately": true,
51
+ "inject": [
52
+ "@deepseek-ai/dsh-api-session-controller",
53
+ "@deepseek-ai/dsh-api-workspace-controller",
54
+ "@deepseek-ai/dsh-client-connection",
55
+ "@deepseek-ai/dsh-client-ui-session",
56
+ "@deepseek-ai/dsh-client-ui-workspace"
57
+ ]
58
+ }
59
+ }
60
+ }