dsh-perf-boost 0.1.0 → 0.2.1

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/index.js CHANGED
@@ -25,6 +25,9 @@ const LAST_ROUTE = '/api/dsh-perf-boost/last-run';
25
25
  // 页面每次启动端口都不一样(localhost:随机端口),localStorage 跟着端口走,
26
26
  // 所以要跨启动留一份「上次实测」只能落到宿主侧的文件里。
27
27
  const LAST_FILE = join(homedir(), '.dsh', 'perf-boost-last.json');
28
+ // 大会话预热开关:客户端只在设置页里改,宿主要能持久化,重启后仍然是你的选择。
29
+ const WARM_ROUTE = '/api/dsh-perf-boost/warmup';
30
+ const WARM_FILE = join(homedir(), '.dsh', 'perf-boost-warmup.json');
28
31
  const PACKAGE_NAME = 'dsh-perf-boost';
29
32
  // npmmirror 优先(国内快),失败再问官方源。
30
33
  const REGISTRIES = ['https://registry.npmmirror.com', 'https://registry.npmjs.org'];
@@ -75,36 +78,88 @@ async function fetchLatest(registry) {
75
78
 
76
79
  async function resolveLatest() {
77
80
  const now = Date.now();
78
- if (cache.at !== 0 && now - cache.at < CACHE_MS) return cache;
81
+ if (cache.at !== 0 && cache.at !== undefined && now - cache.at < CACHE_MS) return cache;
79
82
  let lastError = '未连接';
80
83
  let notPublished = false;
84
+ let best = null;
85
+ let bestSource = '';
81
86
  for (const registry of REGISTRIES) {
82
87
  try {
83
88
  const { version, source } = await fetchLatest(registry);
84
- cache = { at: now, latest: version, source, error: '' };
85
- return cache;
89
+ // 镜像可能比官方慢半拍,两边都问,取版本更高的那个,别被慢的镜像带偏。
90
+ if (best === null || isNewer(version, best)) {
91
+ best = version;
92
+ bestSource = source;
93
+ }
86
94
  } catch (error) {
87
95
  lastError = error?.message ?? String(error);
88
- // 两个镜像都 404 = 这个包还没发到 npm,不算「网络失败」。
96
+ // 所有镜像都 404 = 这个包还没发到 npm,不算「网络失败」。
89
97
  if (lastError === 'HTTP 404') notPublished = true;
90
98
  else notPublished = false;
91
99
  }
92
100
  }
101
+ if (best !== null) {
102
+ cache = { at: now, latest: best, source: bestSource, error: '' };
103
+ return cache;
104
+ }
93
105
  cache = { at: now, latest: null, source: '', error: notPublished ? 'not-published' : lastError };
94
106
  return cache;
95
107
  }
96
108
 
109
+ async function readWarmSetting() {
110
+ try {
111
+ const parsed = JSON.parse(await readFile(WARM_FILE, 'utf8'));
112
+ if (typeof parsed?.enabled === 'boolean') return parsed.enabled;
113
+ } catch {
114
+ // 没有文件 / 文件坏了:用默认值(开)
115
+ }
116
+ return true;
117
+ }
118
+
119
+ async function writeWarmSetting(enabled) {
120
+ try {
121
+ await mkdir(join(homedir(), '.dsh'), { recursive: true });
122
+ await writeFile(WARM_FILE, JSON.stringify({ enabled: !!enabled }), 'utf8');
123
+ } catch {
124
+ // 写不进去只影响「下次启动还记得吗」,本次开关照旧生效
125
+ }
126
+ }
127
+
97
128
  export function apply(ctx, config) {
98
129
  // 大会话预热(宿主侧,可关):把投影冷折叠从首屏挪到后台分片做。
99
130
  // 结构不认识时它会自己静默退出,不影响下面这条路由与客户端功能。
100
- try {
101
- const logger = typeof ctx.logger === 'function' ? ctx.logger('perf-boost') : { info() {}, warn: console.warn };
102
- if (!config || config.warmup !== false) {
103
- const warm = createWarmup({ ctx, logger, config: config || {} });
131
+ let warm = null;
132
+ let warmSetting = true; // 落盘的开关状态,和 warm 实例分开记
133
+ const warmBlocked = config?.warmup === false;
134
+ const warmLogger = (() => {
135
+ try {
136
+ return typeof ctx.logger === 'function' ? ctx.logger('perf-boost') : { info() {}, warn: console.warn };
137
+ } catch {
138
+ return { info() {}, warn: console.warn };
139
+ }
140
+ })();
141
+
142
+ function startWarm() {
143
+ if (warmBlocked || warm !== null) return;
144
+ try {
145
+ warm = createWarmup({ ctx, logger: warmLogger, config: config || {} });
104
146
  warm.start();
147
+ } catch (error) {
148
+ warm = null;
149
+ try { console.warn('[perf-boost] warmup 装配失败:', error?.message ?? error); } catch { void 0; }
105
150
  }
106
- } catch (error) {
107
- try { console.warn('[perf-boost] warmup 装配失败:', error?.message ?? error); } catch { void 0; }
151
+ }
152
+
153
+ function stopWarm() {
154
+ if (warm === null) return;
155
+ try { warm.stop(); } catch { void 0; }
156
+ warm = null;
157
+ }
158
+
159
+ if (!warmBlocked) {
160
+ readWarmSetting()
161
+ .then((on) => { warmSetting = on; if (on) startWarm(); })
162
+ .catch(() => { void 0; });
108
163
  }
109
164
 
110
165
  ctx.inject(['connection'], (c) => {
@@ -160,6 +215,36 @@ export function apply(ctx, config) {
160
215
  // 注册失败只是少一条缓存读取,面板会退回到只显示本次数据。
161
216
  }
162
217
 
218
+ // 预热开关:读/写都走这一条,写会落盘,重启后保持。
219
+ const warmHandler = async (request) => {
220
+ let body = null;
221
+ try {
222
+ const text = typeof request?.text === 'function' ? await request.text() : '';
223
+ if (text) body = JSON.parse(text);
224
+ } catch {
225
+ body = null;
226
+ }
227
+ if (body && typeof body.enabled === 'boolean') {
228
+ warmSetting = body.enabled;
229
+ await writeWarmSetting(body.enabled);
230
+ if (body.enabled) startWarm();
231
+ else stopWarm();
232
+ } else {
233
+ warmSetting = await readWarmSetting();
234
+ if (!warmBlocked && warmSetting && warm === null) startWarm();
235
+ }
236
+ return Response.json({ ok: true, value: { enabled: warmSetting && !warmBlocked } }, { headers: { 'cache-control': 'no-store' } });
237
+ };
238
+
239
+ try {
240
+ c.effect(
241
+ () => register({ path: WARM_ROUTE, methods: ['POST'], requestBody: 'buffered', fetch: warmHandler }),
242
+ 'dsh-perf-boost: /api/dsh-perf-boost/warmup',
243
+ );
244
+ } catch {
245
+ // 注册失败只是设置页那个开关不出现,预热仍按配置文件走。
246
+ }
247
+
163
248
  const handler = async () => {
164
249
  const [installed, resolved] = await Promise.all([readInstalledVersion(), resolveLatest()]);
165
250
  const latest = resolved.latest;
package/package.json CHANGED
@@ -1,56 +1,67 @@
1
- {
2
- "name": "dsh-perf-boost",
3
- "version": "0.1.0",
4
- "description": "DSH 桌面端性能优化(纯客户端):长对话省渲染、窗口隐藏不排帧默认开,关背景模糊/减少动画/空闲降帧按需打开,设置页显示实测省下的主线程时间。Client-side rendering optimizations for DeepSeek Harness Desktop.",
5
- "type": "module",
6
- "main": "lib/index.js",
7
- "exports": {
8
- ".": "./lib/index.js",
9
- "./client": "./lib/client.js"
10
- },
11
- "license": "MIT",
12
- "keywords": [
13
- "deepseek-harness",
14
- "dsh",
15
- "dsh-plugin",
16
- "performance",
17
- "fps",
18
- "requestanimationframe",
19
- "content-visibility"
20
- ],
21
- "files": [
22
- "lib",
23
- "assets",
24
- "cordis.patch.yml",
25
- "README.md",
26
- "LICENSE",
27
- "CHANGELOG.md"
28
- ],
29
- "engines": {
30
- "dsh": ">=0.2.0-0"
31
- },
32
- "peerDependencies": {
33
- "@deepseek-ai/cordis": "^4.0.1"
34
- },
35
- "repository": {
36
- "type": "git",
37
- "url": "git+https://github.com/AlLHHH/dsh-perf-boost.git"
38
- },
39
- "homepage": "https://github.com/AlLHHH/dsh-perf-boost#readme",
40
- "bugs": {
41
- "url": "https://github.com/AlLHHH/dsh-perf-boost/issues"
42
- },
43
- "sideEffects": false,
44
- "dsh": {
45
- "bundle": {
46
- "patch": "./cordis.patch.yml"
47
- },
48
- "client": {
49
- "platform": "web",
50
- "inject": [
51
- "slots",
52
- "sessions"
53
- ]
54
- }
55
- }
56
- }
1
+ {
2
+ "name": "dsh-perf-boost",
3
+ "version": "0.2.1",
4
+ "description": "DSH 桌面端性能优化(纯客户端):长对话省渲染、窗口隐藏不排帧默认开,关背景模糊/减少动画/空闲降帧按需打开,设置页显示实测省下的主线程时间。Client-side rendering optimizations for DeepSeek Harness Desktop.",
5
+ "type": "module",
6
+ "main": "lib/index.js",
7
+ "exports": {
8
+ ".": "./lib/index.js",
9
+ "./client": "./lib/client.js"
10
+ },
11
+ "license": "MIT",
12
+ "keywords": [
13
+ "deepseek-harness",
14
+ "dsh",
15
+ "dsh-plugin",
16
+ "performance",
17
+ "fps",
18
+ "requestanimationframe",
19
+ "content-visibility",
20
+ "性能优化",
21
+ "性能",
22
+ "优化",
23
+ "增强",
24
+ "流畅",
25
+ "加速",
26
+ "卡顿",
27
+ "省内存",
28
+ "faster",
29
+ "smooth",
30
+ "speed-up"
31
+ ],
32
+ "files": [
33
+ "lib",
34
+ "assets",
35
+ "cordis.patch.yml",
36
+ "README.md",
37
+ "LICENSE",
38
+ "CHANGELOG.md"
39
+ ],
40
+ "engines": {
41
+ "dsh": ">=0.2.0-0"
42
+ },
43
+ "peerDependencies": {
44
+ "@deepseek-ai/cordis": "^4.0.1"
45
+ },
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/AlLHHH/dsh-perf-boost.git"
49
+ },
50
+ "homepage": "https://github.com/AlLHHH/dsh-perf-boost#readme",
51
+ "bugs": {
52
+ "url": "https://github.com/AlLHHH/dsh-perf-boost/issues"
53
+ },
54
+ "sideEffects": false,
55
+ "dsh": {
56
+ "bundle": {
57
+ "patch": "./cordis.patch.yml"
58
+ },
59
+ "client": {
60
+ "platform": "web",
61
+ "inject": [
62
+ "slots",
63
+ "sessions"
64
+ ]
65
+ }
66
+ }
67
+ }