dsh-keeper-plugin 0.1.5 → 0.1.7

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.
Files changed (4) hide show
  1. package/README.md +154 -84
  2. package/client.js +4237 -330
  3. package/index.js +153 -2
  4. package/package.json +1 -1
package/index.js CHANGED
@@ -28,7 +28,7 @@ export const inject = [
28
28
  const NS = 'dsh-keeper';
29
29
  const PANEL_ID = 'dsh-keeper';
30
30
  const API_PATH = '/dsh-keeper/api';
31
- const PLUGIN_VERSION = '0.1.5';
31
+ const PLUGIN_VERSION = '0.1.7';
32
32
  const META_NAME = '.dsh-keeper-trash.json';
33
33
  /** Pre-rename identifiers. Kept only so existing installs migrate in place. */
34
34
  const LEGACY_NS = 'sidebar-studio';
@@ -36,6 +36,25 @@ const LEGACY_META_NAME = '.sidebar-studio-trash.json';
36
36
  const LEGACY_BUNDLE = 'dsh-sidebar-studio';
37
37
  /** Bundle names the keeper may be installed under; every self-protection check must recognize all of them. */
38
38
  const SELF_BUNDLES = new Set(['dsh-keeper', 'dsh-keeper-plugin', LEGACY_BUNDLE]);
39
+ const PACKAGE_META = JSON.parse(fs.readFileSync(new URL('./package.json', import.meta.url), 'utf8'));
40
+ const ENGINE_RANGE = typeof PACKAGE_META?.engines?.dsh === 'string' ? PACKAGE_META.engines.dsh : '';
41
+
42
+ function detectHostVersion() {
43
+ const fromEnv = process.env.DSH_VERSION || process.env.DSH_DESKTOP_VERSION || '';
44
+ if (fromEnv && fromEnv.trim()) return fromEnv.trim();
45
+ try {
46
+ if (typeof process.resourcesPath === 'string' && process.resourcesPath) {
47
+ const manifestPath = path.join(process.resourcesPath, 'app.asar', 'dsh', 'package.json');
48
+ if (fs.existsSync(manifestPath)) {
49
+ const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
50
+ if (typeof manifest?.version === 'string') return manifest.version;
51
+ }
52
+ }
53
+ } catch {
54
+ /* host version detection is best effort */
55
+ }
56
+ return '';
57
+ }
39
58
 
40
59
  function isSelfEntryId(value) {
41
60
  return typeof value === 'string' && (value.indexOf('dsh-keeper') !== -1 || value.indexOf(LEGACY_BUNDLE) !== -1);
@@ -62,12 +81,25 @@ const NOTIFY_DEFAULTS = {
62
81
  volume: 100,
63
82
  sounds: { normal: { name: '' }, interrupt: { name: '' } },
64
83
  openOnClick: true,
84
+ // Quiet hours (DND): within the local-time window banners and tones are
85
+ // held back, but the notification center still records the entry.
86
+ quiet: { enabled: false, start: '22:00', end: '08:00' },
87
+ // Mute completion reminders only; failures and pending questions still pass.
88
+ muteDone: false,
89
+ // Workspace ids whose notifications are held back (history unaffected).
90
+ mutedWorkspaces: [],
91
+ // Notification-center history is stored per browser, but this setting lives
92
+ // with the other notification options so every browser follows the same rule.
93
+ // 0 = keep forever; otherwise entries older than N days are pruned.
94
+ recordEnabled: true,
95
+ historyDays: 30,
65
96
  };
66
97
 
67
98
  const DEFAULT_SETTINGS = {
68
99
  deleteMode: 'trash',
69
100
  confirmPurge: true,
70
101
  defaultExportFormat: 'md',
102
+ rowPreview: { enabled: true, delay: 400 },
71
103
  notifications: { ...NOTIFY_DEFAULTS },
72
104
  };
73
105
 
@@ -85,6 +117,11 @@ function normalizeNotifyLastChannels(value, fallback) {
85
117
  return { banner: true, sound: true };
86
118
  }
87
119
 
120
+ function normalizeClock(value, fallback) {
121
+ const match = /^([01]\d|2[0-3]):([0-5]\d)$/.exec(typeof value === 'string' ? value.trim() : '');
122
+ return match ? `${match[1]}:${match[2]}` : fallback;
123
+ }
124
+
88
125
  function normalizeNotificationSettings(value) {
89
126
  const raw = value && typeof value === 'object' ? value : {};
90
127
  // Older builds stored 'custom'; that synthetic tone is now the built-in
@@ -120,6 +157,17 @@ function normalizeNotificationSettings(value) {
120
157
  lastChannels,
121
158
  volume: Number.isFinite(volume) ? Math.max(0, Math.min(100, Math.round(volume))) : 100,
122
159
  sounds,
160
+ quiet: {
161
+ enabled: raw.quiet?.enabled === true,
162
+ start: normalizeClock(raw.quiet?.start, '22:00'),
163
+ end: normalizeClock(raw.quiet?.end, '08:00'),
164
+ },
165
+ muteDone: raw.muteDone === true,
166
+ mutedWorkspaces: Array.isArray(raw.mutedWorkspaces)
167
+ ? raw.mutedWorkspaces.filter((id) => typeof id === 'string' && id).slice(0, 100)
168
+ : [],
169
+ recordEnabled: raw.recordEnabled !== false,
170
+ historyDays: [0, 7, 30, 90].includes(Number(raw.historyDays)) ? Number(raw.historyDays) : 30,
123
171
  openOnClick: raw.openOnClick !== false,
124
172
  };
125
173
  }
@@ -347,6 +395,7 @@ function readState() {
347
395
  deleteMode: settings.deleteMode === 'delete' ? 'delete' : 'trash',
348
396
  confirmPurge: settings.confirmPurge !== false,
349
397
  defaultExportFormat: normalizeExportFormat(settings.defaultExportFormat),
398
+ rowPreview: normalizeRowPreview(settings.rowPreview),
350
399
  notifications: normalizeNotificationSettings(settings.notifications),
351
400
  },
352
401
  updatedAt: typeof state.updatedAt === 'number' ? state.updatedAt : 0,
@@ -361,6 +410,7 @@ function writeState(state) {
361
410
  deleteMode: state.settings?.deleteMode === 'delete' ? 'delete' : 'trash',
362
411
  confirmPurge: state.settings?.confirmPurge !== false,
363
412
  defaultExportFormat: normalizeExportFormat(state.settings?.defaultExportFormat),
413
+ rowPreview: normalizeRowPreview(state.settings?.rowPreview),
364
414
  notifications: normalizeNotificationSettings(state.settings?.notifications),
365
415
  },
366
416
  updatedAt: Date.now(),
@@ -633,6 +683,8 @@ async function sessionInfo(ctx, id, snapshot, dirMap, runningSet, registry) {
633
683
  running: runningSet.has(id),
634
684
  archived: registry.archived.has(id),
635
685
  pinned: registry.pinned.has(id),
686
+ origin: typeof snapshot?.header?.origin === 'string' ? snapshot.header.origin : '',
687
+ parentSession: typeof snapshot?.header?.parentSession === 'string' ? snapshot.header.parentSession : '',
636
688
  };
637
689
  }
638
690
 
@@ -806,6 +858,8 @@ async function buildBootstrap(ctx) {
806
858
 
807
859
  return {
808
860
  version: PLUGIN_VERSION,
861
+ engineRange: ENGINE_RANGE,
862
+ dshVersion: detectHostVersion(),
809
863
  panelId: PANEL_ID,
810
864
  state,
811
865
  workspaces,
@@ -816,6 +870,82 @@ async function buildBootstrap(ctx) {
816
870
  };
817
871
  }
818
872
 
873
+ /**
874
+ * Refresh display metadata for a small set of sessions. The client already
875
+ * owns the session catalog (membership, running, title), so only the fields
876
+ * that need storage access are computed here: `stat()` reads the header and
877
+ * revision without decoding the log, and `sessionInfo` reuses its per-session
878
+ * cache for quiet sessions. This keeps live refresh at roughly one header read
879
+ * per changed session instead of a full bootstrap scan.
880
+ */
881
+ async function sessionDetails(ctx, payload) {
882
+ const rawIds = Array.isArray(payload?.sessionIds) ? payload.sessionIds : [];
883
+ const ids = [];
884
+ const seen = new Set();
885
+ for (const rawId of rawIds) {
886
+ let id;
887
+ try {
888
+ id = assertSessionId(rawId);
889
+ } catch {
890
+ continue;
891
+ }
892
+ if (seen.has(id)) continue;
893
+ seen.add(id);
894
+ ids.push(id);
895
+ if (ids.length >= 200) break;
896
+ }
897
+ if (ids.length === 0) return { sessions: [] };
898
+
899
+ let registry;
900
+ try {
901
+ registry = readRegistryState();
902
+ } catch {
903
+ registry = { archived: new Set(), pinned: new Set() };
904
+ }
905
+
906
+ const snapshots = new Map();
907
+ const dirMap = new Map();
908
+ const missing = [];
909
+ for (const id of ids) {
910
+ let snapshot = null;
911
+ try {
912
+ snapshot = await ctx.sessionPersistence.stat(id);
913
+ } catch {
914
+ snapshot = null;
915
+ }
916
+ if (!snapshot) {
917
+ missing.push(id);
918
+ continue;
919
+ }
920
+ snapshots.set(id, snapshot);
921
+ const logPath = snapshot?.location?.kind === 'jsonl' && typeof snapshot.location.path === 'string'
922
+ ? snapshot.location.path
923
+ : '';
924
+ if (logPath) dirMap.set(id, { id, dir: path.dirname(logPath) });
925
+ }
926
+ if (missing.length > 0) {
927
+ const missingIds = new Set(missing);
928
+ try {
929
+ for (const entry of listSessionDirs()) {
930
+ if (missingIds.has(entry.id) && !dirMap.has(entry.id)) dirMap.set(entry.id, entry);
931
+ }
932
+ } catch {
933
+ /* directory scan is best effort */
934
+ }
935
+ }
936
+
937
+ const sessions = [];
938
+ for (const id of ids) {
939
+ try {
940
+ const info = await sessionInfo(ctx, id, snapshots.get(id), dirMap, new Set(), registry);
941
+ sessions.push(info);
942
+ } catch {
943
+ /* unreadable sessions keep their last known row on the client */
944
+ }
945
+ }
946
+ return { sessions };
947
+ }
948
+
819
949
  /** Whether this deployment can hand a workspace folder to the native desktop. */
820
950
  function canOpenWorkspacePath(ctx) {
821
951
  const controller = ctx.sessionController;
@@ -1417,6 +1547,14 @@ function normalizeExportFormat(value) {
1417
1547
  return EXPORT_FORMATS.includes(value) ? value : 'md';
1418
1548
  }
1419
1549
 
1550
+ const ROW_PREVIEW_DELAYS = [300, 400, 600, 800];
1551
+
1552
+ function normalizeRowPreview(value) {
1553
+ const raw = value && typeof value === 'object' ? value : {};
1554
+ const delay = ROW_PREVIEW_DELAYS.includes(raw.delay) ? raw.delay : 400;
1555
+ return { enabled: raw.enabled !== false, delay };
1556
+ }
1557
+
1420
1558
  function contentTextOf(content) {
1421
1559
  if (!Array.isArray(content)) return '';
1422
1560
  const parts = [];
@@ -2274,12 +2412,14 @@ function pushNotification(ctx, entry) {
2274
2412
  const rawSummary =
2275
2413
  entry.summary || (entry.kind === 'error' ? entry.detail : '') || meta.summary || '';
2276
2414
  const summary = truncate(stripMarkdown(String(rawSummary)), 100);
2415
+ const owner = sessionId ? workspaceContaining(ctx, sessionId) : null;
2277
2416
  const notification = {
2278
2417
  id: String(notificationSeq),
2279
2418
  kind: entry.kind,
2280
2419
  sessionId,
2281
2420
  title: meta.title,
2282
2421
  workspace: meta.workspace,
2422
+ workspaceId: owner?.id ?? '',
2283
2423
  model: meta.model,
2284
2424
  summary,
2285
2425
  detail: entry.detail ?? '',
@@ -2311,6 +2451,10 @@ function readNotifications(ctx, payload) {
2311
2451
  // model is available, so fill the gaps the first time it is read.
2312
2452
  for (const item of items) {
2313
2453
  if (!item.sessionId) continue;
2454
+ if (!item.workspaceId) {
2455
+ const owner = workspaceContaining(ctx, item.sessionId);
2456
+ if (owner) item.workspaceId = owner.id;
2457
+ }
2314
2458
  if (item.title && item.workspace && item.model && item.summary) continue;
2315
2459
  const meta = notificationMeta(ctx, null, item.sessionId);
2316
2460
  if (!item.title && meta.title) item.title = meta.title;
@@ -2671,6 +2815,7 @@ function clearNotificationSound(payload) {
2671
2815
  function createApi(ctx) {
2672
2816
  return {
2673
2817
  bootstrap: () => buildBootstrap(ctx),
2818
+ sessionDetails: (payload) => sessionDetails(ctx, payload),
2674
2819
  deleteSessions: (payload) => deleteSessions(ctx, payload),
2675
2820
  deleteSessionsPermanently: (payload) => deleteSessionsPermanently(ctx, payload),
2676
2821
  restoreSessions: (payload) => restoreSessions(ctx, payload),
@@ -2746,6 +2891,12 @@ function createApi(ctx) {
2746
2891
  if (EXPORT_FORMATS.includes(patch.defaultExportFormat)) {
2747
2892
  state.settings.defaultExportFormat = patch.defaultExportFormat;
2748
2893
  }
2894
+ if (patch.rowPreview && typeof patch.rowPreview === 'object') {
2895
+ state.settings.rowPreview = normalizeRowPreview({
2896
+ ...state.settings.rowPreview,
2897
+ ...patch.rowPreview,
2898
+ });
2899
+ }
2749
2900
  if (patch.notifications && typeof patch.notifications === 'object') {
2750
2901
  state.settings.notifications = normalizeNotificationSettings({
2751
2902
  ...state.settings.notifications,
@@ -2832,4 +2983,4 @@ export function apply(ctx) {
2832
2983
 
2833
2984
  /** Exported for tests and for the host package metadata. */
2834
2985
  export const plugin = { name, NS, PANEL_ID, version: PLUGIN_VERSION };
2835
- export { sessionInfo as _sessionInfo };
2986
+ export { sessionInfo as _sessionInfo, sessionDetails as _sessionDetails };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-keeper-plugin",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "DSH Keeper — manage DSH workspace sessions, plugins, sidebar entries, and notifications in one place. DSH 管家:集中管理 DSH 的会话、插件、侧栏入口与通知。",
5
5
  "icon": "icon.svg",
6
6
  "type": "module",