dsh-keeper-plugin 0.1.6 → 0.1.8
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 +131 -64
- package/client.js +3800 -407
- package/index.js +204 -2
- 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.
|
|
31
|
+
const PLUGIN_VERSION = '0.1.8';
|
|
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,13 +88,22 @@ 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 },
|
|
104
|
+
// Manual "auto clean" suggestions; the client only previews and executes
|
|
105
|
+
// after an explicit confirmation, never on a background timer.
|
|
106
|
+
autoClean: { enabled: false, idleDays: 30, sizeMb: 100, includeBlank: false, action: 'archive', excludedWorkspaces: [] },
|
|
79
107
|
};
|
|
80
108
|
|
|
81
109
|
function normalizeSoundEntry(value) {
|
|
@@ -141,6 +169,8 @@ function normalizeNotificationSettings(value) {
|
|
|
141
169
|
mutedWorkspaces: Array.isArray(raw.mutedWorkspaces)
|
|
142
170
|
? raw.mutedWorkspaces.filter((id) => typeof id === 'string' && id).slice(0, 100)
|
|
143
171
|
: [],
|
|
172
|
+
recordEnabled: raw.recordEnabled !== false,
|
|
173
|
+
historyDays: [0, 7, 30, 90].includes(Number(raw.historyDays)) ? Number(raw.historyDays) : 30,
|
|
144
174
|
openOnClick: raw.openOnClick !== false,
|
|
145
175
|
};
|
|
146
176
|
}
|
|
@@ -290,6 +320,47 @@ function readDisabledPatches() {
|
|
|
290
320
|
return rows;
|
|
291
321
|
}
|
|
292
322
|
|
|
323
|
+
/**
|
|
324
|
+
* Read every profile patch block that toggles one plugin with a literal boolean
|
|
325
|
+
* `disabled`, so the UI can tell a manual override from the installation default.
|
|
326
|
+
* Conditional (`!!js`) patches are reported as conditional and never guessed.
|
|
327
|
+
*/
|
|
328
|
+
function readProfileOverrides() {
|
|
329
|
+
let text = '';
|
|
330
|
+
try {
|
|
331
|
+
text = fs.readFileSync(profilePatchFile(), 'utf8');
|
|
332
|
+
} catch {
|
|
333
|
+
return [];
|
|
334
|
+
}
|
|
335
|
+
const lines = text.split(/\r?\n/);
|
|
336
|
+
const blocks = [];
|
|
337
|
+
let current = null;
|
|
338
|
+
for (const line of lines) {
|
|
339
|
+
if (PATCH_BLOCK_START.test(line) || line.trim() === '-') {
|
|
340
|
+
if (current) blocks.push(current);
|
|
341
|
+
current = { lines: [line] };
|
|
342
|
+
} else if (current) {
|
|
343
|
+
current.lines.push(line);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (current) blocks.push(current);
|
|
347
|
+
const rows = [];
|
|
348
|
+
for (const block of blocks) {
|
|
349
|
+
const body = block.lines.join('\n');
|
|
350
|
+
const idMatch = block.lines.map((line) => line.match(PATCH_BLOCK_ID)).find(Boolean);
|
|
351
|
+
if (!idMatch) continue;
|
|
352
|
+
const literal = body.match(/^\s*disabled:\s*(true|false)\s*$/m);
|
|
353
|
+
const conditional = /^\s*disabled:\s*!!js/m.test(body) || /!!js|!!str/.test(body);
|
|
354
|
+
if (!literal && !conditional) continue;
|
|
355
|
+
rows.push({
|
|
356
|
+
id: idMatch[1],
|
|
357
|
+
disabled: literal ? literal[1] === 'true' : null,
|
|
358
|
+
conditional,
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
return rows;
|
|
362
|
+
}
|
|
363
|
+
|
|
293
364
|
/** Remove one pure `- id / disabled: true` override so the Loader mounts it again. */
|
|
294
365
|
function enableDisabledPatch(patchId) {
|
|
295
366
|
let text = '';
|
|
@@ -368,7 +439,9 @@ function readState() {
|
|
|
368
439
|
deleteMode: settings.deleteMode === 'delete' ? 'delete' : 'trash',
|
|
369
440
|
confirmPurge: settings.confirmPurge !== false,
|
|
370
441
|
defaultExportFormat: normalizeExportFormat(settings.defaultExportFormat),
|
|
442
|
+
rowPreview: normalizeRowPreview(settings.rowPreview),
|
|
371
443
|
notifications: normalizeNotificationSettings(settings.notifications),
|
|
444
|
+
autoClean: normalizeAutoCleanSettings(settings.autoClean),
|
|
372
445
|
},
|
|
373
446
|
updatedAt: typeof state.updatedAt === 'number' ? state.updatedAt : 0,
|
|
374
447
|
};
|
|
@@ -382,7 +455,9 @@ function writeState(state) {
|
|
|
382
455
|
deleteMode: state.settings?.deleteMode === 'delete' ? 'delete' : 'trash',
|
|
383
456
|
confirmPurge: state.settings?.confirmPurge !== false,
|
|
384
457
|
defaultExportFormat: normalizeExportFormat(state.settings?.defaultExportFormat),
|
|
458
|
+
rowPreview: normalizeRowPreview(state.settings?.rowPreview),
|
|
385
459
|
notifications: normalizeNotificationSettings(state.settings?.notifications),
|
|
460
|
+
autoClean: normalizeAutoCleanSettings(state.settings?.autoClean),
|
|
386
461
|
},
|
|
387
462
|
updatedAt: Date.now(),
|
|
388
463
|
};
|
|
@@ -829,6 +904,8 @@ async function buildBootstrap(ctx) {
|
|
|
829
904
|
|
|
830
905
|
return {
|
|
831
906
|
version: PLUGIN_VERSION,
|
|
907
|
+
engineRange: ENGINE_RANGE,
|
|
908
|
+
dshVersion: detectHostVersion(),
|
|
832
909
|
panelId: PANEL_ID,
|
|
833
910
|
state,
|
|
834
911
|
workspaces,
|
|
@@ -839,6 +916,82 @@ async function buildBootstrap(ctx) {
|
|
|
839
916
|
};
|
|
840
917
|
}
|
|
841
918
|
|
|
919
|
+
/**
|
|
920
|
+
* Refresh display metadata for a small set of sessions. The client already
|
|
921
|
+
* owns the session catalog (membership, running, title), so only the fields
|
|
922
|
+
* that need storage access are computed here: `stat()` reads the header and
|
|
923
|
+
* revision without decoding the log, and `sessionInfo` reuses its per-session
|
|
924
|
+
* cache for quiet sessions. This keeps live refresh at roughly one header read
|
|
925
|
+
* per changed session instead of a full bootstrap scan.
|
|
926
|
+
*/
|
|
927
|
+
async function sessionDetails(ctx, payload) {
|
|
928
|
+
const rawIds = Array.isArray(payload?.sessionIds) ? payload.sessionIds : [];
|
|
929
|
+
const ids = [];
|
|
930
|
+
const seen = new Set();
|
|
931
|
+
for (const rawId of rawIds) {
|
|
932
|
+
let id;
|
|
933
|
+
try {
|
|
934
|
+
id = assertSessionId(rawId);
|
|
935
|
+
} catch {
|
|
936
|
+
continue;
|
|
937
|
+
}
|
|
938
|
+
if (seen.has(id)) continue;
|
|
939
|
+
seen.add(id);
|
|
940
|
+
ids.push(id);
|
|
941
|
+
if (ids.length >= 200) break;
|
|
942
|
+
}
|
|
943
|
+
if (ids.length === 0) return { sessions: [] };
|
|
944
|
+
|
|
945
|
+
let registry;
|
|
946
|
+
try {
|
|
947
|
+
registry = readRegistryState();
|
|
948
|
+
} catch {
|
|
949
|
+
registry = { archived: new Set(), pinned: new Set() };
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
const snapshots = new Map();
|
|
953
|
+
const dirMap = new Map();
|
|
954
|
+
const missing = [];
|
|
955
|
+
for (const id of ids) {
|
|
956
|
+
let snapshot = null;
|
|
957
|
+
try {
|
|
958
|
+
snapshot = await ctx.sessionPersistence.stat(id);
|
|
959
|
+
} catch {
|
|
960
|
+
snapshot = null;
|
|
961
|
+
}
|
|
962
|
+
if (!snapshot) {
|
|
963
|
+
missing.push(id);
|
|
964
|
+
continue;
|
|
965
|
+
}
|
|
966
|
+
snapshots.set(id, snapshot);
|
|
967
|
+
const logPath = snapshot?.location?.kind === 'jsonl' && typeof snapshot.location.path === 'string'
|
|
968
|
+
? snapshot.location.path
|
|
969
|
+
: '';
|
|
970
|
+
if (logPath) dirMap.set(id, { id, dir: path.dirname(logPath) });
|
|
971
|
+
}
|
|
972
|
+
if (missing.length > 0) {
|
|
973
|
+
const missingIds = new Set(missing);
|
|
974
|
+
try {
|
|
975
|
+
for (const entry of listSessionDirs()) {
|
|
976
|
+
if (missingIds.has(entry.id) && !dirMap.has(entry.id)) dirMap.set(entry.id, entry);
|
|
977
|
+
}
|
|
978
|
+
} catch {
|
|
979
|
+
/* directory scan is best effort */
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
const sessions = [];
|
|
984
|
+
for (const id of ids) {
|
|
985
|
+
try {
|
|
986
|
+
const info = await sessionInfo(ctx, id, snapshots.get(id), dirMap, new Set(), registry);
|
|
987
|
+
sessions.push(info);
|
|
988
|
+
} catch {
|
|
989
|
+
/* unreadable sessions keep their last known row on the client */
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
return { sessions };
|
|
993
|
+
}
|
|
994
|
+
|
|
842
995
|
/** Whether this deployment can hand a workspace folder to the native desktop. */
|
|
843
996
|
function canOpenWorkspacePath(ctx) {
|
|
844
997
|
const controller = ctx.sessionController;
|
|
@@ -1440,6 +1593,41 @@ function normalizeExportFormat(value) {
|
|
|
1440
1593
|
return EXPORT_FORMATS.includes(value) ? value : 'md';
|
|
1441
1594
|
}
|
|
1442
1595
|
|
|
1596
|
+
const ROW_PREVIEW_DELAYS = [300, 400, 600, 800];
|
|
1597
|
+
|
|
1598
|
+
function normalizeRowPreview(value) {
|
|
1599
|
+
const raw = value && typeof value === 'object' ? value : {};
|
|
1600
|
+
const delay = ROW_PREVIEW_DELAYS.includes(raw.delay) ? raw.delay : 400;
|
|
1601
|
+
return { enabled: raw.enabled !== false, delay };
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1604
|
+
const AUTO_CLEAN_ACTIONS = ['archive', 'trash'];
|
|
1605
|
+
|
|
1606
|
+
function normalizeAutoCleanSettings(value) {
|
|
1607
|
+
const raw = value && typeof value === 'object' ? value : {};
|
|
1608
|
+
const clampInt = (input, min, max, fallback) => {
|
|
1609
|
+
const number = Number(input);
|
|
1610
|
+
if (!Number.isFinite(number)) return fallback;
|
|
1611
|
+
return Math.min(max, Math.max(min, Math.round(number)));
|
|
1612
|
+
};
|
|
1613
|
+
return {
|
|
1614
|
+
enabled: raw.enabled === true,
|
|
1615
|
+
idleDays: clampInt(raw.idleDays, 0, 3650, 30),
|
|
1616
|
+
sizeMb: clampInt(raw.sizeMb, 0, 102400, 100),
|
|
1617
|
+
includeBlank: raw.includeBlank === true,
|
|
1618
|
+
action: AUTO_CLEAN_ACTIONS.includes(raw.action) ? raw.action : 'archive',
|
|
1619
|
+
excludedWorkspaces: Array.isArray(raw.excludedWorkspaces)
|
|
1620
|
+
? [
|
|
1621
|
+
...new Set(
|
|
1622
|
+
raw.excludedWorkspaces.filter(
|
|
1623
|
+
(id) => typeof id === 'string' && id.length > 0 && id.length < 200,
|
|
1624
|
+
),
|
|
1625
|
+
),
|
|
1626
|
+
]
|
|
1627
|
+
: [],
|
|
1628
|
+
};
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1443
1631
|
function contentTextOf(content) {
|
|
1444
1632
|
if (!Array.isArray(content)) return '';
|
|
1445
1633
|
const parts = [];
|
|
@@ -2700,6 +2888,7 @@ function clearNotificationSound(payload) {
|
|
|
2700
2888
|
function createApi(ctx) {
|
|
2701
2889
|
return {
|
|
2702
2890
|
bootstrap: () => buildBootstrap(ctx),
|
|
2891
|
+
sessionDetails: (payload) => sessionDetails(ctx, payload),
|
|
2703
2892
|
deleteSessions: (payload) => deleteSessions(ctx, payload),
|
|
2704
2893
|
deleteSessionsPermanently: (payload) => deleteSessionsPermanently(ctx, payload),
|
|
2705
2894
|
restoreSessions: (payload) => restoreSessions(ctx, payload),
|
|
@@ -2739,6 +2928,7 @@ function createApi(ctx) {
|
|
|
2739
2928
|
}
|
|
2740
2929
|
return readPluginScopes(ctx);
|
|
2741
2930
|
},
|
|
2931
|
+
profileOverrides: () => ({ overrides: readProfileOverrides() }),
|
|
2742
2932
|
notifications: async (payload) => readNotifications(ctx, payload),
|
|
2743
2933
|
debugLog: async (payload) => {
|
|
2744
2934
|
if (payload && typeof payload.message === 'string') {
|
|
@@ -2775,12 +2965,24 @@ function createApi(ctx) {
|
|
|
2775
2965
|
if (EXPORT_FORMATS.includes(patch.defaultExportFormat)) {
|
|
2776
2966
|
state.settings.defaultExportFormat = patch.defaultExportFormat;
|
|
2777
2967
|
}
|
|
2968
|
+
if (patch.rowPreview && typeof patch.rowPreview === 'object') {
|
|
2969
|
+
state.settings.rowPreview = normalizeRowPreview({
|
|
2970
|
+
...state.settings.rowPreview,
|
|
2971
|
+
...patch.rowPreview,
|
|
2972
|
+
});
|
|
2973
|
+
}
|
|
2778
2974
|
if (patch.notifications && typeof patch.notifications === 'object') {
|
|
2779
2975
|
state.settings.notifications = normalizeNotificationSettings({
|
|
2780
2976
|
...state.settings.notifications,
|
|
2781
2977
|
...patch.notifications,
|
|
2782
2978
|
});
|
|
2783
2979
|
}
|
|
2980
|
+
if (patch.autoClean && typeof patch.autoClean === 'object') {
|
|
2981
|
+
state.settings.autoClean = normalizeAutoCleanSettings({
|
|
2982
|
+
...state.settings.autoClean,
|
|
2983
|
+
...patch.autoClean,
|
|
2984
|
+
});
|
|
2985
|
+
}
|
|
2784
2986
|
const saved = writeState(state);
|
|
2785
2987
|
return { state: saved };
|
|
2786
2988
|
},
|
|
@@ -2861,4 +3063,4 @@ export function apply(ctx) {
|
|
|
2861
3063
|
|
|
2862
3064
|
/** Exported for tests and for the host package metadata. */
|
|
2863
3065
|
export const plugin = { name, NS, PANEL_ID, version: PLUGIN_VERSION };
|
|
2864
|
-
export { sessionInfo as _sessionInfo };
|
|
3066
|
+
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.
|
|
3
|
+
"version": "0.1.8",
|
|
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",
|