dsh-hub-center 0.12.2 → 0.12.3

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/CHANGELOG.md ADDED
@@ -0,0 +1,26 @@
1
+ # 更新日志
2
+
3
+ 中枢(dsh-hub-center)每次发版动了什么,按版本倒序记在这儿。
4
+ 中枢面板里也有同一份记录:「更新」页能看到最近改了啥。
5
+
6
+ ## 0.12.3 — 2026-11-23
7
+
8
+ ### 新增
9
+
10
+ - 记忆质检:`GET /hub-center/memory/audit` 扫一遍库,给出分数和可修项(缺标签、缺权重、孤立条目之类)
11
+ - 记忆修复:`POST /hub-center/memory/repair` 按项修,支持 `dryRun` 先看再动,修完在事件日志里记一条 `audit`
12
+ - 中枢加「更新」页:按时间记每次新加了什么功能、修了什么,可以手动补记;任务页底部显示最近三条
13
+ - 设置页改成自适应网格:窗口宽两列、窄一列,不再一路拉长
14
+
15
+ ### 修复
16
+
17
+ - 身体状态里「精神」写反了:原来醒着回精神、睡着掉精神,改成醒着耗、睡着回,不会再越睡越困
18
+ - 设置页「主动找你 / 群聊 / 自主行为」三块渲染不出来(前台引用了个没定义的变量,整段中断),现在都回来了
19
+
20
+ ## 0.12.2 — 2026-11-21
21
+
22
+ - 对着 DSH 2.0.22-next 调;修了装不上 / 面板拉不起来的几个问题
23
+
24
+ ## 更早
25
+
26
+ 早期版本没有单独记录,改动都散在各次提交里。
package/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # dsh-hub-center(左栏中枢)安装说明
2
2
 
3
3
  > 这是一个 DSH 插件:装好后 DSH 左栏会多一个图标,点开是中枢界面(记忆、日记、表情、看板、设置)。
4
- > 版本:0.12.2(对着 DSH 2.0.22-next 调的)· 许可:MIT(本包内代码与配置,含 presets\表情模板.yml)· 图标 icon.svg 为自绘
4
+ > 版本:0.12.3(对着 DSH 2.0.22-next 调的)· 许可:MIT(本包内代码与配置,含 presets\表情模板.yml)· 图标 icon.svg 为自绘
5
+ > 每次改了什么记在 [CHANGELOG.md](CHANGELOG.md)
5
6
 
6
7
  ---
7
8
 
@@ -166,5 +167,7 @@ POST /hub-center/paths 改路径
166
167
  GET /hub-center/features 功能开关
167
168
  POST /hub-center/features 改开关
168
169
  GET /hub-center/setup 网页设置页(路径 + 功能开关)
