dsh-aupdate 0.5.0 → 0.6.0

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 +31 -16
  2. package/client.js +21 -23
  3. package/index.js +115 -57
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -55,8 +55,7 @@ https://github.com/CalmSun/dsh-aupdate
55
55
 
56
56
  | 设置 | 默认 | 说明 |
57
57
  |---|---|---|
58
- | `allow` | `[]` | 只更新这些包;留空表示全部 |
59
- | `exclude` | `[]` | 不更新的包,优先级高于 `allow` |
58
+ | `exclude` | `[]` | 不更新的包;填了就一直不参与自动更新 |
60
59
  | `allowMajor` | `true` | 关掉后只在同一主版本内升级 |
61
60
  | `allowPrerelease` | `false` | 关掉后不装预发布;`next` 标签不受影响 |
62
61
  | `idleOnly` | `true` | 忙的时候不动手(见下节) |
@@ -87,6 +86,9 @@ mtime 为准:那是磁盘事实。会话目录整个读不到时返回「不
87
86
  `~/.dsh/aupdate-history.json`,设置页里能直接看到,并对最近一次更新点「回滚」
88
87
  把旧版本装回去。回滚只针对本插件自己装上去的那一次。
89
88
 
89
+ 记录栏固定高度、在自己的框里滚动:堆到上百条也只是这一栏变长,不会把整页顶到几屏
90
+ 之外,按钮也不会被挤到看不见的地方。
91
+
90
92
  同一个包的 `from → to` 完全相同、且都不是回滚记录时只留最新一条:
91
93
  否则同一行失败记录会一轮一条堆满历史,真正要回的那个点反而找不到了。
92
94
  `1.0 → 1.1` 和 `1.0 → 1.2` 是两件事,不会合并。
@@ -124,19 +126,27 @@ mtime 为准:那是磁盘事实。会话目录整个读不到时返回「不
124
126
 
125
127
  ### 勾选插件,而不是手写包名
126
128
 
127
- `exclude` / `allow` 原来要一行一个包名地敲。现在整页里是两张勾选清单,直接列出
128
- 这个 profile 实际装着的插件和各自的已装版本:
129
+ `exclude` 原来要一行一个包名地敲。现在整页里是一张勾选清单,直接列出这个 profile
130
+ 实际装着的插件和各自的已装版本:
129
131
 
130
132
  - **不自动更新的包**:勾上的永远不参与自动更新
131
- - **只更新这些包**:勾上后只更新勾中的;一个都不勾表示不启用这条白名单
132
- - 能按名字搜索,`/state` 里带着 `packages`(名字、版本、当前是否被排除/在白名单里)
133
+ - 能按名字搜索,`/state` 里带着 `packages`(名字、版本、当前是否被排除)
133
134
  - 「全选 / 清空」只作用于当前筛选出来的行——搜完再点全选,意思是把搜到的都勾上
134
- - 白名单里留着已卸载的包名时照样列出来并标「未安装」,否则那条规则再也删不掉
135
+ - 这个 profile 里装着的插件都会列出来,列表本身就是「能勾什么」的全部答案
136
+
137
+ ### 「上一次」不会再被重启清空
138
+
139
+ 最近一轮的结果(时间、查了多少个、几个可更新、装成几个、失败原因)现在落在
140
+ `~/.dsh/aupdate-lastrun.json`,DSH 重启后照旧显示。以前它是纯内存的,重启一次就回到
141
+ 「还没跑过」,看着像这一轮根本没跑过。读的时候逐字段校验,坏文件只会让这张卡缺席,
142
+ 不会让插件加载失败。
135
143
 
136
- 整页最下面是**运行日志**卡片,直接看插件最近写了什么,不用再去翻文件:
144
+ 整页最下面是**运行日志**卡片,直接看插件最近写了什么,不用再去翻文件。日志正文用中文写,
145
+ 一行一件事(检查了多少个、装哪个、为什么跳过),状态词也翻成人话;
137
146
 
138
147
  - 可选显示最近 100 / 200 / 500 / 1000 行,默认 200
139
148
  - **最新的在最上面**:按时间倒序渲染,刚装了什么不用滚到底
149
+ - 时间只到「月-日 时:分:秒」并等宽对齐,省下的宽度留给正文
140
150
  - 打开「自动刷新」后每 5 秒拉一次,正在排查时开着;关掉就完全不动
141
151
  - 读之前会先把待写队列刷下去,所以刚点完检查,那几行马上就在里面
142
152
  - 时间戳按本地时区显示,文件超过 1MB 轮转给一句提示,另附总行数
@@ -260,8 +270,7 @@ A successful install clears the record.
260
270
 
261
271
  | Setting | Default | Meaning |
262
272
  |---|---|---|
263
- | `allow` | `[]` | Only update these packages; empty means all |
264
- | `exclude` | `[]` | Never update these; takes priority over `allow` |
273
+ | `exclude` | `[]` | Never update these; whatever is listed stays out of auto-updates |
265
274
  | `allowMajor` | `true` | When off, stay within the same major version |
266
275
  | `allowPrerelease` | `false` | When off, skip prereleases; the `next` tag is unaffected |
267
276
  | `idleOnly` | `true` | Hold off while anything is busy (see below) |
@@ -323,6 +332,9 @@ the new version, and a timestamp, in `~/.dsh/aupdate-history.json`. The settings
323
332
  page lists them and can roll the most recent update back to its previous version.
324
333
  A rollback applies once: the same downgrade cannot be replayed.
325
334
 
335
+ The list keeps a fixed height and scrolls inside its own box, so a hundred entries make
336
+ that one card longer instead of pushing the whole page down.
337
+
326
338
  Repeated rows for the same package with an identical `from → to`, where neither is
327
339
  a rollback, collapse into the newest one. Otherwise a single failing version would
