dsh-keeper-plugin 0.1.6 → 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 +134 -64
  2. package/client.js +1839 -275
  3. package/index.js +124 -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.6';
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);
@@ -69,12 +88,18 @@ const NOTIFY_DEFAULTS = {
69
88
  muteDone: false,
70
89
  // Workspace ids whose notifications are held back (history unaffected).
71
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,
72
96
  };
73
97
 
74
98
  const DEFAULT_SETTINGS = {
75
99
  deleteMode: 'trash',
76
100
  confirmPurge: true,
77
101
  defaultExportFormat: 'md',
102
+ rowPreview: { enabled: true, delay: 400 },
78
103
  notifications: { ...NOTIFY_DEFAULTS },
79
104
  };
80
105
 
@@ -141,6 +166,8 @@ function normalizeNotificationSettings(value) {
141
166
  mutedWorkspaces: Array.isArray(raw.mutedWorkspaces)
142
167
  ? raw.mutedWorkspaces.filter((id) => typeof id === 'string' && id).slice(0, 100)
143
168
  : [],
169
+ recordEnabled: raw.recordEnabled !== false,
170
+ historyDays: [0, 7, 30, 90].includes(Number(raw.historyDays)) ? Number(raw.historyDays) : 30,
144
171
  openOnClick: raw.openOnClick !== false,
145
172
  };
146
173
  }
@@ -368,6 +395,7 @@ function readState() {
368
395
  deleteMode: settings.deleteMode === 'delete' ? 'delete' : 'trash',
369
396
  confirmPurge: settings.confirmPurge !== false,
370
397
  defaultExportFormat: normalizeExportFormat(settings.defaultExportFormat),
398
+ rowPreview: normalizeRowPreview(settings.rowPreview),
371
399
  notifications: normalizeNotificationSettings(settings.notifications),
372
400
  },
373
401
  updatedAt: typeof state.updatedAt === 'number' ? state.updatedAt : 0,
@@ -382,6 +410,7 @@ function writeState(state) {
382
410
  deleteMode: state.settings?.deleteMode === 'delete' ? 'delete' : 'trash',
383
411
  confirmPurge: state.settings?.confirmPurge !== false,
384
412
  defaultExportFormat: normalizeExportFormat(state.settings?.defaultExportFormat),
413
+ rowPreview: normalizeRowPreview(state.settings?.rowPreview),
385
414
  notifications: normalizeNotificationSettings(state.settings?.notifications),
386
415
  },
387
416
  updatedAt: Date.now(),
@@ -829,6 +858,8 @@ async function buildBootstrap(ctx) {
829
858
 
830
859
  return {
831
860
  version: PLUGIN_VERSION,
861
+ engineRange: ENGINE_RANGE,
862
+ dshVersion: detectHostVersion(),
832
863
  panelId: PANEL_ID,
833
864
  state,
834
865
  workspaces,
@@ -839,6 +870,82 @@ async function buildBootstrap(ctx) {
839
870
  };
840
871
  }
841
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
+
842
949
  /** Whether this deployment can hand a workspace folder to the native desktop. */
843
950
  function canOpenWorkspacePath(ctx) {
844
951
  const controller = ctx.sessionController;
@@ -1440,6 +1547,14 @@ function normalizeExportFormat(value) {
1440
1547
  return EXPORT_FORMATS.includes(value) ? value : 'md';
1441
1548
  }
1442
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
+
1443
1558
  function contentTextOf(content) {
1444
1559
  if (!Array.isArray(content)) return '';
1445
1560
  const parts = [];
@@ -2700,6 +2815,7 @@ function clearNotificationSound(payload) {
2700
2815
  function createApi(ctx) {
2701
2816
  return {
2702
2817
  bootstrap: () => buildBootstrap(ctx),
2818
+ sessionDetails: (payload) => sessionDetails(ctx, payload),
2703
2819
  deleteSessions: (payload) => deleteSessions(ctx, payload),
2704
2820
  deleteSessionsPermanently: (payload) => deleteSessionsPermanently(ctx, payload),
2705
2821
  restoreSessions: (payload) => restoreSessions(ctx, payload),
@@ -2775,6 +2891,12 @@ function createApi(ctx) {
2775
2891
  if (EXPORT_FORMATS.includes(patch.defaultExportFormat)) {
2776
2892
  state.settings.defaultExportFormat = patch.defaultExportFormat;
2777
2893
  }
2894
+ if (patch.rowPreview && typeof patch.rowPreview === 'object') {
2895
+ state.settings.rowPreview = normalizeRowPreview({
2896
+ ...state.settings.rowPreview,
2897
+ ...patch.rowPreview,
2898
+ });
2899
+ }
2778
2900
  if (patch.notifications && typeof patch.notifications === 'object') {
2779
2901
  state.settings.notifications = normalizeNotificationSettings({
2780
2902
  ...state.settings.notifications,
@@ -2861,4 +2983,4 @@ export function apply(ctx) {
2861
2983
 
2862
2984
  /** Exported for tests and for the host package metadata. */
2863
2985
  export const plugin = { name, NS, PANEL_ID, version: PLUGIN_VERSION };
2864
- 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.6",
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",