dsh-bagu 0.13.1 → 0.13.2

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/client.js CHANGED
@@ -335,19 +335,7 @@ window.__ModuleLoader__.load({
335
335
  onChange: () => save({ autoUpdate: view.autoUpdate === false }),
336
336
  })),
337
337
 
338
- view.autoUpdate !== false ? h('div', { 'data-bg-row': '' },
339
- h('div', { 'data-bg-grow': '' },
340
- h('div', { 'data-bg-label': '' }, '每天几点'),
341
- h('div', { 'data-bg-note': '' },
342
- '凌晨机器闲着,四点最稳。更新只补新词条,不动你改过的。')),
343
- h('select', {
344
- 'data-bg-num': '', 'data-wide': '', value: String(view.updateHour ?? 4),
345
- disabled: busy === 'save',
346
- onChange: (e) => save({ updateHour: Number(e.target.value) }),
347
- },
348
- Array.from({ length: 24 }, (_, i) =>
349
- h('option', { key: i, value: String(i) },
350
- String(i).padStart(2, '0') + ':00')))) : null,
338
+
351
339
 
352
340
  h(Row, {
353
341
  label: view.toneSwitch ? '尺度:自己定' : '尺度:交给模型',
package/dsh-plugin.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "manifestVersion": "0.15",
4
4
  "id": "dsh-bagu",
5
5
  "name": "dsh-bagu",
6
- "version": "0.13.1",
6
+ "version": "0.13.2",
7
7
  "license": "MIT",
8
8
  "description": "AI 对外说话两道门:八股打回,梗接住。",
9
9
  "facets": {
package/lib/config.js CHANGED
@@ -30,10 +30,8 @@ export const DEFAULTS = {
30
30
  memes: true,
31
31
  /** 每轮请求前自动查词库并注入。关掉就只在主动调工具时查。 */
32
32
  autoMeme: true,
33
- /** 词库每天自动更新。关掉就不再联网。 */
33
+ /** 词库自动更新:DSH 开着、距上次超过 20 小时就补。关掉就不再联网。 */
34
34
  autoUpdate: true,
35
- /** 每天几点更新,0-23。默认凌晨 4 点。 */
36
- updateHour: 4,
37
35
  /** 手动接管玩梗尺度。关着时交给模型自己判断。 */
38
36
  toneSwitch: false,
39
37
  /** 玩梗尺度 0-100。toneSwitch 关着时不生效。 */
package/lib/index.js CHANGED
@@ -352,17 +352,20 @@ export function apply(root, config = {}) {
352
352
  if (!live.autoUpdate) return;
353
353
  const st = dbStatus();
354
354
  if (!st.exists) return;
355
- const hour = new Date().getHours();
356
- const target = Math.max(0, Math.min(23, Number(live.updateHour) || 0));
357
- if (hour !== target) return;
358
- // 今天这个点已经跑过就不再跑
355
+ // DSH 是本地会话,不是常驻服务 —— 别指望它四点整点还开着。
356
+ // 实测:死等整点那套跑了九天一次都没成。
357
+ //
358
+ // 改成「距上次检查超过 20 小时就补」,不看几点。
359
+ // 启动后 90 秒查一次,之后每小时查一次(长开的会话也能自己补上)。
359
360
  const last = st.lastCheck ? Date.parse(st.lastCheck) : 0;
360
- if (last && new Date(last).toDateString() === new Date().toDateString()) return;
361
+ const stale = !last || (Date.now() - last) >= 20 * 60 * 60 * 1000;
362
+ if (!stale) return;
363
+
361
364
  updateOnce({ onLog: () => {} }).catch(() => {});
362
365
  } catch { /* 定时检查不能炸 */ }
363
366
  };
364
367
  // 启动后 30 秒看一次,之后每小时一次
365
- const first = setTimeout(tick, 30000);
368
+ const first = setTimeout(tick, 90000);
366
369
  const iv = setInterval(tick, 60 * 60 * 1000);
367
370
  // unref:不阻止进程退出。宿主不调清理函数时也不会挂住。
368
371
  if (typeof first.unref === 'function') first.unref();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-bagu",
3
- "version": "0.13.1",
3
+ "version": "0.13.2",
4
4
  "description": "两道门:八股打回(含空指代/拆句弹回/承诺收尾那套 DeepSeek 腔);梗接住(内置梗Wiki 6845 条,每天自动更新)。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -0,0 +1,46 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { readFileSync } from 'node:fs';
4
+
5
+ const INDEX = readFileSync('lib/index.js', 'utf8');
6
+
7
+ /**
8
+ * 定时更新的判据。
9
+ *
10
+ * 原来写的是「当前小时 === 配置的小时」,DSH 那一刻不在就永远错过。
11
+ * 实测九天一次没跑过(库里 last_check 停在 11-08,今天是 11-17)。
12
+ */
13
+
14
+ test('不许死等整点', () => {
15
+ // hour !== target 这种判法,错过那一小时就整天跳过。
16
+ assert.doesNotMatch(INDEX, /hour !== target/, '又改回死等整点了');
17
+ });
18
+
19
+ test('按「距上次超过 20 小时」判', () => {
20
+ assert.match(INDEX, /20 \* 60 \* 60 \* 1000/, '得有 20 小时的时间闸');
21
+ assert.match(INDEX, /stale/, '得算过不过期');
22
+ });
23
+
24
+ test('不看几点,到点就补', () => {
25
+ // 原来是「当前小时 === 配置的小时」,DSH 那一刻不在就整天跳过 —— 实测九天没跑成。
26
+ // 现在是距上次超过 20 小时就补,跟几点无关。
27
+ assert.doesNotMatch(INDEX, /hour < target/, '不该再卡小时');
28
+ assert.doesNotMatch(INDEX, /getHours\(\)/, '不该再看当前小时');
29
+ });
30
+
31
+ test('定时器要 unref,不能挂住进程', () => {
32
+ // 踩过:加了 setInterval 之后测试从 2.4 秒变卡死 90 秒。
33
+ assert.match(INDEX, /\.unref\(\)/);
34
+ });
35
+
36
+ test('autoUpdate 关掉就一次都不跑', () => {
37
+ assert.match(INDEX, /if \(!live\.autoUpdate\) return/);
38
+ });
39
+
40
+ test('首查留出开机缓冲', () => {
41
+ // 开机瞬间一堆东西抢网络,别第一秒就去翻 229 页。
42
+ const m = INDEX.match(/setTimeout\(tick,\s*(\d+)\)/);
43
+ assert.ok(m, '找不到首次 tick');
44
+ const ms = Number(m[1]);
45
+ assert.ok(ms >= 30000, `首查 ${ms}ms 太急,开机时网络还没稳`);
46
+ });
@@ -19,15 +19,17 @@ test('备份要轮转,不能只增不减', () => {
19
19
  assert.match(UPDATE, /pruneBackups\(log\)/, '写完备份要调一下');
20
20
  });
21
21
 
22
- test('更新按小时对齐,不跟启动时刻漂', () => {
23
- // 用 setInterval(24h) 会跟着启动时刻走,早上开机就永远早上更新。
24
- assert.match(INDEX, /getHours\(\)/, '得看当前小时');
25
- assert.match(INDEX, /live\.updateHour/, '得读配置里的小时');
26
- });
27
-
28
- test('同一天不重复跑', () => {
29
- assert.match(INDEX, /toDateString\(\)/, '得比日期,跑过就跳过');
30
- });
22
+ test('按「距上次超过 20 小时」判,不跟整点绑', () => {
23
+ // 死在整点上那套在 DSH 上不成立:DSH 不是常驻服务,四点不一定会开着。
24
+ assert.match(INDEX, /20 \* 60 \* 60 \* 1000/, '得有 20 小时的时间闸');
25
+ assert.doesNotMatch(INDEX, /live\.updateHour/, '不该再读小时配置');
26
+ });
27
+
28
+ test('刚跑过就不重复跑', () => {
29
+ // 判据从「同一天」改成「20 小时内」。原来按日期判,跨零点会重跑一次。
30
+ assert.match(INDEX, /stale/, '得算过不过期');
31
+ assert.doesNotMatch(INDEX, /toDateString\(\)/, '不该再按日期判');
32
+ });
31
33
 
32
34
  test('列表接口拿不到总数,翻页要容错', () => {
33
35
  // 接口只返回 items / limit / offset / has_more,没有 total。