328
340
  pile up one row per cycle and bury the entry you actually want to return to.
@@ -334,12 +346,15 @@ The row in the plugins page shows a summary and a full page; saving re-schedules
334
346
  immediately without a restart. The same UI is also its own page under
335
347
  **Settings → Plugin updates**, so it is not buried in the plugins page.
336
348
 
337
- `exclude` and `allow` are checkbox lists of the plugins actually installed in this
338
- profile, with their installed versions, instead of two textareas you had to type
339
- package names into. Search narrows the list; Select all / Clear only touch the rows
340
- currently shown, so "search, then select all" means what you expect. A name left in the
341
- allow-list after its package was uninstalled still appears, labelled "not installed",
342
- because otherwise that rule could never be removed.
349
+ `exclude` is a checkbox list of the plugins actually installed in this profile, with
350
+ their installed versions, instead of a textarea you had to type package names into.
351
+ Search narrows the list; Select all / Clear only touch the rows currently shown, so
352
+ "search, then select all" means what you expect.
353
+
354
+ The last run's outcome (when, how many checked, how many updatable, how many installed,
355
+ why it failed) is persisted to `~/.dsh/aupdate-lastrun.json` and survives a restart. It
356
+ used to live in memory only, so every restart reset the card to "never run" and looked
357
+ like nothing had happened.
343
358
 
344
359
  ### Update notices
345
360
 