170
+ GET /hub-center/memory/audit 记忆质检(分数 + 可修项)
171
+ POST /hub-center/memory/repair 记忆修复(body 里带 items / dryRun)
169
172
  ```
170
173
 
package/index.js CHANGED
@@ -9,13 +9,14 @@ import { spawn } from 'node:child_process'
9
9
  // 原来三个独立小插件并进来:跨窗口总线、语音朗读(客户端那个「任务」按钮在 client.js)
10
10
  import { apply as applySessionBus } from './lib/session-bus.js'
11
11
  import { apply as applyVoice } from './lib/voice.js'
12
- import { createRestore } from './lib/restore.js'
12
+ import { createRestore } from './lib/restore.js'
13
+ import { createAudit } from './lib/mem-audit.js'
13
14
  import { createModuleHost, moduleDir } from './lib/platform.js'
14
15
 
15
16
  export const name = 'dsh-hub-center'
16
17
  export const inject = ['webServer']
17
18
 
18
- const VERSION = '0.12.2'
19
+ const VERSION = '0.12.3'
19
20
  // 这一版是对着哪代 DSH 调的,状态接口和首屏「关于」都带出去
20
21
  const DSH_VERSION = '2.0.22-next'
21
22
  const HOME = process.env.DSH_HOME || join(homedir(), '.dsh')
@@ -1998,6 +1999,39 @@ export async function apply(ctx, config) {
1998
1999
  send(res, 200, { ok: true, ...r })
1999
2000
  })
2000
2001
 
2002
+ // ---- 记忆质检:先扫一遍看分数,再按项修 ----
2003
+ let auditApi = null
2004
+ const getAudit = () => auditApi || (auditApi = createAudit({ dbPath: join(BASE, 'hub.db') }))
2005
+
2006
+ route('/hub-center/memory/audit', async (req, res) => {
2007
+ try {
2008
+ const r = await getAudit().audit()
2009
+ send(res, 200, { ok: true, ...r })
2010
+ } catch (e) {
2011
+ send(res, 500, { ok: false, error: e && e.message ? e.message : String(e) })
2012
+ }
2013
+ })
2014
+
2015
+ route('/hub-center/memory/repair', async (req, res) => {
2016
+ if (req.method !== 'POST') return send(res, 405, { ok: false, error: 'POST only' })
2017
+ const body = await readBody(req)
2018
+ try {
2019
+ const r = await getAudit().repair({
2020
+ items: Array.isArray(body.items) ? body.items : [],
2021
+ dryRun: !!body.dryRun,
2022
+ halfLifeDays: Number(body.halfLifeDays) || HALF_LIFE_DAYS,
2023
+ })
2024
+ if (!body.dryRun) {
2025
+ try {
2026
+ store.emit({ module: 'memory', level: 'info', kind: 'audit', summary: '质检修复:' + ((body.items || []).join('/') || '默认项') })
2027
+ } catch {}
2028
+ }
2029
+ send(res, 200, r)
2030
+ } catch (e) {
2031
+ send(res, 500, { ok: false, error: e && e.message ? e.message : String(e) })
2032
+ }
2033
+ })
2034
+
2001
2035
  // ---- 解档:把被裁断(压缩)掉的原文按时间线拼回来 ----
2002
2036
  let restoreApi = null
2003
2037
  const getRestore = () => restoreApi || (restoreApi = createRestore({ storeDir: DSCTX_DIR, outDir: RESTORE_OUT }))
@@ -0,0 +1,289 @@
1
+ // 记忆质检:扫库找毛病 + 按项修。
2
+ // 只改 eff / archived / importance / 索引,删数据的一律不做(要删走 /memory/delete)。
3
+ import { join } from 'node:path'
4
+
5
+ const HALF_LIFE_DAYS = 60
6
+ const LONG = 800
7
+
8
+ // 默认重要度:老数据一大片 0.4,等于没区分;按来源给个底分,再按使用痕迹微调
9
+ const SOURCE_BASE = {
10
+ publish: 0.78, diary: 0.72, dsh: 0.7, distill: 0.66, digest: 0.62, 'event-digest': 0.6,
11
+ qq: 0.6, fact: 0.62, 'asset-sync': 0.52, travel: 0.5, home: 0.5,
12
+ 'dsh-session': 0.46, auto: 0.4, selfie: 0.34,
13
+ }
14
+
15
+ function tagsToText(raw) {
16
+ if (!raw) return ''
17
+ try {
18
+ const v = JSON.parse(raw)
19
+ return Array.isArray(v) ? v.join(' ') : String(v)
20
+ } catch {
21
+ return String(raw).replace(/[\[\]",]/g, ' ')
22
+ }
23
+ }
24
+
25
+ export function createAudit({ dbPath, now = () => Date.now() }) {
26
+ let db = null
27
+
28
+ async function open() {
29
+ if (db) return db
30
+ const { DatabaseSync } = await import('node:sqlite')
31
+ db = new DatabaseSync(dbPath)
32
+ db.exec('PRAGMA journal_mode=WAL; PRAGMA busy_timeout=5000;')
33
+ return db
34
+ }
35
+
36
+ function hasTable(name) {
37
+ const r = db.prepare("SELECT 1 FROM sqlite_master WHERE type IN ('table','view') AND name=?").get(name)
38
+ return !!r
39
+ }
40
+
41
+ // ---------- 体检 ----------
42
+ async function audit() {
43
+ await open()
44
+ const total = Number(db.prepare('SELECT COUNT(*) c FROM memories').get().c)
45
+ const archived = Number(db.prepare('SELECT COUNT(*) c FROM memories WHERE archived=1').get().c)
46
+ const live = total - archived
47
+
48
+ const ftsRows = hasTable('memories_fts') ? Number(db.prepare('SELECT COUNT(*) c FROM memories_fts').get().c) : 0
49
+
50
+ // 该建索引却没建的
51
+ const missingFts = hasTable('memories_fts')
52
+ ? Number(db.prepare('SELECT COUNT(*) c FROM memories WHERE id NOT IN (SELECT id FROM memories_fts)').get().c)
53
+ : live
54
+
55
+ // 索引里有、记忆里没有的(孤儿)
56
+ const orphanFts = hasTable('memories_fts')
57
+ ? Number(db.prepare('SELECT COUNT(*) c FROM memories_fts WHERE id NOT IN (SELECT id FROM memories)').get().c)
58
+ : 0
59
+
60
+ // 重要度:还卡在默认档的有多少(老数据两种默认值:0.4 和 0.45)
61
+ const flat = Number(
62
+ db.prepare('SELECT COUNT(*) c FROM memories WHERE importance IS NULL OR ABS(importance-0.4) < 0.01 OR ABS(importance-0.45) < 0.01').get().c,
63
+ )
64
+
65
+ // 有效权重塌陷:decay 跑过头,一堆 eff 贴在 0 附近,排序等于瞎排
66
+ const sunk = hasTable('memories') && db.prepare('PRAGMA table_info(memories)').all().some((r) => r.name === 'eff')
67
+ ? Number(db.prepare('SELECT COUNT(*) c FROM memories WHERE archived=0 AND importance >= 0.3 AND (eff IS NULL OR eff < 0.15)').get().c)
68
+ : 0
69
+
70
+ const len = db.prepare('SELECT AVG(LENGTH(text)) a, COUNT(*) c FROM memories WHERE LENGTH(text) > ?').get(LONG)
71
+
72
+ const noTags = Number(db.prepare("SELECT COUNT(*) c FROM memories WHERE tags IS NULL OR tags='' OR tags='[]'").get().c)
73
+
74
+ const vecRows = hasTable('mem_vec') ? Number(db.prepare('SELECT COUNT(*) c FROM mem_vec').get().c) : 0
75
+ const missingVec = hasTable('mem_vec')
76
+ ? Number(db.prepare('SELECT COUNT(*) c FROM memories WHERE id NOT IN (SELECT id FROM mem_vec)').get().c)
77
+ : 0
78
+
79
+ const dup = db.prepare('SELECT text, COUNT(*) c, SUM(CASE WHEN archived=0 THEN 1 ELSE 0 END) live FROM memories WHERE archived=0 GROUP BY text HAVING c > 1').all()
80
+ const dupExtra = dup.reduce((s, r) => s + (Number(r.c) - 1), 0)
81
+
82
+ const items = [
83
+ {
84
+ key: 'fts',
85
+ label: '全文索引',
86
+ count: missingFts,
87
+ severity: missingFts > live * 0.1 ? 'high' : missingFts > 0 ? 'mid' : 'ok',
88
+ hint: missingFts ? `${missingFts} 条记忆没进全文索引,按关键词搜基本搜不到;重建一次就好` : '索引齐',
89
+ },
90
+ {
91
+ key: 'importance',
92
+ label: '重要度分层',
93
+ count: flat,
94
+ severity: flat > live * 0.3 ? 'high' : flat > 0 ? 'mid' : 'ok',
95
+ hint: flat ? `${flat} 条还是默认的 0.4,排序时没有区分度;可按来源回填` : '分层正常',
96
+ },
97
+ {
98
+ key: 'eff',
99
+ label: '有效权重塌陷',
100
+ count: sunk,
101
+ severity: sunk > live * 0.3 ? 'high' : sunk > 0 ? 'mid' : 'ok',
102
+ hint: sunk ? `${sunk} 条 eff 贴在 0.15 以下(衰减跑过头),检索时几乎排不上号;重算一次并加下限` : '权重分布正常',
103
+ },
104
+ {
105
+ key: 'longtext',
106
+ label: '超长条目',
107
+ count: Number(len.c),
108
+ severity: Number(len.c) > 200 ? 'mid' : Number(len.c) > 0 ? 'low' : 'ok',
109
+ hint: Number(len.c) ? `${len.c} 条超过 ${LONG} 字,命中后会整段塞进上下文;建议切段(这一项只报不自动切)` : '长度合理',
110
+ },
111
+ {
112
+ key: 'tags',
113
+ label: '标签空缺',
114
+ count: noTags,
115
+ severity: noTags > live * 0.1 ? 'mid' : noTags > 0 ? 'low' : 'ok',
116
+ hint: noTags ? `${noTags} 条没有标签,分类找不着它们` : '都有标签',
117
+ },
118
+ {
119
+ key: 'dup',
120
+ label: '重复',
121
+ count: dupExtra,
122
+ severity: dupExtra > 20 ? 'mid' : dupExtra > 0 ? 'low' : 'ok',
123
+ hint: dupExtra ? `${dup.length} 组重复,多出 ${dupExtra} 条;保留重要的那条,其余归档` : '没有重复',
124
+ },
125
+ {
126
+ key: 'vec',
127
+ label: '向量覆盖',
128
+ count: missingVec,
129
+ severity: missingVec > live * 0.05 ? 'mid' : missingVec > 0 ? 'low' : 'ok',
130
+ hint: missingVec ? `${missingVec} 条没有向量,语义检索摸不到` : '全都有向量',
131
+ },
132
+ {
133
+ key: 'orphan',
134
+ label: '索引孤儿',
135
+ count: orphanFts,
136
+ severity: orphanFts > 0 ? 'low' : 'ok',
137
+ hint: orphanFts ? `${orphanFts} 条索引指向已不存在的记忆,清掉` : '没有孤儿',
138
+ },
139
+ ]
140
+
141
+ const weight = { high: 22, mid: 10, low: 4, ok: 0 }
142
+ const penalty = items.reduce((s, it) => s + weight[it.severity], 0)
143
+ const score = Math.max(0, Math.min(100, 100 - penalty))
144
+
145
+ return {
146
+ score,
147
+ ok: score >= 85,
148
+ at: now(),
149
+ total,
150
+ live,
151
+ archived,
152
+ ftsRows,
153
+ vecRows,
154
+ avgLen: Math.round(Number(len.a) || 0),
155
+ items,
156
+ }
157
+ }
158
+
159
+ // ---------- 修 ----------
160
+ async function repair({ items = [], dryRun = false, halfLifeDays = HALF_LIFE_DAYS } = {}) {
161
+ await open()
162
+ const want = new Set(items.length ? items : ['fts', 'importance', 'decay', 'dup', 'orphan'])
163
+ if (want.has('eff')) { want.delete('eff'); want.add('decay') } // UI 里叫 eff,内部叫 decay
164
+ const report = {}
165
+
166
+ if (want.has('fts')) {
167
+ let n = 0
168
+ if (!hasTable('memories_fts')) {
169
+ db.exec("CREATE VIRTUAL TABLE memories_fts USING fts5(id UNINDEXED, text, tags)")
170
+ }
171
+ if (!dryRun) {
172
+ const rows = db.prepare('SELECT id, text, tags FROM memories').all()
173
+ const ins = db.prepare('INSERT INTO memories_fts (id,text,tags) VALUES (?,?,?)')
174
+ db.exec('BEGIN')
175
+ try {
176
+ db.exec('DELETE FROM memories_fts')
177
+ for (const r of rows) {
178
+ ins.run(r.id, String(r.text || ''), tagsToText(r.tags))
179
+ n++
180
+ }
181
+ db.exec('COMMIT')
182
+ } catch (e) {
183
+ db.exec('ROLLBACK')
184
+ throw e
185
+ }
186
+ }
187
+ report.fts = { rebuilt: n, dryRun }
188
+ }
189
+
190
+ if (want.has('orphan')) {
191
+ let n = 0
192
+ if (hasTable('memories_fts')) {
193
+ if (!dryRun) {
194
+ const info = db.prepare('DELETE FROM memories_fts WHERE id NOT IN (SELECT id FROM memories)').run()
195
+ n = Number(info.changes || 0)
196
+ }
197
+ }
198
+ report.orphan = { removed: n, dryRun }
199
+ }
200
+
201
+ if (want.has('importance')) {
202
+ let n = 0
203
+ const rows = db.prepare('SELECT id, source, kind, tags, text, importance, use_count, created FROM memories').all()
204
+ const upd = db.prepare('UPDATE memories SET importance=? WHERE id=?')
205
+ if (!dryRun) db.exec('BEGIN')
206
+ try {
207
+ for (const r of rows) {
208
+ const cur = Number(r.importance)
209
+ const flatNow = !Number.isFinite(cur) || Math.abs(cur - 0.4) < 0.01 || Math.abs(cur - 0.45) < 0.01
210
+ if (!flatNow) continue
211
+ const base = SOURCE_BASE[r.source] ?? SOURCE_BASE[r.kind] ?? 0.5
212
+ let v = base
213
+ if (Number(r.use_count) > 0) v += Math.min(0.12, 0.03 * Number(r.use_count))
214
+ if (String(r.text || '').length > LONG) v -= 0.04
215
+ if (tagsToText(r.tags).trim()) v += 0.02
216
+ v = Math.max(0.15, Math.min(0.92, v))
217
+ if (!dryRun) upd.run(Number(v.toFixed(3)), r.id)
218
+ n++
219
+ }
220
+ if (!dryRun) db.exec('COMMIT')
221
+ } catch (e) {
222
+ if (!dryRun) db.exec('ROLLBACK')
223
+ throw e
224
+ }
225
+ report.importance = { filled: n, dryRun }
226
+ }
227
+
228
+ if (want.has('dup')) {
229
+ let archived = 0
230
+ const groups = db.prepare('SELECT text, COUNT(*) c FROM memories GROUP BY text HAVING c > 1').all()
231
+ const getRows = db.prepare('SELECT id, importance, length(text) len, created, archived FROM memories WHERE text=?')
232
+ const arch = db.prepare('UPDATE memories SET archived=1, eff=COALESCE(eff,importance)*0.5 WHERE id=?')
233
+ if (!dryRun) db.exec('BEGIN')
234
+ try {
235
+ for (const g of groups) {
236
+ const rows = getRows.all(g.text)
237
+ const keep = rows
238
+ .filter((r) => !Number(r.archived))
239
+ .sort((a, b) => (Number(b.importance) - Number(a.importance)) || (Number(b.len) - Number(a.len)) || (Number(b.created) - Number(a.created)))[0]
240
+ || rows[0]
241
+ for (const r of rows) {
242
+ if (r.id === keep.id) continue
243
+ if (Number(r.archived)) continue
244
+ if (!dryRun) arch.run(r.id)
245
+ archived++
246
+ }
247
+ }
248
+ if (!dryRun) db.exec('COMMIT')
249
+ } catch (e) {
250
+ if (!dryRun) db.exec('ROLLBACK')
251
+ throw e
252
+ }
253
+ report.dup = { groups: groups.length, archived, dryRun }
254
+ }
255
+
256
+ if (want.has('decay')) {
257
+ let touched = 0
258
+ const rows = db.prepare('SELECT id, importance, last_used, created FROM memories').all()
259
+ const upd = db.prepare('UPDATE memories SET eff=? WHERE id=?')
260
+ const t = now()
261
+ if (!dryRun) db.exec('BEGIN')
262
+ try {
263
+ for (const r of rows) {
264
+ const base = Number(r.importance) || 0.4
265
+ const last = Number(r.last_used) || Number(r.created) || t
266
+ const days = Math.max(0, (t - last) / 86400000)
267
+ const floor = base * 0.35 // 不归零:衰减到底也留基准的 35%,免得一批记忆全趴到 0 附近,排序失去区分度
268
+ const eff = Math.max(floor, Math.min(1, base * Math.pow(0.5, days / halfLifeDays)))
269
+ if (!dryRun) upd.run(Number(eff.toFixed(4)), r.id)
270
+ touched++
271
+ }
272
+ if (!dryRun) db.exec('COMMIT')
273
+ } catch (e) {
274
+ if (!dryRun) db.exec('ROLLBACK')
275
+ throw e
276
+ }
277
+ report.decay = { updated: touched, halfLifeDays, dryRun }
278
+ }
279
+
280
+ return { ok: true, at: now(), report }
281
+ }
282
+
283
+ function close() {
284
+ try { db?.close() } catch {}
285
+ db = null
286
+ }
287
+
288
+ return { audit, repair, close }
289
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-hub-center",
3
- "version": "0.12.2",
3
+ "version": "0.12.3",
4
4
  "description": "Sidebar hub for DeepSeek Harness: memory store, diary, sticker library, status board and local-model scheduling.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -19,7 +19,8 @@
19
19
  "locale/*.json",
20
20
  "icon.svg",
21
21
  "LICENSE",
22
- "README.md"
22
+ "README.md",
23
+ "CHANGELOG.md"
23
24
  ],
24
25
  "dsh": {
25
26
  "bundle": {