package/client.js CHANGED
@@ -60,7 +60,6 @@ window.__ModuleLoader__.load({
60
60
  firstDelayHint: '分钟,0 表示立刻',
61
61
  exclude: '不自动更新的包',
62
62
  excludeHint: '每行一个包名',
63
- allow: '只更新这些包',
64
63
  allowHint: '每行一个包名;留空表示全部包都参与',
65
64
  allowMajor: '允许跨大版本',
66
65
  allowMajorHint: '关闭后只在同一主版本内升级(0.x 插件多半会因此长期不动)',
@@ -88,8 +87,6 @@ window.__ModuleLoader__.load({
88
87
  notifyHint: '在界面右下角弹一条提醒,列出可更新的插件和「当前 → 新」版本;同一批更新只提醒一次',
89
88
  pkgsExclude: '不自动更新的包',
90
89
  pkgsExcludeHint: '勾上的插件永远不自动更新;一个都不勾表示全部参与自动更新',
91
- pkgsAllow: '只更新这些包',
92
- pkgsAllowHint: '勾上后只更新勾选的插件;一个都不勾表示不启用这条白名单',
93
90
  pkgsSearch: '搜索插件名',
94
91
  pkgsAll: '全选',
95
92
  pkgsNone: '清空',
@@ -163,7 +160,6 @@ window.__ModuleLoader__.load({
163
160
  firstDelayHint: 'minutes, 0 means immediately',
164
161
  exclude: 'Never auto-update',
165
162
  excludeHint: 'one package name per line',
166
- allow: 'Only update these',
167
163
  allowHint: 'one package name per line; empty means every package',
168
164
  allowMajor: 'Allow major upgrades',
169
165
  allowMajorHint: 'Off keeps upgrades inside one major; 0.x plugins would rarely move',
@@ -191,8 +187,6 @@ window.__ModuleLoader__.load({
191
187
  notifyHint: 'Pops a notice in the bottom-right corner listing the plugins that can update and their current → new versions; each batch is announced once',
192
188
  pkgsExclude: 'Never auto-update',
193
189
  pkgsExcludeHint: 'Checked plugins are never updated automatically; nothing checked means everything takes part',
194
- pkgsAllow: 'Only update these',
195
- pkgsAllowHint: 'When anything is checked, only those plugins update; nothing checked disables this allow-list',
196
190
  pkgsSearch: 'Search plugin names',
197
191
  pkgsAll: 'All',
198
192
  pkgsNone: 'None',
@@ -256,6 +250,20 @@ window.__ModuleLoader__.load({
256
250
  }
257
251
  }
258
252
 
253
+ /**
254
+ * 日志行的时间只到 月-日 时:分:秒。
255
+ *
256
+ * 整条「2026-11-24 09:14:13」占掉一行近四分之一宽度,而日志的重点是内容,
257
+ * 年份在同一个文件里几乎不可能变。缩成短格式后一行能放进更多正文。
258
+ */
259
+ function formatLogWhen(iso) {
260
+ const when = new Date(iso)
261
+ if (Number.isNaN(when.getTime())) return String(iso ?? '')
262
+ const pad = (n) => String(n).padStart(2, '0')
263
+ return pad(when.getMonth() + 1) + '-' + pad(when.getDate()) +
264
+ ' ' + pad(when.getHours()) + ':' + pad(when.getMinutes()) + ':' + pad(when.getSeconds())
265
+ }
266
+
259
267
  /** 「上一次」的光看绝对时间不好判断新鲜度,补一句相对时间。 */
260
268
  function relativeWhen(iso) {
261
269
  const when = new Date(iso)
@@ -348,9 +356,11 @@ window.__ModuleLoader__.load({
348
356
  meta: { display: 'flex', gap: '14px', flexWrap: 'wrap', fontSize: '12px', opacity: 0.7 },
349
357
  // 等宽 + 可滚动:日志要能对齐看时间戳,也不能把整页顶长。
350
358
  logBox: { margin: 0, padding: '8px 10px', borderRadius: '6px', border: '1px solid rgba(128,128,128,0.22)', background: 'rgba(128,128,128,0.06)', fontSize: '11.5px', lineHeight: 1.55, fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace', maxHeight: '260px', overflow: 'auto', whiteSpace: 'pre-wrap', wordBreak: 'break-word' },
351
- logTime: { opacity: 0.5 },
359
+ logTime: { opacity: 0.5, flexShrink: 0, fontVariantNumeric: 'tabular-nums' },
352
360
  logText: {},
353
361
  // 勾选清单:包名可能很长(@scope/name),要能截断,版本靠右对齐。
362
+ // 更新记录可能上百条,不封高度会把整页顶到几屏之外,滚动条交还给这一栏。
363
+ scrollList: { display: 'flex', flexDirection: 'column', gap: '8px', maxHeight: '260px', overflowY: 'auto', paddingRight: '4px' },
354
364
  pkgList: { display: 'flex', flexDirection: 'column', gap: '1px', maxHeight: '240px', overflow: 'auto', border: '1px solid rgba(128,128,128,0.22)', borderRadius: '6px', padding: '4px' },
355
365
  pkgRow: { display: 'flex', alignItems: 'center', gap: '8px', padding: '2px 4px', borderRadius: '4px', cursor: 'pointer' },
356
366
  pkgName: { minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
@@ -573,9 +583,7 @@ window.__ModuleLoader__.load({
573
583
  for (const key of keys) {
574
584
  if (draft[key] !== state.settings[key]) return true
575
585
  }
576
- for (const listKey of ['exclude', 'allow']) {
577
- if (String((draft[listKey] || []).join('\n')) !== String((state.settings[listKey] || []).join('\n'))) return true
578
- }
586
+ if (String((draft.exclude || []).join('\n')) !== String((state.settings.exclude || []).join('\n'))) return true
579
587
  return false
580
588
  }, [state, draft])
581
589
 
@@ -594,7 +602,6 @@ window.__ModuleLoader__.load({
594
602
  intervalMinutes: draft.intervalMinutes,
595
603
  firstDelayMinutes: draft.firstDelayMinutes,
596
604
  exclude: draft.exclude,
597
- allow: draft.allow,
598
605
  allowMajor: draft.allowMajor,
599
606
  allowPrerelease: draft.allowPrerelease,
600
607
  scheduleMode: draft.scheduleMode,
@@ -733,20 +740,11 @@ window.__ModuleLoader__.load({
733
740
  onChange: (list) => patch('exclude', list),
734
741
  }),
735
742
  ),
736
- // 策略与范围:白名单 / 预发布 / 跨大版本,决定「什么算可以装」。
743
+ // 策略:预发布 / 跨大版本,决定「什么算可以装」。
737
744
  h('div', { style: S.card },
738
745
  h('span', { style: S.label }, T.policy),
739
746
  h(SwitchRow, { label: T.allowMajor, hint: T.allowMajorHint, value: draft.allowMajor, onChange: (v) => patch('allowMajor', v) }),
740
747
  h(SwitchRow, { label: T.allowPrerelease, hint: T.allowPrereleaseHint, value: draft.allowPrerelease, onChange: (v) => patch('allowPrerelease', v) }),
741
- h('div', { style: S.labelBox },
742
- h('span', { style: S.label }, T.pkgsAllow),
743
- h('span', { style: S.hint }, T.pkgsAllowHint),
744
- ),
745
- h(PackagePicker, {
746
- packages: state?.packages,
747
- selected: draft.allow,
748
- onChange: (list) => patch('allow', list),
749
- }),
750
748
  ),
751
749
  h('div', { style: S.actions },
752
750
  h('button', { type: 'button', style: dirty ? S.btnPrimary : S.btn, disabled: !dirty || saving, onClick: () => void save() }, saving ? T.saving : T.save),
@@ -772,7 +770,7 @@ window.__ModuleLoader__.load({
772
770
  h('span', { style: S.label }, T.history),
773
771
  (state?.history?.length ?? 0) === 0
774
772
  ? h('span', { style: S.status }, T.historyEmpty)
775
- : h('div', { style: { display: 'flex', flexDirection: 'column', gap: '8px' } },
773
+ : h('div', { style: S.scrollList },
776
774
  state.history.map((row, index) => h('div', {
777
775
  key: row.name + '@' + row.at + ':' + index,
778
776
  style: { display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', gap: '10px' },
@@ -861,7 +859,7 @@ window.__ModuleLoader__.load({
861
859
  ? h('span', { style: S.status }, T.logsEmpty)
862
860
  : h('pre', { style: S.logBox, title: data?.path || '' },
863
861
  rows.map((row, index) => h('div', { key: index },
864
- row.at ? h('span', { style: S.logTime }, formatWhen(row.at) + ' ') : null,
862
+ row.at ? h('span', { style: S.logTime }, formatLogWhen(row.at) + ' ') : null,
865
863
  h('span', { style: S.logText }, row.text),
866
864
  )),
867
865
  ),
package/index.js CHANGED
@@ -32,7 +32,10 @@ const SESSION_IDLE_MINUTES = 2
32
32
  /** 跨进程的安装锁:同一 profile 同时跑两个 pnpm 会抢锁失败。 */
33
33
  const LOCK_STALE_MS = 30 * 60 * 1000
34
34
 
35
- let lastRun = null
35
+ // 上一次运行结果从磁盘恢复。原来是纯内存的,DSH 一重启就没了:设置页明明刚装过
36
+ // 东西,却显示「还没跑过」——那是真的没记住,不是没跑。注意这是在模块加载期调用,
37
+ // 所以只能依赖函数声明(readLastRun/readJson 都提升),不能依赖下面的 const。
38
+ let lastRun = readLastRun()
36
39
  let running = null
37
40
 
38
41
  function oneLine(value, limit = 2000) {
@@ -88,6 +91,31 @@ function flushLog() {
88
91
  }
89
92
  }
90
93
 
94
+ /** 日志里的状态词翻译成人话——面板是给人看的,不留英文状态码。 */
95
+ const STATUS_TEXT = { done: '完成', blocked: '已让开', failed: '失败', skipped: '已跳过', none: '无', ok: '成功' }
96
+
97
+ function statusText(value) {
98
+ return STATUS_TEXT[String(value ?? '')] ?? String(value ?? '')
99
+ }
100
+
101
+ /** 设置页提交的键名,日志里不该出现 enabled,autoApply 这种字面量。 */
102
+ const FIELD_LABELS = {
103
+ enabled: '定时检查', autoApply: '自动安装', hotReload: '就地生效', checkOnStart: '启动先查',
104
+ idleOnly: '忙时不动手', notify: '更新提醒', intervalMinutes: '检查间隔',
105
+ firstDelayMinutes: '首次延迟', exclude: '不更新的包', allowMajor: '跨大版本',
106
+ allowPrerelease: '预发布', scheduleMode: '调度方式', dailyAt: '每天时刻',
107
+ everyHours: '每几小时', everyDays: '每几天', suppressHours: '失败抑制',
108
+ maxPerCycle: '单轮上限', sessionIdleMinutes: '会话静默',
109
+ }
110
+
111
+ function fieldLabel(key) {
112
+ return FIELD_LABELS[key] ?? String(key)
113
+ }
114
+
115
+ function yesNo(value) {
116
+ return value === true ? '开' : '关'
117
+ }
118
+
91
119
  function writeLog(message) {
92
120
  try {
93
121
  console.log('[dsh-aupdate] ' + oneLine(message, 400))
@@ -221,7 +249,7 @@ function settingsPath() {
221
249
  const OVERRIDEABLE = [
222
250
  'enabled', 'autoApply', 'hotReload', 'checkOnStart', 'idleOnly', 'notify',
223
251
  'intervalMinutes', 'firstDelayMinutes', 'exclude',
224
- 'allow', 'allowMajor', 'allowPrerelease',
252
+ 'allowMajor', 'allowPrerelease',
225
253
  // 调度:四种节奏 + 失败抑制时长。这些键不写进 Config schema,
226
254
  // 只活在覆盖层里——Config 的字段类型是宿主校验的,加错一个类型
227
255
  // 会在加载期直接抛错,而覆盖层是我们自己的文件,改坏了只影响这一项。
@@ -278,7 +306,7 @@ function writeOverrides(patch) {
278
306
  for (const key of OVERRIDEABLE) {
279
307
  if (patch === null || typeof patch !== 'object' || patch[key] === undefined) continue
280
308
  const raw = patch[key]
281
- if (key === 'exclude' || key === 'allow') {
309
+ if (key === 'exclude') {
282
310
  next[key] = stringList(raw)
283
311
  continue
284
312
  }
@@ -379,7 +407,6 @@ function settingsOf(config) {
379
407
  intervalMinutes: numberSetting(config, 'intervalMinutes', 1440, 10, 10080),
380
408
  firstDelayMinutes: numberSetting(config, 'firstDelayMinutes', 5, 0, 1440),
381
409
  exclude: stringList(config?.exclude),
382
- allow: stringList(config?.allow),
383
410
  // 默认允许跨大版本:这些都是 0.x 插件,按 semver 卡大版本等于几乎不更新。
384
411
  allowMajor: booleanSetting(config, 'allowMajor', true),
385
412
  // 默认不装预发布。注意:走 next 标签的包(@deepseek-ai/dsh-*)是显式选择,
@@ -413,7 +440,6 @@ const FIELDS = {
413
440
  intervalMinutes: { type: 'number', meta: { default: 1440, description: '检查间隔(分钟)' } },
414
441
  firstDelayMinutes: { type: 'number', meta: { default: 5, description: '启动后多久开始第一次' } },
415
442
  exclude: { type: 'array', meta: { default: [], description: '不要自动更新的包' } },
416
- allow: { type: 'array', meta: { default: [], description: '只更新这些包(留空表示全部)' } },
417
443
  allowMajor: { type: 'boolean', meta: { default: true, description: '允许跨大版本更新' } },
418
444
  allowPrerelease: { type: 'boolean', meta: { default: false, description: '允许安装预发布版本' } },
419
445
  }
@@ -421,7 +447,7 @@ const FIELDS = {
421
447
  const DICT = {
422
448
  enabled: 1, autoApply: 2, hotReload: 3, checkOnStart: 4, idleOnly: 5,
423
449
  intervalMinutes: 6, firstDelayMinutes: 7, exclude: 8,
424
- allow: 11, allowMajor: 12, allowPrerelease: 13,
450
+ allowMajor: 12, allowPrerelease: 13,
425
451
  }
426
452
 
427
453
  export const Config = {
@@ -435,7 +461,6 @@ export const Config = {
435
461
  6: FIELDS.intervalMinutes,
436
462
  7: FIELDS.firstDelayMinutes,
437
463
  8: FIELDS.exclude,
438
- 11: FIELDS.allow,
439
464
  12: FIELDS.allowMajor,
440
465
  13: FIELDS.allowPrerelease,
441
466
  10: { type: 'object', meta: { default: {} }, dict: DICT },
@@ -469,6 +494,52 @@ function historyPath() {
469
494
  return join(dirname(settingsPath()), 'aupdate-history.json')
470
495
  }
471
496
 
497
+ /**
498
+ * 上一次运行结果落盘。
499
+ *
500
+ * 「上一次」这张卡是设置页最有用的东西——它告诉你最近一轮什么时候跑、查了多少个、
501
+ * 装成了几个。但它是纯内存状态,DSH 一重启就归零,页面显示「还没跑过」,而磁盘上
502
+ * 明明有刚装好的包。所以照历史表的做法落一份在 ~/.dsh 下。
503
+ *
504
+ * 读的时候按字段逐个校验:这个文件可能是别的版本写的,缺字段就当默认值,
505
+ * 绝不因为一个坏文件让插件加载失败。
506
+ */
507
+ function lastRunPath() {
508
+ return join(dirname(settingsPath()), 'aupdate-lastrun.json')
509
+ }
510
+
511
+ function readLastRun() {
512
+ let raw = null
513
+ try {
514
+ raw = readJson(lastRunPath())
515
+ } catch {
516
+ return null
517
+ }
518
+ if (raw === null || typeof raw !== 'object') return null
519
+ if (typeof raw.at !== 'string' || raw.at === '') return null
520
+ const textList = (value) => (Array.isArray(value) ? value.filter((item) => typeof item === 'string') : [])
521
+ return {
522
+ status: typeof raw.status === 'string' ? raw.status : 'unknown',
523
+ at: raw.at,
524
+ checked: Number.isFinite(raw.checked) ? raw.checked : 0,
525
+ updates: textList(raw.updates),
526
+ installed: textList(raw.installed),
527
+ reload: typeof raw.reload === 'string' ? raw.reload : 'none',
528
+ reason: typeof raw.reason === 'string' ? raw.reason : '',
529
+ snapshot: typeof raw.snapshot === 'string' ? raw.snapshot : '',
530
+ }
531
+ }
532
+
533
+ function saveLastRun(value) {
534
+ try {
535
+ const file = lastRunPath()
536
+ mkdirSync(dirname(file), { recursive: true })
537
+ writeFileSync(file, JSON.stringify(value, null, 2) + '\n', 'utf8')
538
+ } catch {
539
+ // 记不住也不要紧,最坏的结果就是下次重启又显示「还没跑过」,不该影响更新本身。
540
+ }
541
+ }
542
+
472
543
  // 和失败表一样按 mtime+size 判新旧:这个文件也在 ~/.dsh 下跨 profile 共用,
473
544
  // 读到一次就永久缓存会让另一个进程刚写的记录在这边看不见。
474
545
  let historyCache = { stamp: null, value: [] }
@@ -699,19 +770,16 @@ function readJson(file) {
699
770
  }
700
771
 
701
772
  /** 要被检查的依赖:dependencies 里非 link/file 的那些。 */
702
- function dependencyList(profileDir, exclude, allow = []) {
773
+ function dependencyList(profileDir, exclude) {
703
774
  const manifest = readJson(join(profileDir, 'package.json'))
704
775
  const deps = manifest?.dependencies
705
776
  if (deps === null || typeof deps !== 'object') return []
706
777
  const skip = new Set(exclude)
707
- // 白名单非空时就是「只更新这些」;空数组表示不启用白名单。
708
- const only = new Set(allow)
709
778
  const rows = []
710
779
  for (const [pkgName, spec] of Object.entries(deps)) {
711
780
  if (typeof spec !== 'string') continue
712
781
  if (/^(link|file|workspace|portal):/iu.test(spec)) continue
713
782
  if (!NPM_NAME_RE.test(pkgName) || skip.has(pkgName)) continue
714
- if (only.size > 0 && !only.has(pkgName)) continue
715
783
  rows.push({ name: pkgName, spec })
716
784
  }
717
785
  return rows
@@ -720,38 +788,27 @@ function dependencyList(profileDir, exclude, allow = []) {
720
788
  /**
721
789
  * 设置页的勾选清单。
722
790
  *
723
- * dependencyList 会按 exclude/allow 过滤,而那正是勾选框要展示的东西——被排除的包
791
+ * dependencyList 会按 exclude 过滤,而那正是勾选框要展示的东西——被排除的包
724
792
  * 也必须出现在列表里,否则一旦勾上就再也取消不掉。所以这里不过滤,只给每一项
725
- * 标注「当前是否被排除 / 是否在白名单里」,让页面自己决定勾没勾。
726
- *
727
- * 白名单里还可能留着已经卸载的包名(改过 dependencies 之后就会这样)。它们没有
728
- * 对应的勾选项,但不能悄悄丢掉,否则用户再也没有入口删掉这条规则。
793
+ * 标注「当前是否被排除」,让页面自己决定勾没勾。
729
794
  */
730
795
  function packageChoices(profileDir, settings) {
731
796
  const manifest = readJson(join(profileDir, 'package.json'))
732
797
  const deps = manifest?.dependencies
733
798
  if (deps === null || typeof deps !== 'object') return []
734
799
  const skip = new Set(settings.exclude)
735
- const only = new Set(settings.allow)
736
- const known = new Set()
737
800
  const rows = []
738
801
  for (const [name, spec] of Object.entries(deps)) {
739
802
  if (typeof spec !== 'string') continue
740
803
  if (/^(link|file|workspace|portal):/iu.test(spec)) continue
741
804
  if (!NPM_NAME_RE.test(name)) continue
742
- known.add(name)
743
805
  const version = installedVersion(profileDir, name, spec)
744
806
  rows.push({
745
807
  name,
746
808
  version: typeof version === 'string' ? version : '',
747
809
  excluded: skip.has(name),
748
- allowed: only.has(name),
749
810
  })
750
811
  }
751
- for (const name of only) {
752
- if (known.has(name)) continue
753
- rows.push({ name, version: '', excluded: skip.has(name), allowed: true })
754
- }
755
812
  // 不能直接用 localeCompare:它的结果跟着系统区域变,同一个 profile 在不同机器上
756
813
  // 排出来的顺序会不一样,页面顺序跳来跳去会让人以为列表变了。
757
814
  rows.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))
@@ -1059,7 +1116,7 @@ function snapshotProfile(profileDir, now) {
1059
1116
  return { dir, files: saved }
1060
1117
  } catch (error) {
1061
1118
  // 留底失败不该拦住更新本身:它只是事后证据,不是前置条件。
1062
- writeLog('snapshot failed: ' + oneLine(error?.message ?? error, 200))
1119
+ writeLog('留快照失败:' + oneLine(error?.message ?? error, 200))
1063
1120
  return null
1064
1121
  }
1065
1122
  }
@@ -1118,7 +1175,7 @@ function takeProfileLock(profileDir, now) {
1118
1175
  } catch {}
1119
1176
  try {
1120
1177
  writeFileSync(file, stamp + '\n', { encoding: 'utf8', flag: 'wx' })
1121
- writeLog('took over a stale install lock (' + ageMinutes + ' min old)')
1178
+ writeLog('接管了一个已挂 ' + ageMinutes + ' 分钟的安装锁')
1122
1179
  return { ok: true, file }
1123
1180
  } catch (error) {
1124
1181
  return { ok: false, reason: '抢锁失败:' + oneLine(error?.message ?? error, 160) }
@@ -1240,7 +1297,7 @@ async function runCycle(mode, ctxRef) {
1240
1297
  try {
1241
1298
  const profileDir = profileDirOf(ctxRef.ctx)
1242
1299
  const profileName = basename(profileDir)
1243
- const deps = dependencyList(profileDir, settings.exclude, settings.allow)
1300
+ const deps = dependencyList(profileDir, settings.exclude)
1244
1301
  report.checked = deps.length
1245
1302
  if (deps.length === 0) {
1246
1303
  report.reason = '这个 profile 里没有可检查的依赖'
@@ -1288,7 +1345,7 @@ async function runCycle(mode, ctxRef) {
1288
1345
  else report.skipped.push(answer)
1289
1346
  }
1290
1347
  }
1291
- writeLog('checked ' + report.checked + ' package(s), ' + report.updates.length + ' update(s) available')
1348
+ writeLog('检查 ' + report.checked + ' 个插件,' + report.updates.length + ' 个可更新')
1292
1349
  if (report.updates.length === 0) {
1293
1350
  report.reason = '没有可更新的插件'
1294
1351
  return report
@@ -1298,7 +1355,7 @@ async function runCycle(mode, ctxRef) {
1298
1355
  const deferred = settings.maxPerCycle > 0 ? report.updates.length - settings.maxPerCycle : 0
1299
1356
  if (deferred > 0) {
1300
1357
  report.updates = report.updates.slice(0, settings.maxPerCycle)
1301
- writeLog('capped this cycle at ' + settings.maxPerCycle + ', ' + deferred + ' left for next round')
1358
+ writeLog('本轮限量装 ' + settings.maxPerCycle + ' 个,剩下 ' + deferred + ' 个下一轮再装')
1302
1359
  }
1303
1360
  if (mode === 'check' || !settings.autoApply) {
1304
1361
  report.reason = '只查不装'
@@ -1313,7 +1370,7 @@ async function runCycle(mode, ctxRef) {
1313
1370
  if (why.length > 0) {
1314
1371
  report.status = 'blocked'
1315
1372
  report.reason = why.join(';') + ',这一轮不安装'
1316
- writeLog('apply skipped: ' + why.join('; '))
1373
+ writeLog('跳过安装:' + why.join(';'))
1317
1374
  return report
1318
1375
  }
1319
1376
  }
@@ -1328,7 +1385,7 @@ async function runCycle(mode, ctxRef) {
1328
1385
  if (!lock.ok) {
1329
1386
  report.status = 'blocked'
1330
1387
  report.reason = lock.reason
1331
- writeLog('apply skipped: ' + lock.reason)
1388
+ writeLog('跳过安装:' + lock.reason)
1332
1389
  return report
1333
1390
  }
1334
1391
  try {
@@ -1336,7 +1393,7 @@ async function runCycle(mode, ctxRef) {
1336
1393
  const snapshot = snapshotProfile(profileDir, new Date())
1337
1394
  if (snapshot !== null) {
1338
1395
  report.snapshot = snapshot.dir
1339
- writeLog('snapshot -> ' + snapshot.dir + ' (' + snapshot.files.join(',') + ')')
1396
+ writeLog('已留快照 ' + snapshot.dir + '(' + snapshot.files.join('、') + ')')
1340
1397
  }
1341
1398
  return await applyUpdates(ctxRef, report, settings, runner, profileDir, profileName)
1342
1399
  } finally {
@@ -1345,7 +1402,7 @@ async function runCycle(mode, ctxRef) {
1345
1402
  } catch (error) {
1346
1403
  report.status = 'failed'
1347
1404
  report.reason = oneLine(error?.message ?? error, 400)
1348
- writeLog('cycle failed: ' + report.reason)
1405
+ writeLog('本轮失败:' + report.reason)
1349
1406
  return report
1350
1407
  } finally {
1351
1408
  report.finishedAt = new Date().toISOString()
@@ -1359,6 +1416,7 @@ async function runCycle(mode, ctxRef) {
1359
1416
  reason: report.reason,
1360
1417
  snapshot: report.snapshot,
1361
1418
  }
1419
+ saveLastRun(lastRun)
1362
1420
  }
1363
1421
  }
1364
1422
 
@@ -1373,7 +1431,7 @@ async function applyUpdates(ctxRef, report, settings, runner, profileDir, profil
1373
1431
  for (const update of ordered) {
1374
1432
  const outcome = await installOne(runner, profileName, profileDir, update.name, update.target)
1375
1433
  report.installed.push(outcome)
1376
- writeLog('install ' + update.name + '@' + update.target + ' -> ' + (outcome.ok ? 'ok' : 'failed: ' + outcome.detail))
1434
+ writeLog('安装 ' + update.name + '@' + update.target + ' → ' + (outcome.ok ? '成功' : '失败:' + outcome.detail))
1377
1435
  if (outcome.ok) {
1378
1436
  clearFailure(update.name, update.target)
1379
1437
  appendHistory({
@@ -1410,7 +1468,7 @@ async function applyUpdates(ctxRef, report, settings, runner, profileDir, profil
1410
1468
  return report
1411
1469
  }
1412
1470
  report.reload = await hotApply(ctxRef.ctx, requiredBefore)
1413
- writeLog('hot apply -> ' + report.reload.status + (report.reload.reason ? ': ' + report.reload.reason : ''))
1471
+ writeLog('就地生效 → ' + statusText(report.reload.status) + (report.reload.reason ? ':' + report.reload.reason : ''))
1414
1472
  report.reason = '已安装 ' + okCount + ' 个;' + (report.reload.reason ?? '')
1415
1473
  if (report.reload.status === 'failed') report.status = 'failed'
1416
1474
  else if (report.reload.status === 'blocked' || report.reload.status === 'restart') report.status = 'partial'
@@ -1473,7 +1531,7 @@ async function rollbackOne(ctxRef, entryName) {
1473
1531
  } finally {
1474
1532
  releaseProfileLock(lock)
1475
1533
  }
1476
- writeLog('rollback ' + row.name + ' ' + row.to + ' -> ' + row.from + ' -> ' + (outcome.ok ? 'ok' : 'failed: ' + outcome.detail))
1534
+ writeLog('回滚 ' + row.name + ' ' + row.to + ' → ' + row.from + ' → ' + (outcome.ok ? '成功' : '失败:' + outcome.detail))
1477
1535
  if (!outcome.ok) return { ok: false, reason: outcome.detail }
1478
1536
  const next = rows.slice()
1479
1537
  next.unshift({
@@ -1557,14 +1615,14 @@ function registerTool(ctx, config) {
1557
1615
  skipped: report.skipped.map((item) => item.name + ':' + item.why),
1558
1616
  }
1559
1617
  } catch (error) {
1560
- writeLog('tool failed: ' + oneLine(error?.message ?? error, 300))
1618
+ writeLog('工具调用失败:' + oneLine(error?.message ?? error, 300))
1561
1619
  return { status: 'failed', reason: '没能完成,插件状态需要核对', checked: 0, updates: [], installed: [], reload: 'none' }
1562
1620
  }
1563
1621
  },
1564
1622
  }), 'dsh-aupdate: plugin_updater')
1565
1623
  return true
1566
1624
  } catch (error) {
1567
- writeLog('cannot offer the tool: ' + oneLine(error?.message ?? error, 300))
1625
+ writeLog('无法提供工具:' + oneLine(error?.message ?? error, 300))
1568
1626
  return false
1569
1627
  }
1570
1628
  }
@@ -1774,12 +1832,12 @@ function registerRoutes(scope, ctxRef) {
1774
1832
  sendJson(res, 500, { error: result.error })
1775
1833
  return
1776
1834
  }
1777
- writeLog('settings updated by page: ' + Object.keys(body).join(','))
1835
+ writeLog('设置页改了:' + Object.keys(body).map(fieldLabel).join('、'))
1778
1836
  // 改完立刻按新设置重排,否则要等下一次触发才换节奏。
1779
1837
  try {
1780
1838
  if (typeof ctxRef.reschedule === 'function') ctxRef.reschedule()
1781
1839
  } catch (error) {
1782
- writeLog('reschedule failed: ' + oneLine(error?.message ?? error, 200))
1840
+ writeLog('重排定时失败:' + oneLine(error?.message ?? error, 200))
1783
1841
  }
1784
1842
  sendJson(res, 200, settingsSnapshot(ctxRef.config, ctxRef))
1785
1843
  return
@@ -1792,7 +1850,7 @@ function registerRoutes(scope, ctxRef) {
1792
1850
  return
1793
1851
  }
1794
1852
  const outcome = await rollbackOne(ctxRef, target)
1795
- writeLog('rollback request ' + target + ' -> ' + (outcome.ok ? 'ok' : 'failed: ' + outcome.reason))
1853
+ writeLog('收到回滚请求 ' + target + ' → ' + (outcome.ok ? '成功' : '失败:' + outcome.reason))
1796
1854
  sendJson(res, outcome.ok ? 200 : 409, outcome)
1797
1855
  return
1798
1856
  }
@@ -1812,7 +1870,7 @@ function registerRoutes(scope, ctxRef) {
1812
1870
  }
1813
1871
  sendJson(res, 405, { error: 'method not allowed' })
1814
1872
  } catch (error) {
1815
- writeLog('route failed: ' + oneLine(error?.message ?? error, 300))
1873
+ writeLog('接口处理出错:' + oneLine(error?.message ?? error, 300))
1816
1874
  try { sendJson(res, 500, { error: 'internal' }) } catch {}
1817
1875
  }
1818
1876
  }
@@ -1821,14 +1879,14 @@ function registerRoutes(scope, ctxRef) {
1821
1879
  const register = () => webServer.register({ kind: 'prefix', path: ROUTE_PREFIX, handler })
1822
1880
  if (typeof effect === 'function') {
1823
1881
  effect.call(scope, register, 'dsh-aupdate: settings routes')
1824
- writeLog('settings route ready: ' + ROUTE_PREFIX)
1882
+ writeLog('设置接口已就绪:' + ROUTE_PREFIX)
1825
1883
  return true
1826
1884
  }
1827
1885
  register()
1828
- writeLog('settings route ready (no effect scope): ' + ROUTE_PREFIX)
1886
+ writeLog('设置接口已就绪(没有 effect 作用域):' + ROUTE_PREFIX)
1829
1887
  return true
1830
1888
  } catch (error) {
1831
- writeLog('cannot register settings route: ' + oneLine(error?.message ?? error, 300))
1889
+ writeLog('无法注册设置接口:' + oneLine(error?.message ?? error, 300))
1832
1890
  return false
1833
1891
  }
1834
1892
  }
@@ -1847,15 +1905,15 @@ export function apply(ctx, config) {
1847
1905
  try {
1848
1906
  const tools = serviceOf(scope, 'tools')
1849
1907
  if (tools === null || typeof tools.register !== 'function') {
1850
- writeLog('tool registered: false')
1908
+ writeLog('工具注册失败')
1851
1909
  return
1852
1910
  }
1853
1911
  if (toolService === tools) return
1854
1912
  toolService = tools
1855
1913
  const ok = registerTool(scope, config)
1856
- writeLog('tool registered: ' + ok)
1914
+ writeLog('工具注册:' + (ok ? '成功' : '失败'))
1857
1915
  } catch (error) {
1858
- writeLog('tool registration threw: ' + oneLine(error?.message ?? error, 300))
1916
+ writeLog('注册工具时抛错:' + oneLine(error?.message ?? error, 300))
1859
1917
  }
1860
1918
  }
1861
1919
  // 路由和工具是同一类问题:apply 执行时 webServer 可能还没就绪,
@@ -1865,14 +1923,14 @@ export function apply(ctx, config) {
1865
1923
  try {
1866
1924
  const webServer = serviceOf(scope, 'webServer')
1867
1925
  if (webServer === null || typeof webServer.register !== 'function') {
1868
- writeLog('webServer unavailable: settings page will report it')
1926
+ writeLog('没有 webServer 服务,设置页会显示不可用')
1869
1927
  return
1870
1928
  }
1871
1929
  if (routeService === webServer) return
1872
1930
  const ok = registerRoutes(scope, ctxRef)
1873
1931
  if (ok) routeService = webServer
1874
1932
  } catch (error) {
1875
- writeLog('route registration threw: ' + oneLine(error?.message ?? error, 300))
1933
+ writeLog('注册设置接口时抛错:' + oneLine(error?.message ?? error, 300))
1876
1934
  }
1877
1935
  }
1878
1936
  const inject = propOf(ctx, 'inject')
@@ -1886,10 +1944,10 @@ export function apply(ctx, config) {
1886
1944
  offerRoutes(scope)
1887
1945
  })
1888
1946
  Promise.resolve(fiber).catch((error) => {
1889
- writeLog('tool scope ended: ' + oneLine(error?.message ?? error, 300))
1947
+ writeLog('工具作用域已结束:' + oneLine(error?.message ?? error, 300))
1890
1948
  })
1891
1949
  } catch (error) {
1892
- writeLog('cannot offer the tool: ' + oneLine(error?.message ?? error, 300))
1950
+ writeLog('无法提供工具:' + oneLine(error?.message ?? error, 300))
1893
1951
  offerTool(ctx)
1894
1952
  offerRoutes(ctx)
1895
1953
  }
@@ -1902,9 +1960,9 @@ export function apply(ctx, config) {
1902
1960
  const go = async () => {
1903
1961
  try {
1904
1962
  const report = await beginningRun(mode, ctxRef)
1905
- if (report !== null) writeLog('cycle ' + mode + ' -> ' + report.status + ': ' + report.reason)
1963
+ if (report !== null) writeLog('本轮' + (mode === 'check' ? '检查' : '更新') + ' → ' + statusText(report.status) + ':' + report.reason)
1906
1964
  } catch (error) {
1907
- writeLog('cycle threw: ' + oneLine(error?.message ?? error, 300))
1965
+ writeLog('本轮抛错:' + oneLine(error?.message ?? error, 300))
1908
1966
  }
1909
1967
  }
1910
1968
  void go()
@@ -1939,7 +1997,7 @@ export function apply(ctx, config) {
1939
1997
  clearScheduled()
1940
1998
  const live = settingsOf(ctxRef.config)
1941
1999
  if (!live.enabled) {
1942
- writeLog('settings say disabled; scheduler parked')
2000
+ writeLog('设置里已关闭自动更新,定时器待命')
1943
2001
  return
1944
2002
  }
1945
2003
  // 启动后第一次仍然只看 firstDelayMinutes,之后按当前调度模式算。
@@ -1973,7 +2031,7 @@ export function apply(ctx, config) {
1973
2031
 
1974
2032
  // 设置页要能读到运行状态并改设置,所以路由最后注册、且与 enabled 无关:
1975
2033
  // 关掉定时检查之后,用户仍然要能看到这一页并把它重新打开。
1976
- if (!settings.enabled) writeLog('disabled by config; scheduler parked, settings page still live')
2034
+ if (!settings.enabled) writeLog('配置里已关闭自动更新,定时器待命,设置页仍然可用')
1977
2035
 
1978
2036
  const stop = () => {
1979
2037
  for (const off of timers.splice(0)) {
@@ -1989,7 +2047,7 @@ export function apply(ctx, config) {
1989
2047
  } catch {}
1990
2048
  }
1991
2049
 
1992
- writeLog('ready: every ' + settings.intervalMinutes + ' min, autoApply=' + settings.autoApply + ', hotReload=' + settings.hotReload)
2050
+ writeLog('已就绪:每 ' + settings.intervalMinutes + ' 分钟检查一次,自动安装=' + yesNo(settings.autoApply) + ',就地生效=' + yesNo(settings.hotReload))
1993
2051
  }
1994
2052
 
1995
2053
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-aupdate",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "description": "定时检查 DSH 插件更新,串行安装后就地生效,不重启;支持多种调度节奏、失败抑制、按包回滚,并在动手前留快照、忙时自动让开;不更新/只更新哪些插件改成勾选,发现更新在右下角提醒,日志最新在最上面,并在「设置 → 插件更新」里有独立一页。",
6
6
  "license": "MIT",